From c691f96e9848d05947afc40ea5c14bc2989f00cf Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Mon, 20 Apr 2009 15:50:44 +0100 Subject: trivial/tri-viewport.c - add guide lines, more triangles, make interactive This is becoming more like a test than a trivial/ example. --- progs/trivial/tri-viewport.c | 132 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 118 insertions(+), 14 deletions(-) (limited to 'progs/trivial') diff --git a/progs/trivial/tri-viewport.c b/progs/trivial/tri-viewport.c index 8e5f155c7d..4cd64e0781 100644 --- a/progs/trivial/tri-viewport.c +++ b/progs/trivial/tri-viewport.c @@ -29,6 +29,10 @@ GLenum doubleBuffer = 1; int win; +static float tx = 0; +static float ty = 0; +static float tw = 250; +static float th = 250; static void Init(void) { @@ -42,15 +46,11 @@ static void Init(void) static void Reshape(int width, int height) { - glViewport(width / -2.0, height / -2.0, width, height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + tw = width; + th = height; } + static void Key(unsigned char key, int x, int y) { switch (key) { @@ -62,19 +62,91 @@ static void Key(unsigned char key, int x, int y) } } + static void Draw(void) { + int i; + + fprintf(stderr, "%f %f\n", tx, ty); + fflush(stderr); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode(GL_MODELVIEW); + glClear(GL_COLOR_BUFFER_BIT); + glViewport(0, 0, tw, th); + + glBegin(GL_LINES); + glColor3f(1,1,0); + glVertex3f(-1, 0, -30.0); + glVertex3f(1, 0, -30.0); + + glVertex3f(0, -1, -30.0); + glVertex3f(0, 1, -30.0); + glEnd(); + + + /* + */ + glViewport(tx, ty, tw, th); + + glBegin(GL_TRIANGLES); - glColor3f(.8,0,0); - glVertex3f(-0.9, 0.9, -30.0); - glColor3f(0,.9,0); - glVertex3f( 0.9, 0.9, -30.0); - glColor3f(0,0,.7); - glVertex3f( 0.0, -0.9, -30.0); + glColor3f(1,0,0); + glVertex3f(-1, -1, -30.0); + glVertex3f(0, -1, -30.0); + glVertex3f(-.5, -.5, -30.0); + + glColor3f(1,1,1); + glVertex3f(0, -1, -30.0); + glVertex3f(1, -1, -30.0); + glVertex3f(.5, -.5, -30.0); + + glVertex3f(-.5, -.5, -30.0); + glVertex3f(.5, -.5, -30.0); + glVertex3f(0, 0, -30.0); + + + glColor3f(0,1,0); + glVertex3f(1, 1, -30.0); + glVertex3f(0, 1, -30.0); + glVertex3f(.5, .5, -30.0); + + glColor3f(1,1,1); + glVertex3f(0, 1, -30.0); + glVertex3f(-1, 1, -30.0); + glVertex3f(-.5, .5, -30.0); + + glVertex3f(.5, .5, -30.0); + glVertex3f(-.5, .5, -30.0); + glVertex3f( 0, 0, -30.0); + + glEnd(); + + + glViewport(0, 0, tw, th); + + glBegin(GL_LINES); + glColor3f(.5,.5,0); + for (i = -10; i < 10; i++) { + float f = i / 10.0; + + if (i == 0) + continue; + + glVertex3f(-1, f, -30.0); + glVertex3f(1, f, -30.0); + + glVertex3f(f, -1, -30.0); + glVertex3f(f, 1, -30.0); + } glEnd(); + + glFlush(); if (doubleBuffer) { @@ -86,6 +158,13 @@ static GLenum Args(int argc, char **argv) { GLint i; + if (getenv("VPX")) + tx = atof(getenv("VPX")); + + if (getenv("VPY")) + ty = atof(getenv("VPY")); + + for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-sb") == 0) { doubleBuffer = GL_FALSE; @@ -99,6 +178,30 @@ static GLenum Args(int argc, char **argv) return GL_TRUE; } + +static void +special(int k, int x, int y) +{ + switch (k) { + case GLUT_KEY_UP: + ty += 1.0; + break; + case GLUT_KEY_DOWN: + ty -= 1.0; + break; + case GLUT_KEY_LEFT: + tx -= 1.0; + break; + case GLUT_KEY_RIGHT: + tx += 1.0; + break; + default: + return; + } + glutPostRedisplay(); +} + + int main(int argc, char **argv) { GLenum type; @@ -123,7 +226,8 @@ int main(int argc, char **argv) Init(); glutReshapeFunc(Reshape); - glutKeyboardFunc(Key); + glutKeyboardFunc(Key); + glutSpecialFunc(special); glutDisplayFunc(Draw); glutMainLoop(); return 0; -- cgit v1.2.3 From 6bfcffa79e8b7999e8193e721e07dbb3de4a1658 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Mon, 20 Apr 2009 17:30:53 +0100 Subject: trivial/tri_viewport: add width/height keys --- progs/trivial/tri-viewport.c | 67 ++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 18 deletions(-) (limited to 'progs/trivial') diff --git a/progs/trivial/tri-viewport.c b/progs/trivial/tri-viewport.c index 4cd64e0781..c08089b9dd 100644 --- a/progs/trivial/tri-viewport.c +++ b/progs/trivial/tri-viewport.c @@ -31,8 +31,11 @@ GLenum doubleBuffer = 1; int win; static float tx = 0; static float ty = 0; -static float tw = 250; -static float th = 250; +static float tw = 0; +static float th = 0; + +static float win_width = 250; +static float win_height = 250; static void Init(void) { @@ -41,33 +44,49 @@ static void Init(void) fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); fflush(stderr); - glClearColor(0.3, 0.1, 0.3, 0.0); + glClearColor(0, 0, 0, 0.0); } static void Reshape(int width, int height) { - tw = width; - th = height; + win_width = width; + win_height = height; + glutPostRedisplay(); } static void Key(unsigned char key, int x, int y) { switch (key) { - case 27: - exit(0); - default: - glutPostRedisplay(); - return; + case 27: + exit(0); + case 'w': + tw += 1.0; + break; + case 'W': + tw -= 1.0; + break; + case 'h': + th += 1.0; + break; + case 'H': + th -= 1.0; + break; + + default: + break; } + glutPostRedisplay(); } static void Draw(void) { int i; + float w = tw + win_width; + float h = th + win_height; - fprintf(stderr, "%f %f\n", tx, ty); + fprintf(stderr, "glViewport(%f %f %f %f)\n", tx, ty, w, h); fflush(stderr); glMatrixMode(GL_PROJECTION); @@ -77,8 +96,22 @@ static void Draw(void) glClear(GL_COLOR_BUFFER_BIT); - glViewport(0, 0, tw, th); + /*********************************************************************** + * Should be clipped to be no larger than the triangles: + */ + glViewport(tx, ty, w, h); + glBegin(GL_POLYGON); + glColor3f(.5,.5,1); + glVertex3f(-2, -2, -30.0); + glVertex3f(-2, 2, -30.0); + glVertex3f(2, 2, -30.0); + glVertex3f(2, -2, -30.0); + glEnd(); + + /*********************************************************************** + */ + glViewport(0, 0, win_width, win_height); glBegin(GL_LINES); glColor3f(1,1,0); glVertex3f(-1, 0, -30.0); @@ -89,11 +122,9 @@ static void Draw(void) glEnd(); - /* + /*********************************************************************** */ - glViewport(tx, ty, tw, th); - - + glViewport(tx, ty, w, h); glBegin(GL_TRIANGLES); glColor3f(1,0,0); glVertex3f(-1, -1, -30.0); @@ -127,7 +158,7 @@ static void Draw(void) glEnd(); - glViewport(0, 0, tw, th); + glViewport(0, 0, win_width, win_height); glBegin(GL_LINES); glColor3f(.5,.5,0); @@ -196,7 +227,7 @@ special(int k, int x, int y) tx += 1.0; break; default: - return; + break; } glutPostRedisplay(); } -- cgit v1.2.3 From a38f7d9e689f0e12cb8eed6b96a140805b452ba1 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Mon, 20 Apr 2009 17:32:15 +0100 Subject: trivial/tri_viewport: add space==reset key --- progs/trivial/tri-viewport.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'progs/trivial') diff --git a/progs/trivial/tri-viewport.c b/progs/trivial/tri-viewport.c index c08089b9dd..37e424467b 100644 --- a/progs/trivial/tri-viewport.c +++ b/progs/trivial/tri-viewport.c @@ -72,7 +72,9 @@ static void Key(unsigned char key, int x, int y) case 'H': th -= 1.0; break; - + case ' ': + tw = th = tx = ty = 0; + break; default: break; } -- cgit v1.2.3 From 6e05224bc4d00ba05fee8651d2a9ecbf2a4b3ca8 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 21 Apr 2009 10:59:54 +0100 Subject: trivial/tri-viewport: add more out-of-bounds background quads --- progs/trivial/tri-viewport.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'progs/trivial') diff --git a/progs/trivial/tri-viewport.c b/progs/trivial/tri-viewport.c index 37e424467b..133744235f 100644 --- a/progs/trivial/tri-viewport.c +++ b/progs/trivial/tri-viewport.c @@ -103,14 +103,40 @@ static void Draw(void) * Should be clipped to be no larger than the triangles: */ glViewport(tx, ty, w, h); + glBegin(GL_POLYGON); - glColor3f(.5,.5,1); + glColor3f(1,1,0); + glVertex3f(-100, -100, -30.0); + glVertex3f(-100, 100, -30.0); + glVertex3f(100, 100, -30.0); + glVertex3f(100, -100, -30.0); + glEnd(); + + glBegin(GL_POLYGON); + glColor3f(0,1,1); + glVertex3f(-10, -10, -30.0); + glVertex3f(-10, 10, -30.0); + glVertex3f(10, 10, -30.0); + glVertex3f(10, -10, -30.0); + glEnd(); + + glBegin(GL_POLYGON); + glColor3f(1,0,0); glVertex3f(-2, -2, -30.0); glVertex3f(-2, 2, -30.0); glVertex3f(2, 2, -30.0); glVertex3f(2, -2, -30.0); glEnd(); + + glBegin(GL_POLYGON); + glColor3f(.5,.5,1); + glVertex3f(-1, -1, -30.0); + glVertex3f(-1, 1, -30.0); + glVertex3f(1, 1, -30.0); + glVertex3f(1, -1, -30.0); + glEnd(); + /*********************************************************************** */ glViewport(0, 0, win_width, win_height); -- cgit v1.2.3 From e20f837f672e43671890d5f62f9814487e15531f Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 21 Apr 2009 11:40:59 +0100 Subject: trivial/tri-viewport: add keys for frustrum/ortho and z coordinate --- progs/trivial/tri-viewport.c | 120 +++++++++++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 43 deletions(-) (limited to 'progs/trivial') diff --git a/progs/trivial/tri-viewport.c b/progs/trivial/tri-viewport.c index 133744235f..3e52449b47 100644 --- a/progs/trivial/tri-viewport.c +++ b/progs/trivial/tri-viewport.c @@ -33,9 +33,16 @@ static float tx = 0; static float ty = 0; static float tw = 0; static float th = 0; +static float z = -5; + static float win_width = 250; static float win_height = 250; +static enum { + ORTHO, + FRUSTUM, + MODE_MAX +} mode = ORTHO; static void Init(void) { @@ -72,8 +79,21 @@ static void Key(unsigned char key, int x, int y) case 'H': th -= 1.0; break; + + case 'z': + z += 1.0; + break; + case 'Z': + z -= 1.0; + break; + case 'm': + mode++; + mode %= MODE_MAX; + break; case ' ': tw = th = tx = ty = 0; + z = -5; + mode = ORTHO; break; default: break; @@ -89,12 +109,26 @@ static void Draw(void) float h = th + win_height; fprintf(stderr, "glViewport(%f %f %f %f)\n", tx, ty, w, h); + fprintf(stderr, "mode: %s\n", mode == FRUSTUM ? "FRUSTUM" : "ORTHO"); + fprintf(stderr, "z: %f\n", z); fflush(stderr); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + + switch (mode) { + case FRUSTUM: + glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); + break; + case ORTHO: + default: + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + break; + } + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glClear(GL_COLOR_BUFFER_BIT); @@ -106,35 +140,35 @@ static void Draw(void) glBegin(GL_POLYGON); glColor3f(1,1,0); - glVertex3f(-100, -100, -30.0); - glVertex3f(-100, 100, -30.0); - glVertex3f(100, 100, -30.0); - glVertex3f(100, -100, -30.0); + glVertex3f(-100, -100, z); + glVertex3f(-100, 100, z); + glVertex3f(100, 100, z); + glVertex3f(100, -100, z); glEnd(); glBegin(GL_POLYGON); glColor3f(0,1,1); - glVertex3f(-10, -10, -30.0); - glVertex3f(-10, 10, -30.0); - glVertex3f(10, 10, -30.0); - glVertex3f(10, -10, -30.0); + glVertex3f(-10, -10, z); + glVertex3f(-10, 10, z); + glVertex3f(10, 10, z); + glVertex3f(10, -10, z); glEnd(); glBegin(GL_POLYGON); glColor3f(1,0,0); - glVertex3f(-2, -2, -30.0); - glVertex3f(-2, 2, -30.0); - glVertex3f(2, 2, -30.0); - glVertex3f(2, -2, -30.0); + glVertex3f(-2, -2, z); + glVertex3f(-2, 2, z); + glVertex3f(2, 2, z); + glVertex3f(2, -2, z); glEnd(); glBegin(GL_POLYGON); glColor3f(.5,.5,1); - glVertex3f(-1, -1, -30.0); - glVertex3f(-1, 1, -30.0); - glVertex3f(1, 1, -30.0); - glVertex3f(1, -1, -30.0); + glVertex3f(-1, -1, z); + glVertex3f(-1, 1, z); + glVertex3f(1, 1, z); + glVertex3f(1, -1, z); glEnd(); /*********************************************************************** @@ -142,11 +176,11 @@ static void Draw(void) glViewport(0, 0, win_width, win_height); glBegin(GL_LINES); glColor3f(1,1,0); - glVertex3f(-1, 0, -30.0); - glVertex3f(1, 0, -30.0); + glVertex3f(-1, 0, z); + glVertex3f(1, 0, z); - glVertex3f(0, -1, -30.0); - glVertex3f(0, 1, -30.0); + glVertex3f(0, -1, z); + glVertex3f(0, 1, z); glEnd(); @@ -155,33 +189,33 @@ static void Draw(void) glViewport(tx, ty, w, h); glBegin(GL_TRIANGLES); glColor3f(1,0,0); - glVertex3f(-1, -1, -30.0); - glVertex3f(0, -1, -30.0); - glVertex3f(-.5, -.5, -30.0); + glVertex3f(-1, -1, z); + glVertex3f(0, -1, z); + glVertex3f(-.5, -.5, z); glColor3f(1,1,1); - glVertex3f(0, -1, -30.0); - glVertex3f(1, -1, -30.0); - glVertex3f(.5, -.5, -30.0); + glVertex3f(0, -1, z); + glVertex3f(1, -1, z); + glVertex3f(.5, -.5, z); - glVertex3f(-.5, -.5, -30.0); - glVertex3f(.5, -.5, -30.0); - glVertex3f(0, 0, -30.0); + glVertex3f(-.5, -.5, z); + glVertex3f(.5, -.5, z); + glVertex3f(0, 0, z); glColor3f(0,1,0); - glVertex3f(1, 1, -30.0); - glVertex3f(0, 1, -30.0); - glVertex3f(.5, .5, -30.0); + glVertex3f(1, 1, z); + glVertex3f(0, 1, z); + glVertex3f(.5, .5, z); glColor3f(1,1,1); - glVertex3f(0, 1, -30.0); - glVertex3f(-1, 1, -30.0); - glVertex3f(-.5, .5, -30.0); + glVertex3f(0, 1, z); + glVertex3f(-1, 1, z); + glVertex3f(-.5, .5, z); - glVertex3f(.5, .5, -30.0); - glVertex3f(-.5, .5, -30.0); - glVertex3f( 0, 0, -30.0); + glVertex3f(.5, .5, z); + glVertex3f(-.5, .5, z); + glVertex3f( 0, 0, z); glEnd(); @@ -196,11 +230,11 @@ static void Draw(void) if (i == 0) continue; - glVertex3f(-1, f, -30.0); - glVertex3f(1, f, -30.0); + glVertex3f(-1, f, z); + glVertex3f(1, f, z); - glVertex3f(f, -1, -30.0); - glVertex3f(f, 1, -30.0); + glVertex3f(f, -1, z); + glVertex3f(f, 1, z); } glEnd(); -- cgit v1.2.3 From 482be01db02d3ea224e01c24c4d1638229d6a4dc Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Wed, 29 Apr 2009 14:21:41 +0100 Subject: trivial: add line-flat.c --- progs/trivial/Makefile | 1 + progs/trivial/SConscript | 1 + progs/trivial/line-flat.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 progs/trivial/line-flat.c (limited to 'progs/trivial') diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index 69c71cbaf6..e255cdadc5 100644 --- a/progs/trivial/Makefile +++ b/progs/trivial/Makefile @@ -30,6 +30,7 @@ SOURCES = \ fs-tri.c \ line-clip.c \ line-cull.c \ + line-flat.c \ line-smooth.c \ line-stipple-wide.c \ line-userclip-clip.c \ diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index 480630e210..0333418ad8 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -26,6 +26,7 @@ progs = [ 'fs-tri', 'line-clip', 'line-cull', + 'line-flat', 'line-smooth', 'line-stipple-wide', 'line-userclip-clip', diff --git a/progs/trivial/line-flat.c b/progs/trivial/line-flat.c new file mode 100644 index 0000000000..14f0ac0782 --- /dev/null +++ b/progs/trivial/line-flat.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF + * ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + + +#define CI_OFFSET_1 16 +#define CI_OFFSET_2 32 + + +GLenum doubleBuffer; + +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)); + fflush(stderr); + + glClearColor(0.0, 0.0, 1.0, 0.0); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + glShadeModel(GL_FLAT); + + glBegin(GL_LINES); + glColor3f(0,0,.7); + glVertex3f( 0.9, -0.9, -30.0); + glColor3f(.8,0,0); + glVertex3f( 0.9, 0.9, -30.0); + + glColor3f(.8,0,0); + glVertex3f( 0.9, 0.9, -30.0); + glColor3f(0,.9,0); + glVertex3f(-0.9, 0.0, -30.0); + + + glColor3f(0,.9,0); + glVertex3f(-0.9, 0.0, -30.0); + glColor3f(0,0,.7); + glVertex3f( 0.9, -0.9, -30.0); + glEnd(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + fprintf(stderr, "%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); + + type = GLUT_RGB; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow(*argv) == GL_FALSE) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From e99729d63d50dd7e1dffc8b739b6f9decc834925 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Thu, 30 Apr 2009 12:35:59 +0100 Subject: progs/trivial: add vbo-noninterleaved test --- progs/trivial/Makefile | 1 + progs/trivial/SConscript | 1 + progs/trivial/vbo-noninterleaved.c | 139 +++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 progs/trivial/vbo-noninterleaved.c (limited to 'progs/trivial') diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index e255cdadc5..69b0408bbd 100644 --- a/progs/trivial/Makefile +++ b/progs/trivial/Makefile @@ -139,6 +139,7 @@ SOURCES = \ tristrip-flat.c \ tristrip.c \ vbo-drawarrays.c \ + vbo-noninterleaved.c \ vbo-drawelements.c \ vbo-drawrange.c \ vp-array.c \ diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index 0333418ad8..03ccb1436d 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -135,6 +135,7 @@ progs = [ 'tristrip-flat', 'tristrip', 'vbo-drawarrays', + 'vbo-noninterleaved', 'vbo-drawelements', 'vbo-drawrange', 'vp-array', diff --git a/progs/trivial/vbo-noninterleaved.c b/progs/trivial/vbo-noninterleaved.c new file mode 100644 index 0000000000..0672ca50ff --- /dev/null +++ b/progs/trivial/vbo-noninterleaved.c @@ -0,0 +1,139 @@ +/* Basic VBO */ + +#include +#include +#include +#include +#include +#include +#include + + +struct { + GLfloat pos[4][4]; + GLfloat col[4][4]; +} verts = +{ + /* Position: a quad + */ + { + { 0.9, -0.9, 0.0, 1.0 }, + { 0.9, 0.9, 0.0, 1.0 }, + { -0.9, 0.9, 0.0, 1.0 }, + { -0.9, -0.9, 0.0, 1.0 }, + }, + + /* Color: all red + */ + { + { 1.0, 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 0.0, 1.0 }, + }, + + +}; + +GLuint arrayObj, elementObj; + +static void Init( void ) +{ + GLint errno; + GLuint prognum; + + static const char *prog1 = + "!!ARBvp1.0\n" + "MOV result.color, vertex.color;\n" + "MOV result.position, vertex.position;\n" + "END\n"; + + glGenProgramsARB(1, &prognum); + glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum); + glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(prog1), (const GLubyte *) prog1); + + assert(glIsProgramARB(prognum)); + errno = glGetError(); + printf("glGetError = %d\n", errno); + if (errno != GL_NO_ERROR) + { + GLint errorpos; + + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); + printf("errorpos: %d\n", errorpos); + printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + } + + + glEnableClientState( GL_VERTEX_ARRAY ); + glEnableClientState( GL_COLOR_ARRAY ); + + glGenBuffersARB(1, &arrayObj); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrayObj); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), &verts, GL_STATIC_DRAW_ARB); + + glVertexPointer( 4, GL_FLOAT, sizeof(verts.pos[0]), 0 ); + glColorPointer( 4, GL_FLOAT, sizeof(verts.col[0]), (void *)(4*4*sizeof(float)) ); + +} + + + +static void Display( void ) +{ + glClearColor(0.3, 0.3, 0.3, 1); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glEnable(GL_VERTEX_PROGRAM_ARB); + +// glDrawArrays( GL_TRIANGLES, 0, 3 ); +// glDrawArrays( GL_TRIANGLES, 1, 3 ); + glDrawArrays( GL_QUADS, 0, 4 ); + + glFlush(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + /*glTranslatef( 0.0, 0.0, -15.0 );*/ +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 250, 250 ); + glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH ); + glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From d56b0e6847255410ccb958068f0828fd2543aaba Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 5 May 2009 13:00:44 +0100 Subject: progs/trivial: add test for vertex program invarient transform --- progs/trivial/Makefile | 1 + progs/trivial/SConscript | 1 + progs/trivial/vp-tri-invariant.c | 147 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 progs/trivial/vp-tri-invariant.c (limited to 'progs/trivial') diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index 69b0408bbd..22de83fa79 100644 --- a/progs/trivial/Makefile +++ b/progs/trivial/Makefile @@ -147,6 +147,7 @@ SOURCES = \ vp-clip.c \ vp-line-clip.c \ vp-tri.c \ + vp-tri-invariant.c \ vp-tri-swap.c \ vp-tri-tex.c \ vp-tri-imm.c \ diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index 03ccb1436d..9a1f3575bd 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -143,6 +143,7 @@ progs = [ 'vp-clip', 'vp-line-clip', 'vp-tri', + 'vp-tri-invariant', 'vp-tri-swap', 'vp-tri-tex', 'vp-tri-imm', diff --git a/progs/trivial/vp-tri-invariant.c b/progs/trivial/vp-tri-invariant.c new file mode 100644 index 0000000000..ff24139365 --- /dev/null +++ b/progs/trivial/vp-tri-invariant.c @@ -0,0 +1,147 @@ +/* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */ + +#include +#include +#include +#include +#include +#include + + +#define CI_OFFSET_1 16 +#define CI_OFFSET_2 32 + + +GLenum doubleBuffer; + +static void Init(void) +{ + GLint errno; + GLuint prognum; + + static const char *prog1 = + "!!ARBvp1.0\n" + "OPTION ARB_position_invariant ;" + "MOV result.color, vertex.color;\n" + "END\n"; + + + glGenProgramsARB(1, &prognum); + + glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum); + glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(prog1), (const GLubyte *) prog1); + + errno = glGetError(); + printf("glGetError = %d\n", errno); + if (errno != GL_NO_ERROR) + { + GLint errorpos; + + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); + printf("errorpos: %d\n", errorpos); + printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + } + + 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)); + fflush(stderr); + + glClearColor(0.0, 0.0, 1.0, 0.0); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); +/* glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); */ + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glEnable(GL_VERTEX_PROGRAM_ARB); + + glBegin(GL_TRIANGLES); + glColor3f(0,0,.7); + glVertex3f( 0.9, -0.9, -0.0); + glColor3f(.8,0,0); + glVertex3f( 0.9, 0.9, -0.0); + glColor3f(0,.9,0); + glVertex3f(-0.9, 0.0, -0.0); + glEnd(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + fprintf(stderr, "%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); + + type = GLUT_RGB | GLUT_ALPHA; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow(*argv) == GL_FALSE) { + exit(1); + } + + glewInit(); + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From f5cf181c65293fd9097f63192c09f44b9c82c633 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 11 May 2009 16:08:01 -0600 Subject: trivial: destroy window upon exit --- progs/trivial/tri.c | 1 + 1 file changed, 1 insertion(+) (limited to 'progs/trivial') diff --git a/progs/trivial/tri.c b/progs/trivial/tri.c index d44cb6a9fe..cac3fcb7d9 100644 --- a/progs/trivial/tri.c +++ b/progs/trivial/tri.c @@ -60,6 +60,7 @@ static void Key(unsigned char key, int x, int y) { switch (key) { case 27: + glutDestroyWindow(win); exit(0); default: glutPostRedisplay(); -- cgit v1.2.3 From 723bc9452fee2602fa702699141e91b87872e621 Mon Sep 17 00:00:00 2001 From: Joakim Sindholt Date: Tue, 12 May 2009 19:38:17 +0200 Subject: progs/trivial: update .gitignore with new binaries --- progs/trivial/.gitignore | 3 +++ 1 file changed, 3 insertions(+) (limited to 'progs/trivial') diff --git a/progs/trivial/.gitignore b/progs/trivial/.gitignore index 8dcb20a68f..dce733a70a 100644 --- a/progs/trivial/.gitignore +++ b/progs/trivial/.gitignore @@ -19,6 +19,7 @@ fs-tri line line-clip line-cull +line-flat line-smooth line-stipple-wide line-userclip @@ -130,6 +131,7 @@ tristrip-flat vbo-drawarrays vbo-drawelements vbo-drawrange +vbo-noninterleaved vp-array vp-array-int vp-clip @@ -139,6 +141,7 @@ vp-tri-cb vp-tri-cb-pos vp-tri-cb-tex vp-tri-imm +vp-tri-invariant vp-tri-swap vp-tri-tex vp-unfilled -- cgit v1.2.3 From 00e7a600776ceb589bd5939ccd8aad937527db81 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Wed, 13 May 2009 13:47:38 +0100 Subject: trivial/tri-z: add controls for depthrange min/max Also add key to set up quake-1 style ztrick rendering with clear depth 1.0, deptrange(1.0, 0.0) and depthfunc GL_GREATER. --- progs/trivial/tri-z.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) (limited to 'progs/trivial') diff --git a/progs/trivial/tri-z.c b/progs/trivial/tri-z.c index 335d2b90e2..014aaa071a 100644 --- a/progs/trivial/tri-z.c +++ b/progs/trivial/tri-z.c @@ -57,13 +57,19 @@ static struct { GLenum func; const char *str; } funcs[] = static int curFunc = 0; static double clearVal = 1.0; - +static float minZ = 0.0; +static float maxZ = 1.0; static void usage(void) { - printf("t - toggle rendering order of triangles\n"); - printf("c - toggle Z clear value between 0, 1\n"); - printf("f - cycle through depth test functions\n"); + printf("t - toggle rendering order of triangles\n"); + printf("c - toggle Z clear value between 0, 1\n"); + printf("f - cycle through depth test functions\n"); + printf("n/N - decrease/increase depthrange minZ\n"); + printf("x/X - decrease/increase depthrange maxZ\n"); + printf("spc - reset\n"); + printf("z - set to reverse-direction (ztrick) mode\n"); + fflush(stdout); } @@ -97,9 +103,11 @@ static void drawRightTriangle(void) void display(void) { - printf("GL_CLEAR_DEPTH = %f GL_DEPTH_FUNC = %s\n", - clearVal, funcs[curFunc].str); + printf("GL_CLEAR_DEPTH = %.2f, GL_DEPTH_FUNC = %s, DepthRange(%.1f, %.1f)\n", + clearVal, funcs[curFunc].str, minZ, maxZ); + fflush(stdout); glClearDepth(clearVal); + glDepthRange(minZ, maxZ); glDepthFunc(funcs[curFunc].func); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -131,27 +139,49 @@ void reshape(int w, int h) void keyboard(unsigned char key, int x, int y) { switch (key) { + case 'n': + minZ -= .1; + break; + case 'N': + minZ += .1; + break; + case 'x': + maxZ -= .1; + break; + case 'X': + maxZ += .1; + break; case 'c': case 'C': clearVal = 1.0 - clearVal; - glutPostRedisplay(); break; case 'f': case 'F': curFunc = (curFunc + 1) % NUM_FUNCS; - glutPostRedisplay(); break; case 't': case 'T': leftFirst = !leftFirst; - glutPostRedisplay(); + break; + case ' ': + curFunc = 0; + clearVal = 1.0; + minZ = 0.0; + maxZ = 1.0; + break; + case 'z': + curFunc = 2; + clearVal = 0.0; + minZ = 1.0; + maxZ = 0.0; break; case 27: /* Escape key */ exit(0); break; default: - break; + return; } + glutPostRedisplay(); } /* Main Loop -- cgit v1.2.3