2 * GL_HP_occlustion_test demo
7 * Copyright (C) 2000 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 static GLfloat Xpos
= 0;
40 PrintString(const char *s
)
43 glutBitmapCharacter(GLUT_BITMAP_8_BY_13
, (int) *s
);
50 static void Idle(void)
52 static int lastTime
= 0;
54 int time
= glutGet(GLUT_ELAPSED_TIME
);
59 else if (time
- lastTime
< 20) /* 50Hz update */
62 step
= (time
- lastTime
) / 1000.0 * sign
;
71 else if (Xpos
< -2.5) {
79 static void Display( void )
83 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
85 glMatrixMode( GL_PROJECTION
);
87 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
88 glMatrixMode( GL_MODELVIEW
);
90 glTranslatef( 0.0, 0.0, -15.0 );
92 /* draw the occluding polygons */
93 glColor3f(0, 0.6, 0.8);
95 glVertex2f(-1.6, -1.5);
96 glVertex2f(-0.4, -1.5);
97 glVertex2f(-0.4, 1.5);
98 glVertex2f(-1.6, 1.5);
100 glVertex2f( 0.4, -1.5);
101 glVertex2f( 1.6, -1.5);
102 glVertex2f( 1.6, 1.5);
103 glVertex2f( 0.4, 1.5);
106 /* draw the test polygon with occlusion testing */
108 glTranslatef(Xpos
, 0, -0.5);
109 glScalef(0.3, 0.3, 1.0);
110 glRotatef(-90.0 * Xpos
, 0, 0, 1);
112 glEnable(GL_OCCLUSION_TEST_HP
); /* NOTE: enabling the occlusion test */
113 /* doesn't clear the result flag! */
114 glColorMask(0, 0, 0, 0);
115 glDepthMask(GL_FALSE
);
116 /* this call clear's the result flag. Not really needed for this demo. */
117 glGetBooleanv(GL_OCCLUSION_TEST_RESULT_HP
, &result
);
120 glVertex3f(-1, -1, 0);
121 glVertex3f( 1, -1, 0);
122 glVertex3f( 1, 1, 0);
123 glVertex3f(-1, 1, 0);
126 glGetBooleanv(GL_OCCLUSION_TEST_RESULT_HP
, &result
);
127 /* turn off occlusion testing */
128 glDisable(GL_OCCLUSION_TEST_HP
);
129 glColorMask(1, 1, 1, 1);
130 glDepthMask(GL_TRUE
);
132 /* draw the green rect, so we can see what's going on */
133 glColor3f(0.8, 0.5, 0);
135 glVertex3f(-1, -1, 0);
136 glVertex3f( 1, -1, 0);
137 glVertex3f( 1, 1, 0);
138 glVertex3f(-1, 1, 0);
144 /* Print result message */
145 glMatrixMode( GL_PROJECTION
);
147 glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
148 glMatrixMode( GL_MODELVIEW
);
152 glRasterPos3f(-0.25, -0.7, 0);
155 PrintString(" Visible");
157 PrintString("Fully Occluded");
163 static void Reshape( int width
, int height
)
165 glViewport( 0, 0, width
, height
);
169 static void Key( unsigned char key
, int x
, int y
)
182 static void SpecialKey( int key
, int x
, int y
)
184 const GLfloat step
= 0.1;
199 static void Init( void )
201 const char *ext
= (const char *) glGetString(GL_EXTENSIONS
);
202 if (!strstr(ext
, "GL_HP_occlusion_test")) {
203 printf("Sorry, this demo requires the GL_HP_occlusion_test extension\n");
207 glEnable(GL_DEPTH_TEST
);
211 int main( int argc
, char *argv
[] )
213 glutInit( &argc
, argv
);
214 glutInitWindowPosition( 0, 0 );
215 glutInitWindowSize( 400, 400 );
216 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
217 glutCreateWindow(argv
[0]);
218 glutReshapeFunc( Reshape
);
219 glutKeyboardFunc( Key
);
220 glutSpecialFunc( SpecialKey
);
221 glutIdleFunc( Idle
);
222 glutDisplayFunc( Display
);