diff options
author | Brian Paul <[email protected]> | 2009-02-10 16:44:02 -0700 |
---|---|---|
committer | Brian Paul <[email protected]> | 2009-02-10 16:44:02 -0700 |
commit | 5340b6dff73a0a23531ce2a5f28fba8303adab6e (patch) | |
tree | b141fc3648568dd8b941c966059e6ed32a8bd0ad /progs/trivial/tri-cull.c | |
parent | 9fd26daec24f21dbe17afcb2e2ab272667ee9a69 (diff) | |
parent | ee4c921b65fb76998711f3c40330505cbc49a0e0 (diff) |
Merge commit 'origin/gallium-master-merge'
This is the big merge of the gallium-0.2 branch into master.
gallium-master-merge was just the staging area for it.
Both gallium-0.2 and gallium-master-merge are considered closed now.
Conflicts:
progs/demos/Makefile
src/mesa/main/state.c
src/mesa/main/texenvprogram.c
Diffstat (limited to 'progs/trivial/tri-cull.c')
-rw-r--r-- | progs/trivial/tri-cull.c | 86 |
1 files changed, 61 insertions, 25 deletions
diff --git a/progs/trivial/tri-cull.c b/progs/trivial/tri-cull.c index 20aeaf1d7cd..2eead841155 100644 --- a/progs/trivial/tri-cull.c +++ b/progs/trivial/tri-cull.c @@ -27,25 +27,45 @@ #include <stdlib.h> #include <GL/glut.h> +static GLenum doubleBuffer; +static GLint cullmode = 0; +static GLenum front = GL_CCW; /* GL default */ -#define CI_OFFSET_1 16 -#define CI_OFFSET_2 32 - - -GLenum doubleBuffer; +static void cull(void) +{ + cullmode = (cullmode + 1) % 4; + if (cullmode == 0) { + 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) { fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); 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) { - glViewport(0, 0, (GLint)width, (GLint)height); glMatrixMode(GL_PROJECTION); @@ -56,15 +76,21 @@ static void Reshape(int width, int height) static void Key(unsigned char key, int x, int y) { - - switch (key) { - case 27: - exit(1); - default: - return; - } - - glutPostRedisplay(); + switch (key) { + case 27: + exit(1); + case 'c': + cull(); + break; + case 'f': + front = ((front == GL_CCW) ? GL_CW : GL_CCW); + glFrontFace(front); + printf("front face = %s\n", front == GL_CCW ? "GL_CCW" : "GL_CW"); + break; + default: + return; + } + glutPostRedisplay(); } static void Draw(void) @@ -72,12 +98,22 @@ static void Draw(void) glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES); - glColor3f(0,0,1); - glVertex3f( -1.5, 0.5, -30.0); - glColor3f(1,0,0); - glVertex3f( 0, 2.0, -30.0); - glColor3f(0,1,0); - glVertex3f(-1.5, 2.0, -30.0); + /* CCW / 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); + + /* CW / back-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(); glFlush(); @@ -118,7 +154,7 @@ int main(int argc, char **argv) glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); - type = GLUT_RGB; + type = GLUT_RGB | GLUT_ALPHA; type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); @@ -132,5 +168,5 @@ int main(int argc, char **argv) glutKeyboardFunc(Key); glutDisplayFunc(Draw); glutMainLoop(); - return 0; + return 0; } |