better front-plane clip test
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
|
|
||||||
GLenum doubleBuffer;
|
GLenum doubleBuffer;
|
||||||
|
float Z = -6;
|
||||||
|
|
||||||
static void Init(void)
|
static void Init(void)
|
||||||
{
|
{
|
||||||
@@ -40,30 +41,36 @@ static void Init(void)
|
|||||||
fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
|
fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
|
||||||
fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
|
fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
|
||||||
|
|
||||||
glClearColor(0.0, 0.0, 1.0, 0.0);
|
fprintf(stderr, "Press z/Z to translate quad\n");
|
||||||
|
|
||||||
|
glClearColor(0.0, 0.0, 1.0, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Reshape(int width, int height)
|
static void Reshape(int width, int height)
|
||||||
{
|
{
|
||||||
|
|
||||||
glViewport(0, 0, (GLint)width, (GLint)height);
|
glViewport(0, 0, (GLint)width, (GLint)height);
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
|
glFrustum(-1.0, 1.0, -1.0, 1.0, 5, 100.0);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Key(unsigned char key, int x, int y)
|
static void Key(unsigned char key, int x, int y)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 27:
|
case 'z':
|
||||||
exit(1);
|
Z += 0.5;
|
||||||
default:
|
break;
|
||||||
return;
|
case 'Z':
|
||||||
|
Z -= 0.5;
|
||||||
|
break;
|
||||||
|
case 27:
|
||||||
|
exit(1);
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
printf("Z = %f\n", Z);
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,17 +78,22 @@ static void Draw(void)
|
|||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(0, -0.5, Z);
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glColor3f(1,0,0);
|
glColor3f(1,0,0);
|
||||||
glVertex3f( 0.9, -0.9, 30.0);
|
glVertex3f( -0.8, 0, -4.0);
|
||||||
glColor3f(1,1,0);
|
glColor3f(1,1,0);
|
||||||
glVertex3f( 0.9, 0.9, 30.0);
|
glVertex3f( 0.8, 0, -4.0);
|
||||||
glColor3f(1,0,1);
|
glColor3f(1,0,1);
|
||||||
glVertex3f(-1.9, 0.9, 30.0);
|
glVertex3f( 0.8, 0, 4.0);
|
||||||
glColor3f(0,1,1);
|
glColor3f(0,1,1);
|
||||||
glVertex3f(-1.9, -0.9, -30.0);
|
glVertex3f( -0.8, 0, 4.0);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
glFlush();
|
glFlush();
|
||||||
|
|
||||||
if (doubleBuffer) {
|
if (doubleBuffer) {
|
||||||
@@ -118,7 +130,8 @@ int main(int argc, char **argv)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
|
glutInitWindowPosition(0, 0);
|
||||||
|
glutInitWindowSize( 250, 250);
|
||||||
|
|
||||||
type = GLUT_RGB;
|
type = GLUT_RGB;
|
||||||
type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
|
type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
|
||||||
@@ -134,5 +147,5 @@ int main(int argc, char **argv)
|
|||||||
glutKeyboardFunc(Key);
|
glutKeyboardFunc(Key);
|
||||||
glutDisplayFunc(Draw);
|
glutDisplayFunc(Draw);
|
||||||
glutMainLoop();
|
glutMainLoop();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user