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;
37 static GLboolean Anim
= GL_TRUE
;
41 PrintString(const char *s
)
44 glutBitmapCharacter(GLUT_BITMAP_8_BY_13
, (int) *s
);
51 static void Idle(void)
53 static int lastTime
= 0;
55 int time
= glutGet(GLUT_ELAPSED_TIME
);
60 else if (time
- lastTime
< 20) /* 50Hz update */
63 step
= (time
- lastTime
) / 1000.0 * sign
;
72 else if (Xpos
< -2.5) {
80 static void Display( void )
84 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
86 glMatrixMode( GL_PROJECTION
);
88 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
89 glMatrixMode( GL_MODELVIEW
);
91 glTranslatef( 0.0, 0.0, -15.0 );
93 /* draw the occluding polygons */
94 glColor3f(0, 0.6, 0.8);
96 glVertex2f(-1.6, -1.5);
97 glVertex2f(-0.4, -1.5);
98 glVertex2f(-0.4, 1.5);
99 glVertex2f(-1.6, 1.5);
101 glVertex2f( 0.4, -1.5);
102 glVertex2f( 1.6, -1.5);
103 glVertex2f( 1.6, 1.5);
104 glVertex2f( 0.4, 1.5);
107 /* draw the test polygon with occlusion testing */
109 glTranslatef(Xpos
, 0, -0.5);
110 glScalef(0.3, 0.3, 1.0);
111 glRotatef(-90.0 * Xpos
, 0, 0, 1);
113 glEnable(GL_OCCLUSION_TEST_HP
); /* NOTE: enabling the occlusion test */
114 /* doesn't clear the result flag! */
115 glColorMask(0, 0, 0, 0);
116 glDepthMask(GL_FALSE
);
117 /* this call clear's the result flag. Not really needed for this demo. */
118 glGetBooleanv(GL_OCCLUSION_TEST_RESULT_HP
, &result
);
121 glVertex3f(-1, -1, 0);
122 glVertex3f( 1, -1, 0);
123 glVertex3f( 1, 1, 0);
124 glVertex3f(-1, 1, 0);
127 glGetBooleanv(GL_OCCLUSION_TEST_RESULT_HP
, &result
);
128 /* turn off occlusion testing */
129 glDisable(GL_OCCLUSION_TEST_HP
);
130 glColorMask(1, 1, 1, 1);
131 glDepthMask(GL_TRUE
);
133 /* draw the green rect, so we can see what's going on */
134 glColor3f(0.8, 0.5, 0);
136 glVertex3f(-1, -1, 0);
137 glVertex3f( 1, -1, 0);
138 glVertex3f( 1, 1, 0);
139 glVertex3f(-1, 1, 0);
145 /* Print result message */
146 glMatrixMode( GL_PROJECTION
);
148 glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
149 glMatrixMode( GL_MODELVIEW
);
153 glRasterPos3f(-0.25, -0.7, 0);
156 PrintString(" Visible");
158 PrintString("Fully Occluded");
164 static void Reshape( int width
, int height
)
166 glViewport( 0, 0, width
, height
);
170 static void Key( unsigned char key
, int x
, int y
)
178 glutIdleFunc( Idle
);
180 glutIdleFunc( NULL
);
190 static void SpecialKey( int key
, int x
, int y
)
192 const GLfloat step
= 0.1;
207 static void Init( void )
209 const char *ext
= (const char *) glGetString(GL_EXTENSIONS
);
210 if (!strstr(ext
, "GL_HP_occlusion_test")) {
211 printf("Sorry, this demo requires the GL_HP_occlusion_test extension\n");
215 glEnable(GL_DEPTH_TEST
);
219 int main( int argc
, char *argv
[] )
221 glutInit( &argc
, argv
);
222 glutInitWindowPosition( 0, 0 );
223 glutInitWindowSize( 400, 400 );
224 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
225 glutCreateWindow(argv
[0]);
226 glutReshapeFunc( Reshape
);
227 glutKeyboardFunc( Key
);
228 glutSpecialFunc( SpecialKey
);
229 glutIdleFunc( Idle
);
230 glutDisplayFunc( Display
);