~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to progs/tests/blendsquare.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * (C) Copyright IBM Corporation 2004
3
 
 * All Rights Reserved.
4
 
 *
5
 
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 
 * copy of this software and associated documentation files (the "Software"),
7
 
 * to deal in the Software without restriction, including without limitation
8
 
 * on the rights to use, copy, modify, merge, publish, distribute, sub
9
 
 * license, and/or sell copies of the Software, and to permit persons to whom
10
 
 * the Software is furnished to do so, subject to the following conditions:
11
 
 *
12
 
 * The above copyright notice and this permission notice (including the next
13
 
 * paragraph) shall be included in all copies or substantial portions of the
14
 
 * Software.
15
 
 *
16
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19
 
 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20
 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
 
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22
 
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23
 
 */
24
 
 
25
 
/**
26
 
 * \file blendsquare.c
27
 
 * 
28
 
 * Simple test of GL_NV_blend_square functionality.  Four squares are drawn
29
 
 * with different blending modes, but all should be rendered with the same
30
 
 * final color.
31
 
 *
32
 
 * \author Ian Romanick <idr@us.ibm.com>
33
 
 */
34
 
 
35
 
#include <stdio.h>
36
 
#include <stdlib.h>
37
 
#include <GL/glut.h>
38
 
 
39
 
static int Width = 400;
40
 
static int Height = 200;
41
 
static const GLfloat Near = 5.0, Far = 25.0;
42
 
 
43
 
 
44
 
static void Display( void )
45
 
{
46
 
   glClearColor(0.2, 0.2, 0.8, 0);
47
 
   glClear( GL_COLOR_BUFFER_BIT );
48
 
 
49
 
   glPushMatrix();
50
 
 
51
 
   glTranslatef(-4.5, 0, 0);
52
 
   glBlendFunc( GL_ONE, GL_ZERO );
53
 
   glBegin(GL_QUADS);
54
 
   glColor3f( 0.5 * 0.5, 0.5 * 0.5, 0.5 * 0.5 );
55
 
   glVertex2f(-1, -1);
56
 
   glVertex2f( 1, -1);
57
 
   glVertex2f( 1,  1);
58
 
   glVertex2f(-1,  1);
59
 
   glEnd();
60
 
 
61
 
 
62
 
   glTranslatef(3.0, 0, 0);
63
 
   glBlendFunc( GL_ONE, GL_ZERO );
64
 
   glBegin(GL_QUADS);
65
 
   glColor3f( 0.5, 0.5, 0.5 );
66
 
   glVertex2f(-1, -1);
67
 
   glVertex2f( 1, -1);
68
 
   glVertex2f( 1,  1);
69
 
   glVertex2f(-1,  1);
70
 
   glEnd();
71
 
 
72
 
   glBlendFunc( GL_DST_COLOR, GL_ZERO );
73
 
   glBegin(GL_QUADS);
74
 
   glVertex2f(-1, -1);
75
 
   glVertex2f( 1, -1);
76
 
   glVertex2f( 1,  1);
77
 
   glVertex2f(-1,  1);
78
 
   glEnd();
79
 
 
80
 
 
81
 
   glTranslatef(3.0, 0, 0);
82
 
   glBlendFunc( GL_SRC_COLOR, GL_ZERO );
83
 
   glBegin(GL_QUADS);
84
 
   glVertex2f(-1, -1);
85
 
   glVertex2f( 1, -1);
86
 
   glVertex2f( 1,  1);
87
 
   glVertex2f(-1,  1);
88
 
   glEnd();
89
 
 
90
 
 
91
 
   glTranslatef(3.0, 0, 0);
92
 
   glBlendFunc( GL_ONE, GL_ZERO );
93
 
   glBegin(GL_QUADS);
94
 
   glVertex2f(-1, -1);
95
 
   glVertex2f( 1, -1);
96
 
   glVertex2f( 1,  1);
97
 
   glVertex2f(-1,  1);
98
 
   glEnd();
99
 
 
100
 
   glBlendFunc( GL_ZERO, GL_DST_COLOR );
101
 
   glBegin(GL_QUADS);
102
 
   glVertex2f(-1, -1);
103
 
   glVertex2f( 1, -1);
104
 
   glVertex2f( 1,  1);
105
 
   glVertex2f(-1,  1);
106
 
   glEnd();
107
 
 
108
 
   glPopMatrix();
109
 
 
110
 
   glutSwapBuffers();
111
 
}
112
 
 
113
 
 
114
 
static void Reshape( int width, int height )
115
 
{
116
 
   GLfloat ar = (float) width / (float) height;
117
 
   Width = width;
118
 
   Height = height;
119
 
   glViewport( 0, 0, width, height );
120
 
   glMatrixMode( GL_PROJECTION );
121
 
   glLoadIdentity();
122
 
   glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
123
 
   glMatrixMode( GL_MODELVIEW );
124
 
   glLoadIdentity();
125
 
   glTranslatef( 0.0, 0.0, -15.0 );
126
 
}
127
 
 
128
 
 
129
 
static void Key( unsigned char key, int x, int y )
130
 
{
131
 
   (void) x;
132
 
   (void) y;
133
 
   switch (key) {
134
 
      case 27:
135
 
         exit(0);
136
 
         break;
137
 
   }
138
 
   glutPostRedisplay();
139
 
}
140
 
 
141
 
 
142
 
static void Init( void )
143
 
{
144
 
   const char * const ver_string = (const char * const)
145
 
       glGetString( GL_VERSION );
146
 
   const double version = strtod( ver_string, NULL );
147
 
 
148
 
   printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
149
 
   printf("GL_VERSION = %s\n", ver_string);
150
 
 
151
 
   if ( (version < 1.4) && !glutExtensionSupported("GL_NV_blend_square")) {
152
 
      printf("Sorry, this program requires either OpenGL 1.4 or GL_NV_blend_square\n");
153
 
      exit(1);
154
 
   }
155
 
 
156
 
   printf("\nAll 4 squares should be the same color.  The two on the left are drawn\n"
157
 
          "without NV_blend_square functionality, and the two on the right are drawn\n"
158
 
          "with NV_blend_square functionality.  If the two on the left are dark, but\n"
159
 
          "the two on the right are not, then NV_blend_square is broken.\n");
160
 
   glEnable( GL_BLEND );
161
 
   glBlendEquation( GL_FUNC_ADD );
162
 
}
163
 
 
164
 
 
165
 
int main( int argc, char *argv[] )
166
 
{
167
 
   glutInit( &argc, argv );
168
 
   glutInitWindowPosition( 0, 0 );
169
 
   glutInitWindowSize( Width, Height );
170
 
   glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
171
 
   glutCreateWindow( "GL_NV_blend_square test" );
172
 
   glutReshapeFunc( Reshape );
173
 
   glutKeyboardFunc( Key );
174
 
   glutDisplayFunc( Display );
175
 
   Init();
176
 
   glutMainLoop();
177
 
   return 0;
178
 
}