diff options
Diffstat (limited to 'progs')
-rw-r--r-- | progs/demos/multiarb.c | 123 | ||||
-rw-r--r-- | progs/glsl/trirast.c | 14 | ||||
-rw-r--r-- | progs/samples/blendeq.c | 97 | ||||
-rw-r--r-- | progs/tests/Makefile | 1 | ||||
-rw-r--r-- | progs/tests/exactrast.c | 200 | ||||
-rw-r--r-- | progs/tests/texline.c | 12 | ||||
-rw-r--r-- | progs/trivial/point-param.c | 57 | ||||
-rw-r--r-- | progs/xdemos/offset.c | 3 |
8 files changed, 369 insertions, 138 deletions
diff --git a/progs/demos/multiarb.c b/progs/demos/multiarb.c index d963985c69d..451fd11efe1 100644 --- a/progs/demos/multiarb.c +++ b/progs/demos/multiarb.c @@ -1,4 +1,3 @@ - /* * GL_ARB_multitexture demo * @@ -32,7 +31,6 @@ static GLint NumUnits = 1; static GLboolean TexEnabled[8]; static GLfloat Drift = 0.0; -static GLfloat drift_increment = 0.005; static GLfloat Xrot = 20.0, Yrot = 30.0, Zrot = 0.0; @@ -41,9 +39,7 @@ static void Idle( void ) if (Animate) { GLint i; - Drift += drift_increment; - if (Drift >= 1.0) - Drift = 0.0; + Drift = glutGet(GLUT_ELAPSED_TIME) * 0.001; for (i = 0; i < NumUnits; i++) { glActiveTextureARB(GL_TEXTURE0_ARB + i); @@ -57,10 +53,11 @@ static void Idle( void ) glTranslatef(0.0, Drift, 0.0); } else { - glTranslatef(0.5, 0.5, 0.0); + float tx = 0.5, ty = 0.5; + glTranslatef(tx, ty, 0.0); glRotatef(180.0 * Drift, 0, 0, 1); glScalef(1.0/i, 1.0/i, 1.0/i); - glTranslatef(-0.5, -0.5, 0.0); + glTranslatef(-tx, -ty + i * 0.1, 0.0); } } glMatrixMode(GL_MODELVIEW); @@ -72,10 +69,9 @@ static void Idle( void ) static void DrawObject(void) { - GLint i; - GLint j; - static const GLfloat tex_coords[] = { 0.0, 0.0, 1.0, 1.0, 0.0 }; - static const GLfloat vtx_coords[] = { -1.0, -1.0, 1.0, 1.0, -1.0 }; + static const GLfloat tex_coords[] = { 0.0, 0.0, 1.0, 1.0, 0.0 }; + static const GLfloat vtx_coords[] = { -1.0, -1.0, 1.0, 1.0, -1.0 }; + GLint i, j; if (!TexEnabled[0] && !TexEnabled[1]) glColor3f(0.1, 0.1, 0.1); /* add onto this */ @@ -83,37 +79,20 @@ static void DrawObject(void) glColor3f(1, 1, 1); /* modulate this */ glBegin(GL_QUADS); - - /* Toggle between the vector and scalar entry points. This is done purely - * to hit multiple paths in the driver. - */ - if ( Drift > 0.49 ) { - for (j = 0; j < 4; j++ ) { - for (i = 0; i < NumUnits; i++) - glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i, - tex_coords[j], tex_coords[j+1]); - glVertex2f( vtx_coords[j], vtx_coords[j+1] ); - } - } - else { - for (j = 0; j < 4; j++ ) { - for (i = 0; i < NumUnits; i++) - glMultiTexCoord2fvARB(GL_TEXTURE0_ARB + i, & tex_coords[j]); - glVertex2fv( & vtx_coords[j] ); + for (j = 0; j < 4; j++ ) { + for (i = 0; i < NumUnits; i++) { + if (TexEnabled[i]) + glMultiTexCoord2fARB(GL_TEXTURE0_ARB + i, + tex_coords[j], tex_coords[j+1]); } + glVertex2f( vtx_coords[j], vtx_coords[j+1] ); } - glEnd(); } - static void Display( void ) { - static GLint T0 = 0; - static GLint Frames = 0; - GLint t; - glClear( GL_COLOR_BUFFER_BIT ); glPushMatrix(); @@ -125,16 +104,6 @@ static void Display( void ) glPopMatrix(); glutSwapBuffers(); - - Frames++; - - t = glutGet(GLUT_ELAPSED_TIME); - if (t - T0 >= 250) { - GLfloat seconds = (t - T0) / 1000.0; - drift_increment = 2.2 * seconds / Frames; - T0 = t; - Frames = 0; - } } @@ -151,24 +120,34 @@ static void Reshape( int width, int height ) } +static void ToggleUnit(int unit) +{ + TexEnabled[unit] = !TexEnabled[unit]; + glActiveTextureARB(GL_TEXTURE0_ARB + unit); + if (TexEnabled[unit]) + glEnable(GL_TEXTURE_2D); + else + glDisable(GL_TEXTURE_2D); + printf("Enabled: "); + for (unit = 0; unit < NumUnits; unit++) + printf("%d ", (int) TexEnabled[unit]); + printf("\n"); +} + + static void ModeMenu(int entry) { if (entry >= TEX0 && entry <= TEX7) { /* toggle */ GLint i = entry - TEX0; - TexEnabled[i] = !TexEnabled[i]; - glActiveTextureARB(GL_TEXTURE0_ARB + i); - if (TexEnabled[i]) - glEnable(GL_TEXTURE_2D); - else - glDisable(GL_TEXTURE_2D); - printf("Enabled: "); - for (i = 0; i < NumUnits; i++) - printf("%d ", (int) TexEnabled[i]); - printf("\n"); + ToggleUnit(i); } else if (entry==ANIMATE) { Animate = !Animate; + if (Animate) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); } else if (entry==QUIT) { exit(0); @@ -183,9 +162,36 @@ static void Key( unsigned char key, int x, int y ) (void) x; (void) y; switch (key) { - case 27: - exit(0); - break; + case 'a': + Animate = !Animate; + break; + case '0': + ToggleUnit(0); + break; + case '1': + ToggleUnit(1); + break; + case '2': + ToggleUnit(2); + break; + case '3': + ToggleUnit(3); + break; + case '4': + ToggleUnit(4); + break; + case '5': + ToggleUnit(5); + break; + case '6': + ToggleUnit(6); + break; + case '7': + ToggleUnit(7); + break; + case 27: + exit(0); + break; } glutPostRedisplay(); } @@ -327,7 +333,8 @@ int main( int argc, char *argv[] ) glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); glutDisplayFunc( Display ); - glutIdleFunc( Idle ); + if (Animate) + glutIdleFunc(Idle); glutCreateMenu(ModeMenu); diff --git a/progs/glsl/trirast.c b/progs/glsl/trirast.c index e4325deb1f3..2842755447e 100644 --- a/progs/glsl/trirast.c +++ b/progs/glsl/trirast.c @@ -106,8 +106,12 @@ Redisplay(void) static void Idle(void) { - Zrot = glutGet(GLUT_ELAPSED_TIME) * 0.0005; - glutPostRedisplay(); + if (anim) { + Zrot = glutGet(GLUT_ELAPSED_TIME) * 0.0005; + glutPostRedisplay(); + } + else + abort(); } @@ -149,6 +153,12 @@ Key(unsigned char key, int x, int y) else glutIdleFunc(NULL); break; + case 'z': + Zrot = 0; + break; + case 's': + Zrot += 0.05; + break; case 27: CleanUp(); exit(0); diff --git a/progs/samples/blendeq.c b/progs/samples/blendeq.c index f78afd30381..d5143ecdf5c 100644 --- a/progs/samples/blendeq.c +++ b/progs/samples/blendeq.c @@ -25,6 +25,27 @@ static int doPrint = 1; static int deltaY; GLint windW, windH; +static const struct { + GLenum mode; + const char *name; +} LogicOpModes[] = { + { GL_SET, "GL_SET" }, + { GL_COPY, "GL_COPY" }, + { GL_NOOP, "GL_NOOP" }, + { GL_AND, "GL_AND" }, + { GL_INVERT, "GL_INVERT" }, + { GL_OR, "GL_OR" }, + { GL_XOR, "GL_XOR" }, + { GL_NOR, "GL_NOR" }, + { GL_NAND, "GL_NAND" }, + { GL_OR_REVERSE, "GL_OR_REVERSE" }, + { GL_OR_INVERTED, "GL_OR_INVERTED" }, + { GL_AND_INVERTED, "GL_AND_INVERTED" }, + { 0, NULL } +}; + + + static void DrawString(const char *string) { int i; @@ -47,7 +68,7 @@ static void Reshape(int width, int height) windH = (GLint)height; glViewport(0, 0, (GLint)width, (GLint)height); - deltaY = windH /16; + deltaY = windH /20; glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -105,7 +126,7 @@ static void Draw(void) { int stringOffset = 5, stringx = 8; int x1, x2, xleft, xright; - int i; + int i, k; (dithering) ? glEnable(GL_DITHER) : glDisable(GL_DITHER); glDisable(GL_BLEND); @@ -122,6 +143,7 @@ static void Draw(void) /* Draw labels */ glColor3f(0.8, 0.8, 0.0); i = windH - deltaY + stringOffset; + glRasterPos2f(stringx, i); i -= deltaY; DrawString("SOURCE"); glRasterPos2f(stringx, i); i -= deltaY; @@ -136,21 +158,12 @@ static void Draw(void) DrawString("reverse_subtract"); glRasterPos2f(stringx, i); i -= deltaY; DrawString("clear"); - glRasterPos2f(stringx, i); i -= deltaY; - DrawString("set"); - glRasterPos2f(stringx, i); i -= deltaY; - DrawString("copy"); - glRasterPos2f(stringx, i); i -= deltaY; - DrawString("noop"); - glRasterPos2f(stringx, i); i -= deltaY; - DrawString("and"); - glRasterPos2f(stringx, i); i -= deltaY; - DrawString("invert"); - glRasterPos2f(stringx, i); i -= deltaY; - DrawString("or"); - glRasterPos2f(stringx, i); i -= deltaY; - DrawString("xor"); + for (k = 0; LogicOpModes[k].name; k++) { + glRasterPos2f(stringx, i); + i -= deltaY; + DrawString(LogicOpModes[k].name); + } i = windH - deltaY; x1 = windW/4; @@ -193,43 +206,23 @@ static void Draw(void) glLogicOp(GL_CLEAR); glRectf(x1, i, x2, i+deltaY); - i -= deltaY; - glLogicOp(GL_SET); - glRectf(x1, i, x2, i+deltaY); - - i -= deltaY; - glLogicOp(GL_COPY); - glRectf(x1, i, x2, i+deltaY); - - i -= deltaY; - glLogicOp(GL_NOOP); - glRectf(x1, i, x2, i+deltaY); - - i -= deltaY; - glLogicOp(GL_AND); - glRectf(x1, i, x2, i+deltaY); - - i -= deltaY; - glLogicOp(GL_INVERT); - glRectf(x1, i, x2, i+deltaY); - - i -= deltaY; - glLogicOp(GL_OR); - glRectf(x1, i, x2, i+deltaY); - - i -= deltaY; - glLogicOp(GL_XOR); - glRectf(x1, i, x2, i+deltaY); - glRectf(x1, i+10, x2, i+5); + for (k = 0; LogicOpModes[k].name; k++) { + i -= deltaY; + glLogicOp(LogicOpModes[k].mode); + glRectf(x1, i, x2, i+deltaY); + if (LogicOpModes[k].mode == GL_XOR) { + glRectf(x1, i+10, x2, i+5); + } + } - if (doPrint) { - glDisable(GL_BLEND); - if (supportlogops & 2) + if (doPrint) { + glDisable(GL_BLEND); + if (supportlogops & 2) glDisable(GL_COLOR_LOGIC_OP); - glColor3f(1.0, 1.0, 1.0); - PrintColorStrings(); - } - glFlush(); + glColor3f(1.0, 1.0, 1.0); + PrintColorStrings(); + } + glFlush(); if (doubleBuffer) { glutSwapBuffers(); @@ -271,7 +264,7 @@ int main(int argc, char **argv) exit(1); } - glutInitWindowPosition(0, 0); glutInitWindowSize( 800, 400); + glutInitWindowPosition(0, 0); glutInitWindowSize( 800, 520); type = GLUT_RGB; type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; diff --git a/progs/tests/Makefile b/progs/tests/Makefile index 454b0adf9c1..18b051a14c0 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -35,6 +35,7 @@ SOURCES = \ cva.c \ dinoshade.c \ drawbuffers.c \ + exactrast.c \ floattex.c \ fbotest1.c \ fbotest2.c \ diff --git a/progs/tests/exactrast.c b/progs/tests/exactrast.c new file mode 100644 index 00000000000..56c0c79c3fa --- /dev/null +++ b/progs/tests/exactrast.c @@ -0,0 +1,200 @@ +/** + * Test for exact point/line/polygon rasterization, or at least rasterization + * that fits the tolerance of the OpenGL spec. + * + * Brian Paul + * 9 Nov 2007 + */ + +/* + * Notes: + * - 'm' to cycle through point, hline, vline and quad drawing + * - Use cursor keys to translate coordinates (z to reset) + * - Resize window to check for proper rasterization + * - Make sure your LCD is running in its native resolution + * + * If translation is (0,0): + * a point will be drawn where x%2==0 and y%2==0, + * a horizontal line will be drawn where x%2==0, + * a vertical line will be drawn where y%2==0, + * for quads, pixels will be set where (x%4)!=3 and (y%4)!=3 + * + * XXX todo: do glReadPixels and test that the results are what's expected. + * Upon failure, iterate over sub-pixel translations to find the ideal offset. + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <GL/glut.h> + +static int Width = 400, Height = 400; +static int Win; +static float Xtrans = 0, Ytrans = 0; +static float Step = 0.125; + +enum { + POINTS, + HLINES, + VLINES, + QUADS, + NUM_MODES +}; + +static int Mode = POINTS; + + +static void +Draw(void) +{ + /* See the OpenGL Programming Guide, Appendix H, "OpenGL Correctness Tips" + * for information about the 0.375 translation factor. + */ + float tx = 0.375, ty = 0.375; + int i, j; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glTranslatef(tx + Xtrans, ty + Ytrans, 0); + + if (Mode == POINTS) { + glBegin(GL_POINTS); + for (j = 0; j < Height; j += 2) { + for (i = 0; i < Width; i += 2) { + glVertex2f(i, j); + } + } + glEnd(); + } + else if (Mode == HLINES) { + glBegin(GL_LINES); + for (i = 0; i < Height; i += 2) { + glVertex2f(0, i); + glVertex2f(Width, i); + } + glEnd(); + } + else if (Mode == VLINES) { + glBegin(GL_LINES); + for (i = 0; i < Width; i += 2) { + glVertex2f(i, 0 ); + glVertex2f(i, Height); + } + glEnd(); + } + else if (Mode == QUADS) { + glBegin(GL_QUADS); + for (j = 0; j < Height; j += 4) { + for (i = 0; i < Width; i += 4) { + glVertex2f(i, j ); + glVertex2f(i + 3, j ); + glVertex2f(i + 3, j + 3); + glVertex2f(i, j + 3); + } + } + glEnd(); + } + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void +Reshape(int width, int height) +{ + Width = width; + Height = height; + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, width, 0, height, -1, 1); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case 'm': + case 'M': + Mode = (Mode + 1) % NUM_MODES; + break; + case 'z': + case 'Z': + Xtrans = Ytrans = 0; + printf("Translation: %f, %f\n", Xtrans, Ytrans); + break; + case 27: + glutDestroyWindow(Win); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void +SpecialKey(int key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_UP: + Ytrans += Step; + break; + case GLUT_KEY_DOWN: + Ytrans -= Step; + break; + case GLUT_KEY_LEFT: + Xtrans -= Step; + break; + case GLUT_KEY_RIGHT: + Xtrans += Step; + break; + } + glutPostRedisplay(); + printf("Translation: %f, %f\n", Xtrans, Ytrans); +} + + +static void +Init(void) +{ +} + + +static void +Usage(void) +{ + printf("Keys:\n"); + printf(" up/down/left/right - translate by %f\n", Step); + printf(" z - reset translation to zero\n"); + printf(" m - change rendering mode (points, hlines, vlines, quads)\n"); + printf(" Esc - exit\n"); +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowPosition(0, 0); + glutInitWindowSize(Width, Height); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + Win = glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(SpecialKey); + glutDisplayFunc(Draw); + Init(); + Usage(); + glutMainLoop(); + return 0; +} diff --git a/progs/tests/texline.c b/progs/tests/texline.c index 3d59d9ac264..d3935b94af8 100644 --- a/progs/tests/texline.c +++ b/progs/tests/texline.c @@ -7,7 +7,6 @@ * September 2000 */ - #include <stdio.h> #include <stdlib.h> #include <math.h> @@ -211,7 +210,9 @@ static void SpecialKey( int key, int x, int y ) static void Init( int argc, char *argv[] ) { + GLfloat r[2]; GLuint u; + for (u = 0; u < 2; u++) { glActiveTextureARB(GL_TEXTURE0_ARB + u); glBindTexture(GL_TEXTURE_2D, 10+u); @@ -242,6 +243,15 @@ static void Init( int argc, char *argv[] ) printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); } + + glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, r); + printf("Non-smooth point size range: %g .. %g\n", r[0], r[1]); + glGetFloatv(GL_POINT_SIZE_RANGE, r); + printf("Smoothed point size range: %g .. %g\n", r[0], r[1]); + glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, r); + printf("Non-smooth line width range: %g .. %g\n", r[0], r[1]); + glGetFloatv(GL_LINE_WIDTH_RANGE, r); + printf("Smoothed line width range: %g .. %g\n", r[0], r[1]); } diff --git a/progs/trivial/point-param.c b/progs/trivial/point-param.c index c5424682b85..02500cd34e8 100644 --- a/progs/trivial/point-param.c +++ b/progs/trivial/point-param.c @@ -22,15 +22,14 @@ * OF THIS SOFTWARE. */ +#define GL_GLEXT_PROTOTYPES +#include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <GL/glut.h> -#define CI_OFFSET_1 16 -#define CI_OFFSET_2 32 - GLenum doubleBuffer; @@ -40,53 +39,63 @@ static void Init(void) 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); } 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); + glOrtho(-1.0, 1.0, -1.0, 1.0, 0, 100.0); glMatrixMode(GL_MODELVIEW); } static void Key(unsigned char key, int x, int y) { - switch (key) { - case 27: + case 27: exit(1); - default: + default: return; } - glutPostRedisplay(); } + +static float +expected(float z, float size, const float atten[3]) +{ + float dist = fabs(z); + const GLfloat q = atten[0] + dist * (atten[1] + dist * atten[2]); + const GLfloat a = sqrt(1.0 / q); + return size * a; +} + + static void Draw(void) { - static GLfloat theQuad[3] = { 0.25, 0.0, 1/60.0 }; + static GLfloat atten[3] = { 0.0, 0.1, .01 }; + float size = 40.0; + int i; glClear(GL_COLOR_BUFFER_BIT); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glPointSize(8.0); - glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, theQuad); + glPointSize(size); + glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, atten); + glColor3f(1,0,0); + printf("Expected point sizes:\n"); glBegin(GL_POINTS); - glColor3f(1,0,0); - glVertex3f( 0.9, -0.9, -30.0); - glColor3f(1,1,0); - glVertex3f( 0.9, 0.9, -30.0); - glColor3f(1,0,1); - glVertex3f(-0.9, 0.9, -30.0); - glColor3f(0,1,1); - glVertex3f(-0.9, -0.9, -30.0); + for (i = 0; i < 5; i++) { + float x = -0.8 + i * 0.4; + float z = -i * 20 - 10; + glVertex3f( x, 0.0, z); + printf(" %f\n", expected(z, size, atten)); + } glEnd(); glFlush(); @@ -96,6 +105,7 @@ static void Draw(void) } } + static GLenum Args(int argc, char **argv) { GLint i; @@ -115,6 +125,7 @@ static GLenum Args(int argc, char **argv) return GL_TRUE; } + int main(int argc, char **argv) { GLenum type; @@ -131,7 +142,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(argv[0]) == GL_FALSE) { exit(1); } @@ -141,5 +152,5 @@ int main(int argc, char **argv) glutKeyboardFunc(Key); glutDisplayFunc(Draw); glutMainLoop(); - return 0; + return 0; } diff --git a/progs/xdemos/offset.c b/progs/xdemos/offset.c index 0ad9147aea6..6c5abf383be 100644 --- a/progs/xdemos/offset.c +++ b/progs/xdemos/offset.c @@ -47,7 +47,6 @@ PERFORMANCE OF THIS SOFTWARE. #include <GL/glx.h> -#include <GL/glu.h> #include <X11/keysym.h> #include <stdlib.h> #include <stdio.h> @@ -135,7 +134,7 @@ int main(int argc, char** argv) { /* set up viewing parameters */ glMatrixMode(GL_PROJECTION); - gluPerspective(20, 1, 10, 20); + glFrustum(-1, 1, -1, 1, 6, 20); glMatrixMode(GL_MODELVIEW); glTranslatef(0, 0, -15); |