use 'c' to cycle through polygon cull modes
This commit is contained in:
parent
8733ee9dc9
commit
9a89cc3b6b
|
@ -27,25 +27,44 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <GL/glut.h>
|
#include <GL/glut.h>
|
||||||
|
|
||||||
|
static GLenum doubleBuffer;
|
||||||
|
static GLint cullmode = 0;
|
||||||
|
|
||||||
#define CI_OFFSET_1 16
|
static void cull(void)
|
||||||
#define CI_OFFSET_2 32
|
{
|
||||||
|
cullmode = (cullmode + 1) % 4;
|
||||||
|
if (cullmode == 0) {
|
||||||
GLenum doubleBuffer;
|
glCullFace(GL_FRONT);
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
printf("cull GL_FRONT\n");
|
||||||
|
}
|
||||||
|
else if (cullmode == 1) {
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
printf("cull GL_BACK\n");
|
||||||
|
}
|
||||||
|
else if (cullmode == 2) {
|
||||||
|
glCullFace(GL_FRONT_AND_BACK);
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
printf("cull GL_FRONT_AND_BACK\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
glDisable(GL_CULL_FACE);
|
||||||
|
printf("cull none\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void Init(void)
|
static void Init(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
|
fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
|
||||||
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);
|
glClearColor(0.0, 0.0, 1.0, 0.0);
|
||||||
|
cull();
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -56,14 +75,15 @@ static void Reshape(int width, int height)
|
||||||
|
|
||||||
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 27:
|
||||||
exit(1);
|
exit(1);
|
||||||
|
case 'c':
|
||||||
|
cull();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,12 +92,22 @@ static void Draw(void)
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
glBegin(GL_TRIANGLES);
|
glBegin(GL_TRIANGLES);
|
||||||
glColor3f(0,0,1);
|
/* back-facing */
|
||||||
glVertex3f( -1.5, 0.5, -30.0);
|
glColor3f(0,0,.7);
|
||||||
glColor3f(1,0,0);
|
glVertex3f(-0.1, -0.9, -30.0);
|
||||||
glVertex3f( 0, 2.0, -30.0);
|
glColor3f(.8,0,0);
|
||||||
glColor3f(0,1,0);
|
glVertex3f(-0.1, 0.9, -30.0);
|
||||||
glVertex3f(-1.5, 2.0, -30.0);
|
glColor3f(0,.9,0);
|
||||||
|
glVertex3f(-0.9, 0.0, -30.0);
|
||||||
|
|
||||||
|
/* front-facing */
|
||||||
|
glColor3f(0,0,.7);
|
||||||
|
glVertex3f( 0.1, -0.9, -30.0);
|
||||||
|
glColor3f(.8,0,0);
|
||||||
|
glVertex3f( 0.1, 0.9, -30.0);
|
||||||
|
glColor3f(0,.9,0);
|
||||||
|
glVertex3f( 0.9, 0.0, -30.0);
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
glFlush();
|
glFlush();
|
||||||
|
|
Loading…
Reference in New Issue