diff options
Diffstat (limited to 'progs')
258 files changed, 5326 insertions, 391 deletions
diff --git a/progs/SConscript b/progs/SConscript index 6484c761fc5..71ebe5e0f37 100644 --- a/progs/SConscript +++ b/progs/SConscript @@ -3,6 +3,10 @@ SConscript([ 'demos/SConscript', 'redbook/SConscript', 'samples/SConscript', + 'tests/SConscript', 'trivial/SConscript', 'vp/SConscript', + 'vpglsl/SConscript', + 'fp/SConscript', + 'wgl/SConscript', ]) diff --git a/progs/demos/arbfplight.c b/progs/demos/arbfplight.c index 401bfb49684..7b7a12bf88d 100644 --- a/progs/demos/arbfplight.c +++ b/progs/demos/arbfplight.c @@ -92,6 +92,7 @@ static void Redisplay( void ) GLfloat seconds = (t - T0) / 1000.0; GLfloat fps = Frames / seconds; printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); + fflush(stdout); T0 = t; Frames = 0; } diff --git a/progs/demos/arbfslight.c b/progs/demos/arbfslight.c index a84491d34fe..275c85105ed 100644 --- a/progs/demos/arbfslight.c +++ b/progs/demos/arbfslight.c @@ -105,6 +105,7 @@ static void Redisplay (void) GLfloat seconds = (GLfloat) (t - t0) / 1000.0f; GLfloat fps = frames / seconds; printf ("%d frames in %6.3f seconds = %6.3f FPS\n", frames, seconds, fps); + fflush(stdout); t0 = t; frames = 0; } diff --git a/progs/demos/cubemap.c b/progs/demos/cubemap.c index b3bdd64f68d..26db42aed5e 100644 --- a/progs/demos/cubemap.c +++ b/progs/demos/cubemap.c @@ -39,6 +39,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <GL/glew.h> #include "GL/glut.h" #include "readtex.h" @@ -49,6 +50,45 @@ static GLboolean use_vertex_arrays = GL_FALSE; static GLboolean anim = GL_TRUE; static GLboolean NoClear = GL_FALSE; static GLint FrameParity = 0; +static GLenum FilterIndex = 0; +static GLint ClampIndex = 0; + + +static struct { + GLenum mode; + const char *name; +} ClampModes[] = { + { GL_CLAMP_TO_EDGE, "GL_CLAMP_TO_EDGE" }, + { GL_CLAMP_TO_BORDER, "GL_CLAMP_TO_BORDER" }, + { GL_CLAMP, "GL_CLAMP" }, + { GL_REPEAT, "GL_REPEAT" } +}; + +#define NUM_CLAMP_MODES (sizeof(ClampModes) / sizeof(ClampModes[0])) + + +static struct { + GLenum mag_mode, min_mode; + const char *name; +} FilterModes[] = { + { GL_NEAREST, GL_NEAREST, "GL_NEAREST, GL_NEAREST" }, + { GL_NEAREST, GL_LINEAR, "GL_NEAREST, GL_LINEAR" }, + { GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, "GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST" }, + { GL_NEAREST, GL_NEAREST_MIPMAP_LINEAR, "GL_NEAREST, GL_NEAREST_MIPMAP_LINEAR" }, + { GL_NEAREST, GL_LINEAR_MIPMAP_NEAREST, "GL_NEAREST, GL_LINEAR_MIPMAP_NEAREST" }, + { GL_NEAREST, GL_LINEAR_MIPMAP_LINEAR, "GL_NEAREST, GL_LINEAR_MIPMAP_LINEAR" }, + + { GL_LINEAR, GL_NEAREST, "GL_LINEAR, GL_NEAREST" }, + { GL_LINEAR, GL_LINEAR, "GL_LINEAR, GL_LINEAR" }, + { GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, "GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST" }, + { GL_LINEAR, GL_NEAREST_MIPMAP_LINEAR, "GL_LINEAR, GL_NEAREST_MIPMAP_LINEAR" }, + { GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, "GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST" }, + { GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR, "GL_LINEAR, GL_LINEAR_MIPMAP_LINEAR" } +}; + +#define NUM_FILTER_MODES (sizeof(FilterModes) / sizeof(FilterModes[0])) + + #define eps1 0.99 #define br 20.0 /* box radius */ @@ -158,6 +198,8 @@ static void draw_skybox( void ) static void draw( void ) { + GLenum wrap; + if (NoClear) { /* This demonstrates how we can avoid calling glClear. * This method only works if every pixel in the window is painted for @@ -183,6 +225,16 @@ static void draw( void ) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, + FilterModes[FilterIndex].min_mode); + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, + FilterModes[FilterIndex].mag_mode); + + wrap = ClampModes[ClampIndex].mode; + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, wrap); + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, wrap); + glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, wrap); + glPushMatrix(); /*MODELVIEW*/ glTranslatef( 0.0, 0.0, -EyeDist ); @@ -256,6 +308,14 @@ static void key(unsigned char k, int x, int y) else glutIdleFunc(NULL); break; + case 'f': + FilterIndex = (FilterIndex + 1) % NUM_FILTER_MODES; + printf("Tex filter: %s\n", FilterModes[FilterIndex].name); + break; + case 'c': + ClampIndex = (ClampIndex + 1) % NUM_CLAMP_MODES; + printf("Tex wrap mode: %s\n", ClampModes[ClampIndex].name); + break; case 'm': mode = !mode; set_mode(mode); @@ -321,7 +381,7 @@ static void reshape(int width, int height) static void init_checkers( void ) { #define CUBE_TEX_SIZE 64 - GLubyte image[CUBE_TEX_SIZE][CUBE_TEX_SIZE][3]; + GLubyte image[CUBE_TEX_SIZE][CUBE_TEX_SIZE][4]; static const GLubyte colors[6][3] = { { 255, 0, 0 }, /* face 0 - red */ { 0, 255, 255 }, /* face 1 - cyan */ @@ -348,21 +408,25 @@ static void init_checkers( void ) for (i = 0; i < CUBE_TEX_SIZE; i++) { for (j = 0; j < CUBE_TEX_SIZE; j++) { if ((i/4 + j/4) & 1) { - image[i][j][0] = colors[f][0]; + image[i][j][0] = colors[f][2]; image[i][j][1] = colors[f][1]; - image[i][j][2] = colors[f][2]; + image[i][j][2] = colors[f][0]; + image[i][j][3] = 255; } else { image[i][j][0] = 255; image[i][j][1] = 255; image[i][j][2] = 255; + image[i][j][3] = 255; } } } - glTexImage2D(targets[f], 0, GL_RGB, CUBE_TEX_SIZE, CUBE_TEX_SIZE, 0, - GL_RGB, GL_UNSIGNED_BYTE, image); + glTexImage2D(targets[f], 0, GL_RGBA8, CUBE_TEX_SIZE, CUBE_TEX_SIZE, 0, + GL_BGRA, GL_UNSIGNED_BYTE, image); } + + glGenerateMipmapEXT(GL_TEXTURE_CUBE_MAP_ARB); } @@ -431,32 +495,30 @@ static void load_envmaps(void) static void init( GLboolean useImageFiles ) { - GLenum filter; - - /* check for extension */ + /* check for extensions */ { char *exten = (char *) glGetString(GL_EXTENSIONS); if (!strstr(exten, "GL_ARB_texture_cube_map")) { printf("Sorry, this demo requires GL_ARB_texture_cube_map\n"); exit(0); } + + /* Needed for glGenerateMipmapEXT + */ + if (!strstr(exten, "GL_EXT_framebuffer_object")) { + printf("Sorry, this demo requires GL_EXT_framebuffer_object\n"); + exit(0); + } } printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER)); if (useImageFiles) { load_envmaps(); - filter = GL_LINEAR; } else { init_checkers(); - filter = GL_NEAREST; } - glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, filter); - glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, filter); - glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - glEnable(GL_TEXTURE_CUBE_MAP_ARB); glEnable(GL_DEPTH_TEST); @@ -472,6 +534,8 @@ static void usage(void) printf("keys:\n"); printf(" SPACE - toggle animation\n"); printf(" CURSOR KEYS - rotation\n"); + printf(" c - toggle texture clamp/wrap mode\n"); + printf(" f - toggle texture filter mode\n"); printf(" m - toggle texgen reflection mode\n"); printf(" z/Z - change viewing distance\n"); } @@ -502,6 +566,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize(600, 500); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); glutCreateWindow("Texture Cube Mapping"); + glewInit(); glutReshapeFunc( reshape ); glutKeyboardFunc( key ); glutSpecialFunc( specialkey ); diff --git a/progs/demos/engine.c b/progs/demos/engine.c index 14fd1e68629..3cf311e7782 100644 --- a/progs/demos/engine.c +++ b/progs/demos/engine.c @@ -386,7 +386,10 @@ DrawPositionedPiston(const Engine *eng, float crankAngle) glPushMatrix(); glRotatef(-90, 1, 0, 0); glTranslatef(0, 0, pos); - DrawPiston(eng); + if (eng->PistonList) + glCallList(eng->PistonList); + else + DrawPiston(eng); glPopMatrix(); } @@ -961,6 +964,28 @@ Draw(void) glEnable(GL_TEXTURE_2D); } + /* also print out a periodic fps to stdout. useful for trying to + * figure out the performance impact of rendering the string above + * with glBitmap. + */ + { + static GLint T0 = 0; + static GLint Frames = 0; + GLint t = glutGet(GLUT_ELAPSED_TIME); + + Frames++; + + if (t - T0 >= 5000) { + GLfloat seconds = (t - T0) / 1000.0; + GLfloat fps = Frames / seconds; + printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); + fflush(stdout); + T0 = t; + Frames = 0; + } + } + + glutSwapBuffers(); } diff --git a/progs/demos/fslight.c b/progs/demos/fslight.c index e79b5cc1970..41a13cc9f46 100644 --- a/progs/demos/fslight.c +++ b/progs/demos/fslight.c @@ -105,6 +105,7 @@ Redisplay(void) GLfloat fps = frames / seconds; printf("%d frames in %6.3f seconds = %6.3f FPS\n", frames, seconds, fps); + fflush(stdout); t0 = t; frames = 0; } diff --git a/progs/demos/gearbox.c b/progs/demos/gearbox.c index 35bde04417b..2dcf32f92ff 100644 --- a/progs/demos/gearbox.c +++ b/progs/demos/gearbox.c @@ -314,6 +314,7 @@ draw(void) GLfloat seconds = (t - T0) / 1000.0; GLfloat fps = Frames / seconds; printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); + fflush(stdout); T0 = t; Frames = 0; } diff --git a/progs/demos/gears.c b/progs/demos/gears.c index 2a9fefefb53..6016162d6f7 100644 --- a/progs/demos/gears.c +++ b/progs/demos/gears.c @@ -219,6 +219,7 @@ draw(void) GLfloat seconds = (t - T0) / 1000.0; GLfloat fps = Frames / seconds; printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); + fflush(stdout); T0 = t; Frames = 0; if ((t >= 999.0 * autoexit) && (autoexit)) { diff --git a/progs/demos/geartrain.c b/progs/demos/geartrain.c index 8363f2abc6d..8fe405e8076 100644 --- a/progs/demos/geartrain.c +++ b/progs/demos/geartrain.c @@ -905,6 +905,7 @@ draw (void) GLfloat seconds = (t - T0) / 1000.0; GLfloat fps = Frames / seconds; printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps); + fflush(stdout); T0 = t; Frames = 0; } diff --git a/progs/demos/gloss.c b/progs/demos/gloss.c index b2126e32678..69694b23a09 100644 --- a/progs/demos/gloss.c +++ b/progs/demos/gloss.c @@ -132,6 +132,7 @@ static void Display( void ) GLfloat seconds = (t - T0) / 1000.0; GLfloat fps = Frames / seconds; printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps); + fflush(stdout); T0 = t; Frames = 0; } diff --git a/progs/demos/glslnoise.c b/progs/demos/glslnoise.c index 4ee12928164..e972b62673f 100644 --- a/progs/demos/glslnoise.c +++ b/progs/demos/glslnoise.c @@ -65,6 +65,7 @@ static void Redisplay (void) GLfloat seconds = (GLfloat) (t - t0) / 1000.0f; GLfloat fps = frames / seconds; printf ("%d frames in %6.3f seconds = %6.3f FPS\n", frames, seconds, fps); + fflush(stdout); t0 = t; frames = 0; } diff --git a/progs/demos/isosurf.c b/progs/demos/isosurf.c index 393741cc9d6..e280d8f507c 100644 --- a/progs/demos/isosurf.c +++ b/progs/demos/isosurf.c @@ -69,6 +69,7 @@ #define NO_STIPPLE 0x08000000 #define POLYGON_FILL 0x10000000 #define POLYGON_LINE 0x20000000 +#define POLYGON_POINT 0x40000000 #define LIGHT_MASK (LIT|UNLIT|REFLECT) #define FILTER_MASK (POINT_FILTER|LINEAR_FILTER) @@ -81,7 +82,7 @@ #define SHADE_MASK (SHADE_SMOOTH|SHADE_FLAT) #define FOG_MASK (FOG|NO_FOG) #define STIPPLE_MASK (STIPPLE|NO_STIPPLE) -#define POLYGON_MASK (POLYGON_FILL|POLYGON_LINE) +#define POLYGON_MASK (POLYGON_FILL|POLYGON_LINE|POLYGON_POINT) #define MAXVERTS 10000 static GLint maxverts = MAXVERTS; @@ -147,7 +148,7 @@ static void read_surface( char *filename ) static void print_flags( const char *msg, GLuint flags ) { fprintf(stderr, - "%s (0x%x): %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", + "%s (0x%x): %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n", msg, flags, (flags & GLVERTEX) ? "glVertex, " : "", (flags & DRAW_ARRAYS) ? "glDrawArrays, " : "", @@ -166,7 +167,8 @@ static void print_flags( const char *msg, GLuint flags ) (flags & MATERIALS) ? "materials, " : "", (flags & FOG) ? "fog, " : "", (flags & STIPPLE) ? "stipple, " : "", - (flags & POLYGON_LINE) ? "polygon mode line, " : ""); + (flags & POLYGON_LINE) ? "polygon mode line, " : "", + (flags & POLYGON_POINT) ? "polygon mode point, " : ""); } @@ -711,9 +713,12 @@ static void ModeMenu(int m) if (m & POLYGON_FILL) { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } - else { + else if (m & POLYGON_LINE) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } + else { + glPolygonMode(GL_FRONT_AND_BACK, GL_POINT); + } } #ifdef GL_EXT_vertex_array @@ -1089,6 +1094,7 @@ int main(int argc, char **argv) glutAddMenuEntry("", 0); glutAddMenuEntry("Polygon Mode Fill", POLYGON_FILL); glutAddMenuEntry("Polygon Mode Line", POLYGON_LINE); + glutAddMenuEntry("Polygon Mode Points", POLYGON_POINT); glutAddMenuEntry("", 0); glutAddMenuEntry("Point Filtered", POINT_FILTER); glutAddMenuEntry("Linear Filtered", LINEAR_FILTER); diff --git a/progs/demos/reflect.c b/progs/demos/reflect.c index 0bec0663bc2..b72af12885d 100644 --- a/progs/demos/reflect.c +++ b/progs/demos/reflect.c @@ -401,6 +401,7 @@ DrawWindow(void) GLfloat seconds = (t - t0) / 1000.0; GLfloat fps = frames / seconds; printf("%d frames in %g seconds = %g FPS\n", frames, seconds, fps); + fflush(stdout); t0 = t; frames = 0; } diff --git a/progs/demos/streaming_rect.c b/progs/demos/streaming_rect.c index 4d4656e722b..f65ac4ce36c 100644 --- a/progs/demos/streaming_rect.c +++ b/progs/demos/streaming_rect.c @@ -47,7 +47,10 @@ static void Idle( void ) } /*static int max( int a, int b ) { return a > b ? a : b; }*/ + +#ifndef min static int min( int a, int b ) { return a < b ? a : b; } +#endif static void DrawObject() { @@ -150,6 +153,7 @@ static void Display( void ) GLfloat fps = Frames / seconds; printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); + fflush(stdout); drift_increment = 2.2 * seconds / Frames; T0 = t; diff --git a/progs/demos/texcyl.c b/progs/demos/texcyl.c index e3b03039759..0e6089bced5 100644 --- a/progs/demos/texcyl.c +++ b/progs/demos/texcyl.c @@ -79,6 +79,7 @@ static void Display( void ) GLfloat seconds = (t - T0) / 1000.0; GLfloat fps = Frames / seconds; printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps); + fflush(stdout); T0 = t; Frames = 0; } diff --git a/progs/fp/Makefile b/progs/fp/Makefile index ef6644cce27..681928cf260 100755 --- a/progs/fp/Makefile +++ b/progs/fp/Makefile @@ -8,7 +8,7 @@ TOP = ../.. include $(TOP)/configs/current -LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) +LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLEW_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) SOURCES = \ tri-tex.c \ diff --git a/progs/fp/SConscript b/progs/fp/SConscript new file mode 100644 index 00000000000..553799758b0 --- /dev/null +++ b/progs/fp/SConscript @@ -0,0 +1,17 @@ +Import('env') + +if not env['GLUT']: + Return() + +env = env.Clone() + +env.Prepend(CPPPATH = [ + '../util', +]) + +env.Prepend(LIBS = ['$GLUT_LIB']) + +env.Program( + target = 'fp-tri', + source = ['fp-tri.c'], + ) diff --git a/progs/fp/fp-tri.c b/progs/fp/fp-tri.c index 843f897871b..bc490c05201 100644 --- a/progs/fp/fp-tri.c +++ b/progs/fp/fp-tri.c @@ -2,10 +2,19 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#define GL_GLEXT_PROTOTYPES -#include <GL/glut.h> + +#ifndef WIN32 #include <unistd.h> #include <signal.h> +#endif + +#include <GL/glew.h> +#include <GL/glut.h> + +#include "readtex.c" + + +#define TEXTURE_FILE "../images/bw.rgb" unsigned show_fps = 0; unsigned int frame_cnt = 0; @@ -15,11 +24,14 @@ static const char *filename = NULL; static void usage(char *name) { fprintf(stderr, "usage: %s [ options ] shader_filename\n", name); +#ifndef WIN32 fprintf(stderr, "\n" ); fprintf(stderr, "options:\n"); fprintf(stderr, " -fps show frames per second\n"); +#endif } +#ifndef WIN32 void alarmhandler (int sig) { if (sig == SIGALRM) { @@ -31,6 +43,7 @@ void alarmhandler (int sig) signal(SIGALRM, alarmhandler); alarm(5); } +#endif static void args(int argc, char *argv[]) { @@ -57,6 +70,7 @@ static void args(int argc, char *argv[]) static void Init( void ) { + GLuint Texture; GLint errno; GLuint prognum; char buf[4096]; @@ -99,7 +113,70 @@ static void Init( void ) } glEnable(GL_FRAGMENT_PROGRAM_ARB); - glClearColor(.3, .3, .3, 0); + + /* Load texture */ + glGenTextures(1, &Texture); + glBindTexture(GL_TEXTURE_2D, Texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { + printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE); + exit(1); + } + + + glGenTextures(1, &Texture); + glActiveTextureARB(GL_TEXTURE0_ARB + 1); + glBindTexture(GL_TEXTURE_2D, Texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + { + GLubyte data[32][32]; + int width = 32; + int height = 32; + int i; + int j; + + for (i = 0; i < 32; i++) + for (j = 0; j < 32; j++) + { + /** + ** +-----------+ + ** | W | + ** | +-----+ | + ** | | | | + ** | | B | | + ** | | | | + ** | +-----+ | + ** | | + ** +-----------+ + **/ + int i2 = i - height / 2; + int j2 = j - width / 2; + int h8 = height / 8; + int w8 = width / 8; + if ( -h8 <= i2 && i2 <= h8 && -w8 <= j2 && j2 <= w8 ) { + data[i][j] = 0x00; + } else if ( -2 * h8 <= i2 && i2 <= 2 * h8 && -2 * w8 <= j2 && j2 <= 2 * w8 ) { + data[i][j] = 0x55; + } else if ( -3 * h8 <= i2 && i2 <= 3 * h8 && -3 * w8 <= j2 && j2 <= 3 * w8 ) { + data[i][j] = 0xaa; + } else { + data[i][j] = 0xff; + } + } + + glTexImage2D( GL_TEXTURE_2D, 0, + GL_ALPHA8, + 32, 32, 0, + GL_ALPHA, GL_UNSIGNED_BYTE, data ); + } + + + glClearColor(.1, .3, .5, 0); } static void Reshape(int width, int height) @@ -142,7 +219,6 @@ static void Display(void) glEnd(); glFlush(); - if (show_fps) { ++frame_cnt; glutPostRedisplay(); @@ -158,14 +234,17 @@ int main(int argc, char **argv) glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH); args(argc, argv); glutCreateWindow(filename); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Display); Init(); +#ifndef WIN32 if (show_fps) { signal(SIGALRM, alarmhandler); alarm(5); } +#endif glutMainLoop(); return 0; } diff --git a/progs/fp/kill-pos.txt b/progs/fp/kill-pos.txt new file mode 100644 index 00000000000..5ff4f6f2c84 --- /dev/null +++ b/progs/fp/kill-pos.txt @@ -0,0 +1,9 @@ +!!ARBfp1.0 +TEMP R0; +SUB R0.xy, fragment.position, {125}.x; +MOV R0.zw, {0}.x; +DP3 R0, R0, R0; +SUB R0.x, R0, {10000}.x; +KIL -R0.x; +MOV result.color, fragment.color; +END diff --git a/progs/fp/position.txt b/progs/fp/position.txt index 27fac12a3a5..1875897d781 100644 --- a/progs/fp/position.txt +++ b/progs/fp/position.txt @@ -1,3 +1,4 @@ !!ARBfp1.0 -MUL result.color, fragment.position, {.005}.x; +MOV result.color, {0}.x; +MUL result.color.xy, fragment.position, {.005}.x; END diff --git a/progs/fp/tex-pos-kil-1.txt b/progs/fp/tex-pos-kil-1.txt new file mode 100644 index 00000000000..3f01e79ffe7 --- /dev/null +++ b/progs/fp/tex-pos-kil-1.txt @@ -0,0 +1,7 @@ +!!ARBfp1.0 +TEMP R0; +MUL R0, fragment.position, {0.03125}.x; +TEX R0, R0, texture[1], 2D; +KIL -R0; +MOV result.color, fragment.color; +END diff --git a/progs/fp/tex-pos-kil.txt b/progs/fp/tex-pos-kil.txt new file mode 100644 index 00000000000..b7aaa9f7c88 --- /dev/null +++ b/progs/fp/tex-pos-kil.txt @@ -0,0 +1,8 @@ +!!ARBfp1.0 +TEMP R0; +MUL R0, fragment.position, {0.008}.x; +TEX R0, R0, texture[0], 2D; +SUB R0, R0, {0.25}.x; +KIL R0.xyzz; +MOV result.color, fragment.color; +END diff --git a/progs/fp/tex-pos.txt b/progs/fp/tex-pos.txt new file mode 100644 index 00000000000..b969f423f57 --- /dev/null +++ b/progs/fp/tex-pos.txt @@ -0,0 +1,6 @@ +!!ARBfp1.0 +TEMP R0; +MOV R0, {0.0}.x; +MUL R0.xy, fragment.position, {0.008}.x; +TEX result.color, R0, texture[0], 2D; +END diff --git a/progs/fp/tex.txt b/progs/fp/tex.txt new file mode 100644 index 00000000000..b3a885d9e07 --- /dev/null +++ b/progs/fp/tex.txt @@ -0,0 +1,3 @@ +!!ARBfp1.0 +TEX result.color, fragment.color, texture[0], 2D; +END diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore index 7a51c8cf6f9..5fdb4ef16d4 100644 --- a/progs/glsl/.gitignore +++ b/progs/glsl/.gitignore @@ -18,6 +18,7 @@ samplers samplers_array shaderutil.c shaderutil.h +shadow_sampler skinning texdemo1 toyball diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 7099eeadbd9..80612770332 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -25,6 +25,7 @@ PROGS = \ pointcoord \ samplers \ samplers_array \ + shadow_sampler \ skinning \ texdemo1 \ toyball \ diff --git a/progs/glsl/shadow_sampler.c b/progs/glsl/shadow_sampler.c new file mode 100644 index 00000000000..2902b535522 --- /dev/null +++ b/progs/glsl/shadow_sampler.c @@ -0,0 +1,341 @@ +/** + * Test shadow2DRectProj() and shadow2D() functions. + * Brian Paul + * 11 April 2007 + */ + +#define GL_GLEXT_PROTOTYPES +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/gl.h> +#include <GL/glut.h> +#include <GL/glext.h> +#include "extfuncs.h" + + +/** Use GL_RECTANGLE texture (with projective texcoords)? */ +#define USE_RECT 01 + +#define TEXSIZE 16 + + +static char *FragProgFile = NULL; +static char *VertProgFile = NULL; + +static GLuint fragShader; +static GLuint vertShader; +static GLuint program; + +static GLint uTexture2D; +static GLint uTextureRect; + +static GLint win = 0; + +static GLenum Filter = GL_LINEAR; + +static void +CheckError(int line) +{ + GLenum err = glGetError(); + if (err) { + printf("GL Error %s (0x%x) at line %d\n", + gluErrorString(err), (int) err, line); + } +} + + +static void +PrintString(const char *s) +{ + while (*s) { + glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s); + s++; + } +} + + +static void +Redisplay(void) +{ + CheckError(__LINE__); + glClear(GL_COLOR_BUFFER_BIT); + + glPushMatrix(); + + CheckError(__LINE__); + glUseProgram_func(program); + CheckError(__LINE__); + + glBegin(GL_POLYGON); +#if USE_RECT + /* scale coords by two to test projection */ + glTexCoord4f( 0, 0, 0, 2.0); glVertex2f(-1, -1); + glTexCoord4f(2*TEXSIZE, 0, 2*1, 2.0); glVertex2f( 1, -1); + glTexCoord4f(2*TEXSIZE, 2*TEXSIZE, 2*1, 2.0); glVertex2f( 1, 1); + glTexCoord4f( 0, 2*TEXSIZE, 0, 2.0); glVertex2f(-1, 1); +#else + glTexCoord3f(0, 0, 0); glVertex2f(-1, -1); + glTexCoord3f(1, 0, 1); glVertex2f( 1, -1); + glTexCoord3f(1, 1, 1); glVertex2f( 1, 1); + glTexCoord3f(0, 1, 0); glVertex2f(-1, 1); +#endif + glEnd(); + + glPopMatrix(); + + glUseProgram_func(0); + glWindowPos2iARB(80, 20); + PrintString("white black white black"); + + glutSwapBuffers(); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0f, 0.0f, -8.0f); +} + + +static void +CleanUp(void) +{ + glDeleteShader_func(fragShader); + glDeleteShader_func(vertShader); + glDeleteProgram_func(program); + glutDestroyWindow(win); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + + switch(key) { + case 27: + CleanUp(); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void +MakeTexture(void) +{ + GLfloat image[TEXSIZE][TEXSIZE]; + GLuint i, j; + + for (i = 0; i < TEXSIZE; i++) { + for (j = 0; j < TEXSIZE; j++) { + if (j < (TEXSIZE / 2)) { + image[i][j] = 0.25; + } + else { + image[i][j] = 0.75; + } + } + } + + glActiveTexture(GL_TEXTURE0); /* unit 0 */ + glBindTexture(GL_TEXTURE_2D, 42); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, TEXSIZE, TEXSIZE, 0, + GL_DEPTH_COMPONENT, GL_FLOAT, image); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, Filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, + GL_COMPARE_R_TO_TEXTURE_ARB); + CheckError(__LINE__); + + glActiveTexture(GL_TEXTURE1); /* unit 1 */ + glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 43); + glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_DEPTH_COMPONENT, + TEXSIZE, 10, 0,/*16x10*/ + GL_DEPTH_COMPONENT, GL_FLOAT, image); + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, Filter); + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, Filter); + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_COMPARE_MODE_ARB, + GL_COMPARE_R_TO_TEXTURE_ARB); + CheckError(__LINE__); +} + + +static void +LoadAndCompileShader(GLuint shader, const char *text) +{ + GLint stat; + glShaderSource_func(shader, 1, (const GLchar **) &text, NULL); + glCompileShader_func(shader); + glGetShaderiv_func(shader, GL_COMPILE_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + glGetShaderInfoLog_func(shader, 1000, &len, log); + fprintf(stderr, "fslight: problem compiling shader:\n%s\n", log); + exit(1); + } +} + + +/** + * Read a shader from a file. + */ +static void +ReadShader(GLuint shader, const char *filename) +{ + const int max = 100*1000; + int n; + char *buffer = (char*) malloc(max); + FILE *f = fopen(filename, "r"); + if (!f) { + fprintf(stderr, "fslight: Unable to open shader file %s\n", filename); + exit(1); + } + + n = fread(buffer, 1, max, f); + printf("fslight: read %d bytes from shader file %s\n", n, filename); + if (n > 0) { + buffer[n] = 0; + LoadAndCompileShader(shader, buffer); + } + + fclose(f); + free(buffer); +} + + +static void +CheckLink(GLuint prog) +{ + GLint stat; + glGetProgramiv_func(prog, GL_LINK_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + glGetProgramInfoLog_func(prog, 1000, &len, log); + fprintf(stderr, "Linker error:\n%s\n", log); + } +} + + +static void +Init(void) +{ + static const char *fragShaderText = + "uniform sampler2DShadow shadowTex2D; \n" + "uniform sampler2DRectShadow shadowTexRect; \n" + "void main() {\n" +#if USE_RECT + " gl_FragColor = shadow2DRectProj(shadowTexRect, gl_TexCoord[0]); \n" +#else + " gl_FragColor = shadow2D(shadowTex2D, gl_TexCoord[0].xyz); \n" +#endif + "}\n"; + static const char *vertShaderText = + "void main() {\n" + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + " gl_TexCoord[0] = gl_MultiTexCoord0; \n" + "}\n"; + const char *version; + +#if USE_RECT + if (!glutExtensionSupported("GL_ARB_texture_rectangle")) { + printf("This program requires GL_ARB_texture_rectangle\n"); + exit(1); + } +#endif + + version = (const char *) glGetString(GL_VERSION); + if (version[0] != '2' || version[1] != '.') { + printf("This program requires OpenGL 2.x, found %s\n", version); + exit(1); + } + printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); + + GetExtensionFuncs(); + + fragShader = glCreateShader_func(GL_FRAGMENT_SHADER); + if (FragProgFile) + ReadShader(fragShader, FragProgFile); + else + LoadAndCompileShader(fragShader, fragShaderText); + + vertShader = glCreateShader_func(GL_VERTEX_SHADER); + if (VertProgFile) + ReadShader(vertShader, VertProgFile); + else + LoadAndCompileShader(vertShader, vertShaderText); + + program = glCreateProgram_func(); + glAttachShader_func(program, fragShader); + glAttachShader_func(program, vertShader); + glLinkProgram_func(program); + CheckLink(program); + glUseProgram_func(program); + + uTexture2D = glGetUniformLocation_func(program, "shadowTex2D"); + uTextureRect = glGetUniformLocation_func(program, "shadowTexRect"); + printf("uTexture2D %d uTextureRect %d\n", uTexture2D, uTextureRect); + if (uTexture2D >= 0) { + glUniform1i_func(uTexture2D, 0); /* use texture unit 0 */ + } + if (uTextureRect >= 0) { + glUniform1i_func(uTextureRect, 1); /* use texture unit 0 */ + } + CheckError(__LINE__); + + glClearColor(0.3f, 0.3f, 0.3f, 0.0f); + glColor3f(1, 1, 1); + + MakeTexture(); + CheckError(__LINE__); +} + + +static void +ParseOptions(int argc, char *argv[]) +{ + int i; + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-fs") == 0) { + FragProgFile = argv[i+1]; + } + else if (strcmp(argv[i], "-vs") == 0) { + VertProgFile = argv[i+1]; + } + } +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowPosition( 0, 0); + glutInitWindowSize(400, 300); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + win = glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Redisplay); + ParseOptions(argc, argv); + Init(); + glutMainLoop(); + return 0; +} + + diff --git a/progs/tests/.gitignore b/progs/tests/.gitignore index c5b9e28dab1..0ed3a885c26 100644 --- a/progs/tests/.gitignore +++ b/progs/tests/.gitignore @@ -14,7 +14,9 @@ arbvpwarpmesh arraytexture blendminmax blendsquare +blendxor bufferobj +bumpmap bug_3050 bug_3101 bug_3195 @@ -59,6 +61,8 @@ readtex.h seccolor sharedtex shader_api +shaderutil.c +shaderutil.h stencil_twoside stencil_wrap stencilwrap diff --git a/progs/tests/Makefile b/progs/tests/Makefile index 34c9ab1dcef..58ea5690df6 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -8,7 +8,7 @@ TOP = ../.. include $(TOP)/configs/current -LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) +LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLEW_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) SOURCES = \ afsmultiarb.c \ @@ -28,6 +28,7 @@ SOURCES = \ blendsquare.c \ blendxor.c \ bufferobj.c \ + bumpmap.c \ bug_3050.c \ bug_3101.c \ bug_3195.c \ @@ -54,7 +55,10 @@ SOURCES = \ jkrahntest.c \ lineclip.c \ manytex.c \ + mapbufrange.c \ + mapvbo.c \ minmag.c \ + mipgen.c \ mipmap_limits.c \ mipmap_view.c \ multipal.c \ @@ -145,6 +149,12 @@ afsmultiarb: afsmultiarb.o readtex.o afsmultiarb.o: afsmultiarb.c readtex.h $(APP_CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) afsmultiarb.c -o $@ +bumpmap: bumpmap.o readtex.o + $(CC) $(CFLAGS) $(LDFLAGS) bumpmap.o readtex.o $(LIBS) -o $@ + +bumpmap.o: bumpmap.c readtex.h + $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) bumpmap.c -o $@ + drawbuffers: drawbuffers.o $(APP_CC) $(CFLAGS) $(LDFLAGS) drawbuffers.o $(LIBS) -o $@ @@ -175,6 +185,11 @@ mipmap_view: mipmap_view.o readtex.o mipmap_view.o: mipmap_view.c readtex.h $(APP_CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@ +mipmap_limits: mipmap_limits.o readtex.o + $(APP_CC) $(CFLAGS) mipmap_limits.o readtex.o $(LIBS) -o $@ + +mipmap_limits.o: mipmap_limits.c readtex.h + $(APP_CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@ fillrate: fillrate.o readtex.o $(APP_CC) $(CFLAGS) fillrate.o readtex.o $(LIBS) -o $@ diff --git a/progs/tests/SConscript b/progs/tests/SConscript new file mode 100644 index 00000000000..cfeb9d1c378 --- /dev/null +++ b/progs/tests/SConscript @@ -0,0 +1,134 @@ +Import('*') + +if not env['GLUT']: + Return() + +env = env.Clone() + +env.Prepend(CPPPATH = [ + '../util', +]) + +env.Prepend(LIBS = [ + util, + '$GLUT_LIB' +]) + +if env['platform'] == 'windows': + env.Append(CPPDEFINES = ['NOMINMAX']) + env.Prepend(LIBS = ['winmm']) + +linux_progs = [ + 'api_speed', +] + +glx_progs = [ + 'auxbuffer', + 'getprocaddress', + 'jkrahntest', + 'sharedtex', + 'texcompress2', + 'texobjshare', +] + +mesa_progs = [ + 'debugger', +] + +progs = [ + 'afsmultiarb', + 'antialias', + 'arbfpspec', + 'arbfptest1', + 'arbfptexture', + 'arbfptrig', + 'arbnpot-mipmap', + 'arbnpot', + 'arbvptest1', + 'arbvptest3', + 'arbvptorus', + 'arbvpwarpmesh', + 'arraytexture', + 'blendminmax', + 'blendsquare', + 'blendxor', + 'bufferobj', + 'bug_3050', + 'bug_3101', + 'bug_3195', + 'bug_texstore_i8', + 'calibrate_rast', + 'copypixrate', + 'crossbar', + 'cva', + 'dinoshade', + 'drawbuffers', + 'exactrast', + 'ext422square', + 'fbotest1', + 'fbotest2', + 'fbotexture', + 'fillrate', + 'floattex', + 'fog', + 'fogcoord', + 'fptest1', + 'fptexture', + 'interleave', + 'invert', + 'lineclip', + 'manytex', + 'mapbufrange', + 'mapvbo', + 'minmag', + 'mipgen', + 'mipmap_limits', + 'mipmap_view', + 'multipal', + 'multitexarray', + 'multiwindow', + 'no_s3tc', + 'packedpixels', + 'pbo', + 'prog_parameter', + 'projtex', + 'quads', + 'random', + 'readrate', + 'rubberband', + 'seccolor', + 'shader_api', + 'stencil_twoside', + 'stencil_wrap', + 'stencilwrap', + 'subtex', + 'subtexrate', + 'tex1d', + 'texcmp', + 'texfilt', + 'texgenmix', + 'texline', + 'texrect', + 'texwrap', + 'unfilledclip', + 'vao-01', + 'vao-02', + 'vparray', + 'vpeval', + 'vptest1', + 'vptest2', + 'vptest3', + 'vptorus', + 'vpwarpmesh', + 'yuvrect', + 'yuvsquare', + 'zcomp', + 'zdrawpix', + 'zreaddraw', +] + +for prog in progs: + env.Program( + target = prog, + source = prog + '.c', + ) diff --git a/progs/tests/afsmultiarb.c b/progs/tests/afsmultiarb.c index c026ecd4ce2..162ab19493c 100644 --- a/progs/tests/afsmultiarb.c +++ b/progs/tests/afsmultiarb.c @@ -11,7 +11,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> #include "readtex.h" @@ -442,6 +442,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 300, 300 ); glutInitWindowPosition( 0, 0 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + glewInit(); glutCreateWindow(argv[0] ); Init( argc, argv ); diff --git a/progs/tests/antialias.c b/progs/tests/antialias.c index f23b5aff324..656bf2471fe 100644 --- a/progs/tests/antialias.c +++ b/progs/tests/antialias.c @@ -9,6 +9,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> @@ -29,7 +30,7 @@ PrintString(const char *s) static void -Polygon( GLint verts, GLfloat radius, GLfloat z ) +doPolygon( GLint verts, GLfloat radius, GLfloat z ) { int i; for (i = 0; i < verts; i++) { @@ -47,33 +48,33 @@ DrawObject( void ) glLineWidth(3.0); glColor3f(1, 1, 1); glBegin(GL_LINE_LOOP); - Polygon(12, 1.2, 0); + doPolygon(12, 1.2, 0); glEnd(); glLineWidth(1.0); glColor3f(1, 1, 1); glBegin(GL_LINE_LOOP); - Polygon(12, 1.1, 0); + doPolygon(12, 1.1, 0); glEnd(); glColor3f(1, 0, 0); glBegin(GL_POLYGON); - Polygon(12, 0.4, 0.3); + doPolygon(12, 0.4, 0.3); glEnd(); glColor3f(0, 1, 0); glBegin(GL_POLYGON); - Polygon(12, 0.6, 0.2); + doPolygon(12, 0.6, 0.2); glEnd(); glColor3f(0, 0, 1); glBegin(GL_POLYGON); - Polygon(12, 0.8, 0.1); + doPolygon(12, 0.8, 0.1); glEnd(); glColor3f(1, 1, 1); glBegin(GL_POLYGON); - Polygon(12, 1.0, 0); + doPolygon(12, 1.0, 0); glEnd(); } @@ -225,6 +226,7 @@ main( int argc, char *argv[] ) glutInitDisplayMode( GLUT_RGB | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/api_speed.c b/progs/tests/api_speed.c index aed65b35fe3..28e28e61d8b 100644 --- a/progs/tests/api_speed.c +++ b/progs/tests/api_speed.c @@ -37,9 +37,7 @@ #include <stdio.h> #include <stdlib.h> -#define GL_GLEXT_PROTOTYPES -#include <GL/gl.h> -#include <GL/glext.h> +#include <GL/glew.h> #include <GL/glut.h> #define inline __inline__ @@ -127,6 +125,7 @@ int main( int argc, char *argv[] ) glutInitDisplayMode( GLUT_RGB ); glutCreateWindow( argv[0] ); + glewInit(); if ( argc > 1 ) { count = strtoul( argv[1], NULL, 0 ); diff --git a/progs/tests/arbfpspec.c b/progs/tests/arbfpspec.c index eac2a9100f5..550e9543406 100644 --- a/progs/tests/arbfpspec.c +++ b/progs/tests/arbfpspec.c @@ -8,7 +8,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> static float Xrot = 0.0, Yrot = 0.0, Zrot = 0.0; @@ -180,6 +180,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); diff --git a/progs/tests/arbfptest1.c b/progs/tests/arbfptest1.c index 7949f87eddb..e7237b76a87 100644 --- a/progs/tests/arbfptest1.c +++ b/progs/tests/arbfptest1.c @@ -5,7 +5,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> @@ -201,6 +201,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/arbfptexture.c b/progs/tests/arbfptexture.c index a854908c311..f66b060cbb2 100644 --- a/progs/tests/arbfptexture.c +++ b/progs/tests/arbfptexture.c @@ -5,7 +5,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> #include "readtex.c" @@ -143,6 +143,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); diff --git a/progs/tests/arbfptrig.c b/progs/tests/arbfptrig.c index 26b68c6b412..95f008a078d 100644 --- a/progs/tests/arbfptrig.c +++ b/progs/tests/arbfptrig.c @@ -5,7 +5,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> #include "readtex.c" @@ -146,6 +146,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); diff --git a/progs/tests/arbnpot-mipmap.c b/progs/tests/arbnpot-mipmap.c index 4ed84e7acee..700ec0b09d0 100644 --- a/progs/tests/arbnpot-mipmap.c +++ b/progs/tests/arbnpot-mipmap.c @@ -46,6 +46,7 @@ */ #include <stdlib.h> #include <stdio.h> +#include <GL/glew.h> #include <GL/glut.h> GLubyte mipmapImage32[40][46][3]; @@ -175,6 +176,7 @@ int main(int argc, char** argv) glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize (500, 500); glutCreateWindow (argv[0]); + glewInit(); myinit(); glutReshapeFunc (myReshape); glutDisplayFunc(display); diff --git a/progs/tests/arbnpot.c b/progs/tests/arbnpot.c index 05ba85dad9e..c51a5416413 100644 --- a/progs/tests/arbnpot.c +++ b/progs/tests/arbnpot.c @@ -8,6 +8,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #include "../util/readtex.c" @@ -188,6 +189,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 400, 400 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/arbvptest1.c b/progs/tests/arbvptest1.c index 0ebd3987f58..3a6d71a42bd 100644 --- a/progs/tests/arbvptest1.c +++ b/progs/tests/arbvptest1.c @@ -5,7 +5,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> static void Display( void ) @@ -155,6 +155,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/arbvptest3.c b/progs/tests/arbvptest3.c index 6437062900e..56de7b46963 100644 --- a/progs/tests/arbvptest3.c +++ b/progs/tests/arbvptest3.c @@ -4,7 +4,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> static float Zrot = 0.0; @@ -118,6 +118,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/arbvptorus.c b/progs/tests/arbvptorus.c index 9d19ef90da5..f1f84d87749 100644 --- a/progs/tests/arbvptorus.c +++ b/progs/tests/arbvptorus.c @@ -7,7 +7,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> static float Xrot = 0.0, Yrot = 0.0, Zrot = 0.0; @@ -174,6 +174,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); diff --git a/progs/tests/arbvpwarpmesh.c b/progs/tests/arbvpwarpmesh.c index 3dfe94f7596..973a1574099 100644 --- a/progs/tests/arbvpwarpmesh.c +++ b/progs/tests/arbvpwarpmesh.c @@ -7,7 +7,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> static float Xrot = -60.0, Yrot = 0.0, Zrot = 0.0; @@ -234,6 +234,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); diff --git a/progs/tests/arraytexture.c b/progs/tests/arraytexture.c index 48c622be302..6c0484df0de 100644 --- a/progs/tests/arraytexture.c +++ b/progs/tests/arraytexture.c @@ -34,6 +34,7 @@ #include <stdio.h> #include <string.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #include <GL/glext.h> @@ -326,6 +327,7 @@ int main(int argc, char *argv[]) glutInitWindowSize(350, 350); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutCreateWindow("Array texture test"); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutSpecialFunc(SpecialKey); diff --git a/progs/tests/blendminmax.c b/progs/tests/blendminmax.c index 2aab1a39d29..7297f41b787 100644 --- a/progs/tests/blendminmax.c +++ b/progs/tests/blendminmax.c @@ -34,6 +34,7 @@ #include <stdio.h> #include <stdlib.h> +#include <GL/glew.h> #include <GL/glut.h> static int Width = 400; @@ -200,6 +201,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( Width, Height ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow( "GL_EXT_blend_minmax test" ); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/blendsquare.c b/progs/tests/blendsquare.c index 1694866a557..3ee3ae2230c 100644 --- a/progs/tests/blendsquare.c +++ b/progs/tests/blendsquare.c @@ -34,6 +34,7 @@ #include <stdio.h> #include <stdlib.h> +#include <GL/glew.h> #include <GL/glut.h> static int Width = 400; @@ -169,6 +170,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( Width, Height ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow( "GL_NV_blend_square test" ); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/blendxor.c b/progs/tests/blendxor.c index 8961a827eab..d6dcb8b8486 100644 --- a/progs/tests/blendxor.c +++ b/progs/tests/blendxor.c @@ -3,10 +3,10 @@ * */ -#define GL_GLEXT_PROTOTYPES #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #include "readtex.c" @@ -183,6 +183,7 @@ main(int argc, char *argv[]) glutInitWindowSize(Width, Height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutSpecialFunc(SpecialKey); diff --git a/progs/tests/bufferobj.c b/progs/tests/bufferobj.c index d1a85392e1e..1d97b060efc 100644 --- a/progs/tests/bufferobj.c +++ b/progs/tests/bufferobj.c @@ -6,18 +6,19 @@ */ -#define GL_GLEXT_PROTOTYPES #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #define NUM_OBJECTS 10 struct object { - GLuint BufferID; + GLuint VertexBufferID; + GLuint ColorBufferID; GLuint ElementsBufferID; GLuint NumVerts; GLuint VertexOffset; @@ -47,7 +48,7 @@ static void CheckError(int line) static void DrawObject( const struct object *obj ) { - glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->BufferID); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->VertexBufferID); glVertexPointer(3, GL_FLOAT, obj->VertexStride, (void *) obj->VertexOffset); glEnable(GL_VERTEX_ARRAY); @@ -62,6 +63,7 @@ static void DrawObject( const struct object *obj ) glPopClientAttrib(); } #endif + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->ColorBufferID); glColorPointer(3, GL_FLOAT, obj->ColorStride, (void *) obj->ColorOffset); glEnable(GL_COLOR_ARRAY); @@ -92,7 +94,7 @@ static void Display( void ) glClear( GL_COLOR_BUFFER_BIT ); for (i = 0; i < NumObjects; i++) { - float x = 5.0 * ((float) i / (NumObjects-1) - 0.5); + float x = 7.0 * ((float) i / (NumObjects-1) - 0.5); glPushMatrix(); glTranslatef(x, 0, 0); glRotatef(Xrot, 1, 0, 0); @@ -125,8 +127,11 @@ static void Reshape( int width, int height ) static void FreeBuffers(void) { int i; - for (i = 0; i < NUM_OBJECTS; i++) - glDeleteBuffersARB(1, &Objects[i].BufferID); + for (i = 0; i < NUM_OBJECTS; i++) { + glDeleteBuffersARB(1, &Objects[i].VertexBufferID); + glDeleteBuffersARB(1, &Objects[i].ColorBufferID); + glDeleteBuffersARB(1, &Objects[i].ElementsBufferID); + } } @@ -182,7 +187,9 @@ static void SpecialKey( int key, int x, int y ) } - +/* + * Non-interleaved position/color data. + */ static void MakeObject1(struct object *obj) { GLfloat *v, *c; @@ -193,10 +200,11 @@ static void MakeObject1(struct object *obj) for (i = 0; i < 500; i++) buffer[i] = i & 0xff; - obj->BufferID = 0; - glGenBuffersARB(1, &obj->BufferID); - assert(obj->BufferID != 0); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->BufferID); + obj->VertexBufferID = 0; + glGenBuffersARB(1, &obj->VertexBufferID); + obj->ColorBufferID = obj->VertexBufferID; + assert(obj->VertexBufferID != 0); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->VertexBufferID); glBufferDataARB(GL_ARRAY_BUFFER_ARB, 500, buffer, GL_STATIC_DRAW_ARB); for (i = 0; i < 500; i++) @@ -257,13 +265,18 @@ static void MakeObject1(struct object *obj) } +/* + * Interleaved position/color data. + */ static void MakeObject2(struct object *obj) { GLfloat *v; int start = 40; /* bytes, to test non-zero array offsets */ - glGenBuffersARB(1, &obj->BufferID); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->BufferID); + glGenBuffersARB(1, &obj->VertexBufferID); + obj->ColorBufferID = obj->VertexBufferID; + + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->VertexBufferID); glBufferDataARB(GL_ARRAY_BUFFER_ARB, 1000, NULL, GL_STATIC_DRAW_ARB); v = (GLfloat *) glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); @@ -287,6 +300,9 @@ static void MakeObject2(struct object *obj) } +/* + * Use an index buffer and glDrawElements(). + */ static void MakeObject3(struct object *obj) { GLfloat vertexData[1000]; @@ -314,8 +330,10 @@ static void MakeObject3(struct object *obj) bytes = obj->NumVerts * (3 + 3) * sizeof(GLfloat); /* Don't use glMap/UnmapBuffer for this object */ - glGenBuffersARB(1, &obj->BufferID); - glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->BufferID); + glGenBuffersARB(1, &obj->VertexBufferID); + obj->ColorBufferID = obj->VertexBufferID; + + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->VertexBufferID); glBufferDataARB(GL_ARRAY_BUFFER_ARB, bytes, vertexData, GL_STATIC_DRAW_ARB); /* Setup a buffer of indices to test the ELEMENTS path */ @@ -332,6 +350,46 @@ static void MakeObject3(struct object *obj) } +/* + * Vertex and color data in different buffers. + */ +static void MakeObject4(struct object *obj) +{ + static const GLfloat vertexData[] = { + 0, -1, 0, + 0.5, 0, 0, + 0, 1, 0, + -0.5, 0, 0 + }; + static const GLfloat colorData[] = { + 1, 1, 1, + 1, 1, 0, + .5, .5, 0, + 1, 1, 0 + }; + + obj->VertexOffset = 0; + obj->VertexStride = 0; + obj->ColorOffset = 0; + obj->ColorStride = 0; + obj->NumVerts = 4; + + glGenBuffersARB(1, &obj->VertexBufferID); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->VertexBufferID); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(vertexData), vertexData, + GL_STATIC_DRAW_ARB); + + glGenBuffersARB(1, &obj->ColorBufferID); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, obj->ColorBufferID); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(colorData), colorData, + GL_STATIC_DRAW_ARB); + + /* Setup a buffer of indices to test the ELEMENTS path */ + obj->ElementsBufferID = 0; + obj->NumElements = 0; +} + + static void Init( void ) { @@ -358,7 +416,8 @@ static void Init( void ) MakeObject1(Objects + 0); MakeObject2(Objects + 1); MakeObject3(Objects + 2); - NumObjects = 3; + MakeObject4(Objects + 3); + NumObjects = 4; } @@ -369,6 +428,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 600, 300 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); diff --git a/progs/tests/bug_3050.c b/progs/tests/bug_3050.c index 4ea7b80f231..a04e40eaf6e 100644 --- a/progs/tests/bug_3050.c +++ b/progs/tests/bug_3050.c @@ -39,6 +39,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <GL/glew.h> #include <GL/glut.h> static int Width = 400; @@ -154,6 +155,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( Width, Height ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow( "Bug #3050 Test" ); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/bug_3101.c b/progs/tests/bug_3101.c index 761dcbb9513..06a97761557 100644 --- a/progs/tests/bug_3101.c +++ b/progs/tests/bug_3101.c @@ -34,6 +34,7 @@ #include <stdio.h> #include <stdlib.h> +#include <GL/glew.h> #include <GL/glut.h> static int Width = 400; @@ -119,6 +120,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( Width, Height ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow( "Bug #3101 Test" ); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/bug_3195.c b/progs/tests/bug_3195.c index 4aceae04abe..a075b94e370 100644 --- a/progs/tests/bug_3195.c +++ b/progs/tests/bug_3195.c @@ -36,6 +36,7 @@ #include <stdlib.h> #include <stdio.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #include <GL/glext.h> @@ -264,6 +265,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 350, 350 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow( "Bug #3195 Test" ); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); diff --git a/progs/tests/bug_texstore_i8.c b/progs/tests/bug_texstore_i8.c index f8dac210f7a..10e5eba7c5e 100644 --- a/progs/tests/bug_texstore_i8.c +++ b/progs/tests/bug_texstore_i8.c @@ -29,6 +29,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#include <GL/glew.h> #include <GL/glut.h> static GLenum Target = GL_TEXTURE_2D; @@ -180,6 +181,7 @@ int main(int argc, char **argv) glutInitDisplayMode(type); win = glutCreateWindow("Tex test"); + glewInit(); if (!win) { exit(1); } diff --git a/progs/tests/bumpmap.c b/progs/tests/bumpmap.c new file mode 100644 index 00000000000..1b7ec2c135c --- /dev/null +++ b/progs/tests/bumpmap.c @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/** + * Simple test for testing ATI_envmap_bumpmap support. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> +#include <GL/glut.h> + +#include "readtex.h" + +static PFNGLGETTEXBUMPPARAMETERFVATIPROC glGetTexBumpParameterfvATI_func = NULL; +static PFNGLGETTEXBUMPPARAMETERIVATIPROC glGetTexBumpParameterivATI_func = NULL; +static PFNGLTEXBUMPPARAMETERFVATIPROC glTexBumpParameterfvATI_func = NULL; + +static const char *TexFile = "../images/arch.rgb"; + +static const GLfloat Near = 5.0, Far = 25.0; + +static void Display( void ) +{ + /* together with the construction of dudv map, do fixed translation + in y direction (up), some cosine deformation in x and more + deformation in y dir */ + GLfloat bumpMatrix[4] = {0.1, 0.0, 0.2, 0.1}; + + + glClearColor(0.2, 0.2, 0.8, 0); + glClear( GL_COLOR_BUFFER_BIT ); + + glPushMatrix(); + + /* this is the base map */ + glActiveTexture( GL_TEXTURE0 ); + glEnable( GL_TEXTURE_2D ); + glBindTexture( GL_TEXTURE_2D, 1 ); + glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE ); + glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE ); + glTexEnvf( GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE ); + + /* bump map */ + glActiveTexture( GL_TEXTURE1 ); + glEnable( GL_TEXTURE_2D ); + glBindTexture( GL_TEXTURE_2D, 2 ); + glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE ); + glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_BUMP_ENVMAP_ATI ); + glTexEnvf( GL_TEXTURE_ENV, GL_BUMP_TARGET_ATI, GL_TEXTURE0); + + glTexBumpParameterfvATI_func(GL_BUMP_ROT_MATRIX_ATI, bumpMatrix); + + glCallList(1); + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + GLfloat ar = (float) width / (float) height; + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -ar, ar, -1.0, 1.0, Near, Far ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -6.0 ); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ + const char * const ver_string = (const char * const) + glGetString( GL_VERSION ); + GLfloat temp[16][16][2]; + GLubyte *image = NULL; + GLint imgWidth, imgHeight; + GLenum imgFormat; + GLint i,j; + GLint param, paramArray[16]; + GLfloat paramMat[4]; + + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", ver_string); + + if ( !glutExtensionSupported("GL_ATI_envmap_bumpmap")) { + printf("\nSorry, this program requires GL_ATI_envmap_bumpmap\n"); + exit(1); + } + + glGetTexBumpParameterfvATI_func = glutGetProcAddress("glGetTexBumpParameterfvATI"); + glGetTexBumpParameterivATI_func = glutGetProcAddress("glGetTexBumpParameterivATI"); + glTexBumpParameterfvATI_func = glutGetProcAddress("glTexBumpParameterfvATI"); + + glGetTexBumpParameterivATI_func(GL_BUMP_ROT_MATRIX_SIZE_ATI, ¶m); + printf("BUMP_ROT_MATRIX_SIZE_ATI = %d\n", param); + glGetTexBumpParameterivATI_func(GL_BUMP_NUM_TEX_UNITS_ATI, ¶m); + printf("BUMP_NUM_TEX_UNITS_ATI = %d\n", param); + glGetTexBumpParameterfvATI_func(GL_BUMP_ROT_MATRIX_ATI, paramMat); + printf("initial rot matrix %f %f %f %f\n", paramMat[0], paramMat[1], paramMat[2], paramMat[3]); + glGetTexBumpParameterivATI_func(GL_BUMP_TEX_UNITS_ATI, paramArray); + printf("units supporting bump mapping: "); + for (i = 0; i < param; i++) + printf("%d ", paramArray[i] - GL_TEXTURE0); + printf("\n"); + + image = LoadRGBImage(TexFile, &imgWidth, &imgHeight, &imgFormat); + if (!image) { + printf("Couldn't read %s\n", TexFile); + exit(0); + } + + glBindTexture( GL_TEXTURE_2D, 1 ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + glTexImage2D( GL_TEXTURE_2D, 0, imgFormat, imgWidth, imgHeight, 0, + imgFormat, GL_UNSIGNED_BYTE, image ); + + for (j = 0; j < 16; j++) { + for (i = 0; i < 16; i++) { + temp[j][i][0] = cos((float)(i) * 3.1415 / 16.0); + temp[j][i][1] = -0.5; + } + } + glBindTexture( GL_TEXTURE_2D, 2 ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); + glTexImage2D( GL_TEXTURE_2D, 0, GL_DU8DV8_ATI, 16, 16, 0, + GL_DUDV_ATI, GL_FLOAT, temp ); + + + glNewList( 1, GL_COMPILE ); + glBegin(GL_QUADS); + glColor3f( 0.9, 0.0, 0.0 ); + glMultiTexCoord2f( GL_TEXTURE0, 0.0, 0.0 ); + glMultiTexCoord2f( GL_TEXTURE1, 0.0, 0.0 ); + glVertex2f(-1, -1); + glMultiTexCoord2f( GL_TEXTURE0, 1.0, 0.0 ); + glMultiTexCoord2f( GL_TEXTURE1, 1.0, 0.0 ); + glVertex2f( 1, -1); + glMultiTexCoord2f( GL_TEXTURE0, 1.0, 1.0 ); + glMultiTexCoord2f( GL_TEXTURE1, 1.0, 1.0 ); + glVertex2f( 1, 1); + glMultiTexCoord2f( GL_TEXTURE0, 0.0, 1.0 ); + glMultiTexCoord2f( GL_TEXTURE1, 0.0, 1.0 ); + glVertex2f(-1, 1); + glEnd(); + glEndList(); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 400, 400 ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + glutCreateWindow( "GL_ATI_envmap_bumpmap test" ); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/tests/calibrate_rast.c b/progs/tests/calibrate_rast.c index 37d8ac85e54..5d89ff79c55 100644 --- a/progs/tests/calibrate_rast.c +++ b/progs/tests/calibrate_rast.c @@ -19,6 +19,7 @@ #include <assert.h> #include <stdio.h> #include <stdlib.h> +#include <GL/glew.h> #include <GL/glut.h> @@ -386,6 +387,7 @@ main(int argc, char *argv[]) glutInitWindowSize(Width, Height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Draw); diff --git a/progs/tests/copypixrate.c b/progs/tests/copypixrate.c index 142315364c6..aa4acfc18b5 100644 --- a/progs/tests/copypixrate.c +++ b/progs/tests/copypixrate.c @@ -5,11 +5,11 @@ * 26 Jan 2006 */ -#define GL_GLEXT_PROTOTYPES #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> static GLint WinWidth = 1000, WinHeight = 800; @@ -260,6 +260,7 @@ main(int argc, char *argv[]) glutInitWindowSize(WinWidth, WinHeight); glutInitDisplayMode(mode); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutSpecialFunc(SpecialKey); diff --git a/progs/tests/crossbar.c b/progs/tests/crossbar.c index 12aabb1c9ad..3dd21372f9a 100644 --- a/progs/tests/crossbar.c +++ b/progs/tests/crossbar.c @@ -35,6 +35,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <GL/glew.h> #include <GL/glut.h> static const GLint tests[][8] = { @@ -226,6 +227,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( Width, Height ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow( "GL_ARB_texture_env_crossbar test" ); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/cva.c b/progs/tests/cva.c index a9393aef0ca..80483900cb7 100644 --- a/progs/tests/cva.c +++ b/progs/tests/cva.c @@ -15,6 +15,7 @@ #include <windows.h> #endif #define GL_GLEXT_LEGACY +#include <GL/glew.h> #include <GL/glut.h> #include <GL/glext.h> @@ -129,6 +130,7 @@ int main( int argc, char **argv ) glutInitWindowSize( 250, 250 ); glutInitWindowPosition( 100, 100 ); glutCreateWindow( "CVA Test" ); + glewInit(); /* Make sure the server supports GL 1.2 vertex arrays. */ diff --git a/progs/tests/debugger.c b/progs/tests/debugger.c index 4c6955bcfc6..1c2f9bebca6 100644 --- a/progs/tests/debugger.c +++ b/progs/tests/debugger.c @@ -9,7 +9,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> @@ -81,6 +81,7 @@ find_line_column(const GLubyte *string, const GLubyte *pos, #define NV_FRAGMENT_PROGRAM 4 + struct breakpoint { enum {PIXEL, LINE} type; int x, y; @@ -101,7 +102,7 @@ static void Debugger2(GLenum target, GLvoid *data) { static GLuint skipCount = 0; const GLubyte *ln; - GLint pos, line, column; + GLint pos = 0, line, column; GLint id; int progType; GLint len; @@ -721,6 +722,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 200, 200 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); diff --git a/progs/tests/dinoshade.c b/progs/tests/dinoshade.c index 44115b9209d..fb7c3f4535c 100644 --- a/progs/tests/dinoshade.c +++ b/progs/tests/dinoshade.c @@ -43,6 +43,7 @@ #include <windows.h> #endif #define GL_GLEXT_LEGACY +#include <GL/glew.h> /* OpenGL Utility Toolkit header */ #include <GL/glut.h> /* OpenGL Utility Toolkit header */ /* Some <math.h> files do not define M_PI... */ @@ -823,6 +824,7 @@ main(int argc, char **argv) #endif glutCreateWindow("Shadowy Leapin' Lizards"); + glewInit(); if (glutGet(GLUT_WINDOW_STENCIL_SIZE) <= 1) { printf("dinoshade: Sorry, I need at least 2 bits of stencil.\n"); diff --git a/progs/tests/drawbuffers.c b/progs/tests/drawbuffers.c index 5e89569380a..d75a870c26b 100644 --- a/progs/tests/drawbuffers.c +++ b/progs/tests/drawbuffers.c @@ -7,11 +7,11 @@ */ -#define GL_GLEXT_PROTOTYPES #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #include "extfuncs.h" @@ -294,6 +294,7 @@ main(int argc, char *argv[]) glutInitWindowSize(Width, Height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Display); diff --git a/progs/tests/exactrast.c b/progs/tests/exactrast.c index 56c0c79c3fa..63b8336d973 100644 --- a/progs/tests/exactrast.c +++ b/progs/tests/exactrast.c @@ -26,6 +26,7 @@ #include <stdio.h> #include <stdlib.h> +#include <GL/glew.h> #include <GL/glut.h> static int Width = 400, Height = 400; @@ -34,14 +35,14 @@ static float Xtrans = 0, Ytrans = 0; static float Step = 0.125; enum { - POINTS, - HLINES, - VLINES, - QUADS, + MODE_POINTS, + MODE_HLINES, + MODE_VLINES, + MODE_QUADS, NUM_MODES }; -static int Mode = POINTS; +static int Mode = MODE_POINTS; static void @@ -58,7 +59,7 @@ Draw(void) glPushMatrix(); glTranslatef(tx + Xtrans, ty + Ytrans, 0); - if (Mode == POINTS) { + if (Mode == MODE_POINTS) { glBegin(GL_POINTS); for (j = 0; j < Height; j += 2) { for (i = 0; i < Width; i += 2) { @@ -67,7 +68,7 @@ Draw(void) } glEnd(); } - else if (Mode == HLINES) { + else if (Mode == MODE_HLINES) { glBegin(GL_LINES); for (i = 0; i < Height; i += 2) { glVertex2f(0, i); @@ -75,7 +76,7 @@ Draw(void) } glEnd(); } - else if (Mode == VLINES) { + else if (Mode == MODE_VLINES) { glBegin(GL_LINES); for (i = 0; i < Width; i += 2) { glVertex2f(i, 0 ); @@ -83,7 +84,7 @@ Draw(void) } glEnd(); } - else if (Mode == QUADS) { + else if (Mode == MODE_QUADS) { glBegin(GL_QUADS); for (j = 0; j < Height; j += 4) { for (i = 0; i < Width; i += 4) { @@ -189,6 +190,7 @@ main(int argc, char *argv[]) glutInitWindowSize(Width, Height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutSpecialFunc(SpecialKey); diff --git a/progs/tests/ext422square.c b/progs/tests/ext422square.c index 6533514d697..89e99f02926 100644 --- a/progs/tests/ext422square.c +++ b/progs/tests/ext422square.c @@ -12,7 +12,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> #include <assert.h> @@ -249,6 +249,7 @@ int main( int argc, char *argv[] ) glutInitWindowPosition( 0, 0 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow(argv[0] ); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); diff --git a/progs/tests/fbotest1.c b/progs/tests/fbotest1.c index ab2757c3c3d..8dac21494e6 100644 --- a/progs/tests/fbotest1.c +++ b/progs/tests/fbotest1.c @@ -6,11 +6,11 @@ */ -#define GL_GLEXT_PROTOTYPES #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> static int Win; @@ -202,6 +202,7 @@ main( int argc, char *argv[] ) glutInitWindowSize(Width, Height); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/fbotest2.c b/progs/tests/fbotest2.c index 5283c7e1fd6..f9c506193f6 100644 --- a/progs/tests/fbotest2.c +++ b/progs/tests/fbotest2.c @@ -6,11 +6,11 @@ */ -#define GL_GLEXT_PROTOTYPES #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> static int Win = 0; @@ -191,6 +191,7 @@ main( int argc, char *argv[] ) glutInitWindowSize(Width, Height); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/fbotexture.c b/progs/tests/fbotexture.c index 1f7c45fc794..50a4b00afce 100644 --- a/progs/tests/fbotexture.c +++ b/progs/tests/fbotexture.c @@ -9,7 +9,7 @@ */ -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> #include <assert.h> #include <stdio.h> @@ -26,9 +26,16 @@ static int Win = 0; static int Width = 400, Height = 400; -static GLenum TexTarget = GL_TEXTURE_2D; /*GL_TEXTURE_RECTANGLE_ARB;*/ +#if 1 +static GLenum TexTarget = GL_TEXTURE_2D; static int TexWidth = 512, TexHeight = 512; -/*static int TexWidth = 600, TexHeight = 600;*/ +static GLenum TexIntFormat = GL_RGB; /* either GL_RGB or GL_RGBA */ +#else +static GLenum TexTarget = GL_TEXTURE_RECTANGLE_ARB; +static int TexWidth = 200, TexHeight = 200; +static GLenum TexIntFormat = GL_RGB5; /* either GL_RGB or GL_RGBA */ +#endif +static GLuint TextureLevel = 0; /* which texture level to render to */ static GLuint MyFB; static GLuint TexObj; @@ -38,8 +45,6 @@ static GLfloat Rot = 0.0; static GLboolean UsePackedDepthStencil = GL_FALSE; static GLboolean UsePackedDepthStencilBoth = GL_FALSE; static GLboolean Use_ARB_fbo = GL_FALSE; -static GLuint TextureLevel = 0; /* which texture level to render to */ -static GLenum TexIntFormat = GL_RGB; /* either GL_RGB or GL_RGBA */ static GLboolean Cull = GL_FALSE; static GLboolean Wireframe = GL_FALSE; @@ -404,8 +409,12 @@ AttachDepthAndStencilBuffers(GLuint fbo, return GL_FALSE; status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); - if (status != GL_FRAMEBUFFER_COMPLETE_EXT) + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + glDeleteRenderbuffersEXT(1, depthRbOut); + *depthRbOut = 0; + glDeleteRenderbuffersEXT(1, &rb); return GL_FALSE; + } *stencilRbOut = rb; } @@ -554,15 +563,17 @@ Init(void) /* make two image levels */ glTexImage2D(TexTarget, 0, TexIntFormat, TexWidth, TexHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexImage2D(TexTarget, 1, TexIntFormat, TexWidth/2, TexHeight/2, 0, - GL_RGBA, GL_UNSIGNED_BYTE, NULL); - TexWidth = TexWidth >> TextureLevel; - TexHeight = TexHeight >> TextureLevel; + if (TexTarget == GL_TEXTURE_2D) { + glTexImage2D(TexTarget, 1, TexIntFormat, TexWidth/2, TexHeight/2, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + TexWidth = TexWidth >> TextureLevel; + TexHeight = TexHeight >> TextureLevel; + glTexParameteri(TexTarget, GL_TEXTURE_MAX_LEVEL, TextureLevel); + } glTexParameteri(TexTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(TexTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(TexTarget, GL_TEXTURE_BASE_LEVEL, TextureLevel); - glTexParameteri(TexTarget, GL_TEXTURE_MAX_LEVEL, TextureLevel); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } @@ -576,7 +587,7 @@ Usage(void) printf("Usage:\n"); printf(" -ds Use combined depth/stencil renderbuffer\n"); printf(" -arb Try GL_ARB_framebuffer_object's mismatched buffer sizes\n"); - printf(" -ds2 Tye GL_ARB_framebuffer_object's GL_DEPTH_STENCIL_ATTACHMENT\n"); + printf(" -ds2 Try GL_ARB_framebuffer_object's GL_DEPTH_STENCIL_ATTACHMENT\n"); printf("Keys:\n"); printf(" a Toggle animation\n"); printf(" s/s Step/rotate\n"); @@ -594,6 +605,7 @@ main(int argc, char *argv[]) glutInitWindowSize(Width, Height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Display); diff --git a/progs/tests/fillrate.c b/progs/tests/fillrate.c index 8fe636c364b..1e58df281e1 100644 --- a/progs/tests/fillrate.c +++ b/progs/tests/fillrate.c @@ -6,10 +6,10 @@ */ -#define GL_GLEXT_PROTOTYPES #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #include "readtex.h" @@ -194,6 +194,7 @@ main(int argc, char *argv[]) glutInitWindowSize(Width, Height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Draw); diff --git a/progs/tests/floattex.c b/progs/tests/floattex.c index dd6d882089c..dd99d836c64 100644 --- a/progs/tests/floattex.c +++ b/progs/tests/floattex.c @@ -8,6 +8,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #include "extfuncs.h" #include "readtex.h" @@ -230,6 +231,7 @@ main(int argc, char *argv[]) glutInitWindowSize(400, 400); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Draw); diff --git a/progs/tests/fog.c b/progs/tests/fog.c index ecd9f533f99..b6cea8c080a 100644 --- a/progs/tests/fog.c +++ b/progs/tests/fog.c @@ -30,10 +30,10 @@ * Test to exercise fog modes and for comparison with GL_EXT_fog_coord. */ -#define GL_GLEXT_PROTOTYPES #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> static int Width = 600; @@ -190,6 +190,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( Width, Height ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/fogcoord.c b/progs/tests/fogcoord.c index 89355742aad..7822d33b09f 100644 --- a/progs/tests/fogcoord.c +++ b/progs/tests/fogcoord.c @@ -3,10 +3,10 @@ */ -#define GL_GLEXT_PROTOTYPES #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> static int Width = 600; @@ -93,6 +93,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( Width, Height ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/fptest1.c b/progs/tests/fptest1.c index 095190a8aef..2b8f8d0f5ec 100644 --- a/progs/tests/fptest1.c +++ b/progs/tests/fptest1.c @@ -5,7 +5,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> @@ -216,6 +216,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/fptexture.c b/progs/tests/fptexture.c index f57ad628282..332e07182dc 100644 --- a/progs/tests/fptexture.c +++ b/progs/tests/fptexture.c @@ -5,7 +5,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> #include "../util/readtex.c" @@ -141,6 +141,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); diff --git a/progs/tests/interleave.c b/progs/tests/interleave.c index e98b3ed0469..47bf9dfbe5e 100644 --- a/progs/tests/interleave.c +++ b/progs/tests/interleave.c @@ -36,6 +36,7 @@ #include <stdlib.h> #include <string.h> #include <time.h> +#include <GL/glew.h> #include <GL/glut.h> static int Width = 400; @@ -386,6 +387,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( Width, Height ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow( "glInterleavedArrays test" ); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/invert.c b/progs/tests/invert.c index 750592ed79f..63099fbd221 100644 --- a/progs/tests/invert.c +++ b/progs/tests/invert.c @@ -35,6 +35,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <GL/glew.h> #include <GL/glut.h> #include "readtex.h" @@ -186,6 +187,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( Width, Height ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow( "GL_MESA_pack_invert test" ); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/lineclip.c b/progs/tests/lineclip.c index 098f5e92ebd..bb688c04a5f 100644 --- a/progs/tests/lineclip.c +++ b/progs/tests/lineclip.c @@ -26,6 +26,7 @@ */ #include <stdlib.h> +#include <GL/glew.h> #include <GL/glut.h> static int win_width, win_height; @@ -164,6 +165,7 @@ main(int argc, char *argv[]) glutInitWindowSize(win_width, win_height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(reshape); glutKeyboardFunc(key); glutDisplayFunc(display); diff --git a/progs/tests/manytex.c b/progs/tests/manytex.c index 83c86766571..52e7e1de44a 100644 --- a/progs/tests/manytex.c +++ b/progs/tests/manytex.c @@ -13,6 +13,7 @@ #include <stdlib.h> #include <string.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> @@ -336,6 +337,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( WinWidth, WinHeight ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/mapbufrange.c b/progs/tests/mapbufrange.c new file mode 100644 index 00000000000..0021bb26071 --- /dev/null +++ b/progs/tests/mapbufrange.c @@ -0,0 +1,205 @@ +/* + * Test glMapBuffer() and glMapBufferRange() + * + * Fill a VBO with vertex data to draw several colored quads. + * On each redraw, update the geometry for just one rect in the VBO. + * + * Brian Paul + * 4 March 2009 + */ + + +#include <assert.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <GL/glew.h> +#include <GL/glew.h> +#include <GL/glut.h> + +static GLuint Win; +static const GLuint NumRects = 10; +static GLuint BufferID; +static GLboolean Anim = GL_TRUE; +static GLboolean UseBufferRange = GL_FALSE; + + + +static const float RectData[] = { + /* vertex */ /* color */ + 0, -1, 0, 1, 0, 0, + 1, 0, 0, 1, 1, 0, + 0, 1, 0, 0, 1, 1, + -1, 0, 0, 1, 0, 1 +}; + + +/** + * The buffer contains vertex positions (float[3]) and colors (float[3]) + * for 'NumRects' quads. + * This function updates/rotates one quad in the buffer. + */ +static void +UpdateRect(int r, float angle) +{ + float *rect; + int i; + + assert(r < NumRects); + + glBindBufferARB(GL_ARRAY_BUFFER_ARB, BufferID); + if (UseBufferRange) { + GLintptr offset = r * sizeof(RectData); + GLsizeiptr length = sizeof(RectData); + GLbitfield access = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT; + float *buf = (float *) glMapBufferRange(GL_ARRAY_BUFFER_ARB, + offset, length, access); + rect = buf; + } + else { + /* map whole buffer */ + float *buf = (float *) + glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB); + rect = buf + r * 24; + } + + /* set rect verts/colors */ + memcpy(rect, RectData, sizeof(RectData)); + + /* loop over four verts, updating vertices */ + for (i = 0; i < 4; i++) { + float x = 0.2 * RectData[i*6+0]; + float y = 0.2 * RectData[i*6+1]; + float xpos = -2.5 + 0.5 * r; + float ypos = 0.0; + + /* translate and rotate vert */ + rect[i * 6 + 0] = xpos + x * cos(angle) + y * sin(angle); + rect[i * 6 + 1] = ypos + x * sin(angle) - y * cos(angle); + } + + glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); +} + + +static void +LoadBuffer(void) +{ + static int frame = 0; + float angle = glutGet(GLUT_ELAPSED_TIME) * 0.001; + UpdateRect(frame % NumRects, angle); + frame++; +} + + +static void +Draw(void) +{ + glBindBufferARB(GL_ARRAY_BUFFER_ARB, BufferID); + glVertexPointer(3, GL_FLOAT, 24, 0); + glEnable(GL_VERTEX_ARRAY); + + glColorPointer(3, GL_FLOAT, 24, (void*) 12); + glEnable(GL_COLOR_ARRAY); + + glDrawArrays(GL_QUADS, 0, NumRects * 4); + + if (0) + glFinish(); +} + + +static void +Display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + Draw(); + glutSwapBuffers(); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-3.0, 3.0, -1.0, 1.0, -1.0, 1.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void +Idle(void) +{ + LoadBuffer(); + glutPostRedisplay(); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + if (key == 'a') { + Anim = !Anim; + glutIdleFunc(Anim ? Idle : NULL); + } + else if (key == 's') { + LoadBuffer(); + } + else if (key == 27) { + glutDestroyWindow(Win); + exit(0); + } + glutPostRedisplay(); +} + + +static void +Init(void) +{ + GLuint BufferSize = NumRects * sizeof(RectData); + float *buf; + + if (!glutExtensionSupported("GL_ARB_vertex_buffer_object")) { + printf("GL_ARB_vertex_buffer_object not found!\n"); + exit(0); + } + + UseBufferRange = glutExtensionSupported("GL_ARB_map_buffer_range"); + printf("Use GL_ARB_map_buffer_range: %c\n", "NY"[UseBufferRange]); + + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + + /* initially load buffer with zeros */ + buf = (float *) calloc(1, BufferSize); + + glGenBuffersARB(1, &BufferID); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, BufferID); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, BufferSize, buf, GL_DYNAMIC_DRAW_ARB); + + free(buf); +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowSize(800, 200); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + Win = glutCreateWindow(argv[0]); + glewInit(); + glewInit(); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Display); + glutIdleFunc(Anim ? Idle : NULL); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/tests/mapvbo.c b/progs/tests/mapvbo.c new file mode 100644 index 00000000000..c392e768358 --- /dev/null +++ b/progs/tests/mapvbo.c @@ -0,0 +1,139 @@ +/* + * Test glMapBuffer() call immediately after glDrawArrays(). + * See details below. + * + * NOTE: Do not use freeglut with this test! It calls the Display() + * callback twice right away instead of just once. + * + * Brian Paul + * 27 Feb 2009 + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <GL/glew.h> +#include <GL/glut.h> + +static GLuint BufferID; + + +static GLuint Win; + + + + +/* + * Create VBO (position and color) and load with data. + */ +static void +SetupBuffers(void) +{ + static const GLfloat data[] = { + /* vertex */ /* color */ + 0, -1, 0, 1, 1, 0, + 1, 0, 0, 1, 1, 0, + 0, 1, 0, 1, 1, 0, + -1, 0, 0, 1, 1, 0 + }; + + glGenBuffersARB(1, &BufferID); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, BufferID); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(data), data, + GL_STATIC_DRAW_ARB); +} + + +static void +Draw(void) +{ + static int count = 1; + + printf("Draw Frame %d\n", count); + count++; + + glBindBufferARB(GL_ARRAY_BUFFER_ARB, BufferID); + glVertexPointer(3, GL_FLOAT, 24, 0); + glEnable(GL_VERTEX_ARRAY); + + glColorPointer(3, GL_FLOAT, 24, (void*) 12); + glEnable(GL_COLOR_ARRAY); + + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + if (0) + glFinish(); + + /* Immediately map the color buffer and change something. + * This should not effect the first glDrawArrays above, but the + * next time we draw we should see a black vertex. + */ + if (1) { + GLfloat *m = (GLfloat *) glMapBufferARB(GL_ARRAY_BUFFER_ARB, + GL_WRITE_ONLY_ARB); + m[3] = m[4] = m[5] = 0.0f; /* black vertex */ + glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); + } +} + + +static void Display( void ) +{ + glClear( GL_COLOR_BUFFER_BIT ); + Draw(); + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + float ar = (float) width / (float) height; + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -ar, ar, -1.0, 1.0, 5.0, 25.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; + if (key == 27) { + glutDestroyWindow(Win); + exit(0); + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ + if (!glutExtensionSupported("GL_ARB_vertex_buffer_object")) { + printf("GL_ARB_vertex_buffer_object not found!\n"); + exit(0); + } + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + + SetupBuffers(); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 300, 300 ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + Win = glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/tests/minmag.c b/progs/tests/minmag.c index 78ef9db03ac..03019f94faa 100644 --- a/progs/tests/minmag.c +++ b/progs/tests/minmag.c @@ -17,6 +17,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <GL/glew.h> #include <GL/glut.h> @@ -189,6 +190,7 @@ main(int argc, char *argv[]) glutInitWindowSize(Width, Height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(redraw); diff --git a/progs/tests/mipgen.c b/progs/tests/mipgen.c new file mode 100644 index 00000000000..088f643215c --- /dev/null +++ b/progs/tests/mipgen.c @@ -0,0 +1,207 @@ +/* Test GL_TEXTURE_BASE_LEVEL and GL_TEXTURE_MAX_LEVEL + * Brian Paul + * 10 May 2006 + */ + + +/* Copyright (c) Mark J. Kilgard, 1994. */ + +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "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, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ + +#include <stdlib.h> +#include <stdio.h> +#include <GL/glew.h> +#include <GL/glut.h> + +#include "readtex.h" + + +static GLfloat LodBias = 6.0; /* make smallest miplevel visible */ +static GLuint texImage; + +#define WIDTH 2 +#define HEIGHT 2 + +static void +InitValues(void) +{ + LodBias = 6.0; /* make smallest miplevel visible */ +} + + +static void MakeImage(void) +{ + const GLubyte color0[4] = { 0xff, 0x80, 0x20, 0xff }; + const GLubyte color1[4] = { 0x10, 0x20, 0x40, 0xff }; + + GLubyte img[WIDTH*HEIGHT*3]; + int i, j; + for (i = 0; i < HEIGHT; i++) { + for (j = 0; j < WIDTH; j++) { + int k = (i * WIDTH + j) * 3; + int p = ((i+j)%2); + if (p == 0) { + img[k + 0] = color0[0]; + img[k + 1] = color0[1]; + img[k + 2] = color0[2]; + } + else { + img[k + 0] = color1[0]; + img[k + 1] = color1[1]; + img[k + 2] = color1[2]; + } + } + } + + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, WIDTH, HEIGHT, 0, + GL_RGB, GL_UNSIGNED_BYTE, img); + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_FALSE); +} + + + +static void myinit(void) +{ + InitValues(); + + glShadeModel(GL_FLAT); + + glTranslatef(0.0, 0.0, -3.6); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glGenTextures(1, &texImage); + glBindTexture(GL_TEXTURE_2D, texImage); + MakeImage(); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glEnable(GL_TEXTURE_2D); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, -1); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 1); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_NEAREST_MIPMAP_NEAREST); +} + + + +static void display(void) +{ + GLfloat tcm = 1.0; + glBindTexture(GL_TEXTURE_2D, texImage); + + printf("Bias=%.2g\n", LodBias); + fflush(stdout); + + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, LodBias); + + glClear(GL_COLOR_BUFFER_BIT); + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); + glTexCoord2f(0.0, tcm); glVertex3f(-2.0, 1.0, 0.0); + glTexCoord2f(tcm * 3000.0, tcm); glVertex3f(3000.0, 1.0, -6000.0); + glTexCoord2f(tcm * 3000.0, 0.0); glVertex3f(3000.0, -1.0, -6000.0); + glEnd(); + glFlush(); +} + +static void myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30000.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +static void +key(unsigned char k, int x, int y) +{ + (void) x; + (void) y; + switch (k) { + case 'l': + LodBias -= 0.25; + break; + case 'L': + LodBias += 0.25; + break; + case ' ': + InitValues(); + break; + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + + +static void usage(void) +{ + printf("usage:\n"); + printf(" l/L decrease/increase GL_TEXTURE_LOD_BIAS\n"); + printf(" SPACE reset values\n"); +} + + +int main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB ); + glutInitWindowSize (600, 600); + glutCreateWindow (argv[0]); + glewInit(); + myinit(); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutKeyboardFunc(key); + usage(); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/tests/mipmap_limits.c b/progs/tests/mipmap_limits.c index 8bdad826f7c..5b899cd1551 100644 --- a/progs/tests/mipmap_limits.c +++ b/progs/tests/mipmap_limits.c @@ -51,19 +51,25 @@ */ #include <stdlib.h> #include <stdio.h> +#include <GL/glew.h> #include <GL/glut.h> -static GLint BaseLevel = 0, MaxLevel = 8; +#include "readtex.h" + +#define TEXTURE_FILE "../images/girl.rgb" + +static GLint BaseLevel = 0, MaxLevel = 9; static GLfloat MinLod = -1, MaxLod = 9; static GLfloat LodBias = 0.0; static GLboolean NearestFilter = GL_TRUE; +static GLuint texImage, texColor, texCurrent; static void InitValues(void) { BaseLevel = 0; - MaxLevel = 8; + MaxLevel = 9; MinLod = -1; MaxLod = 9; LodBias = 0.0; @@ -74,7 +80,7 @@ InitValues(void) static void MakeImage(int level, int width, int height, const GLubyte color[4]) { const int makeStripes = 0; - GLubyte img[256*256*3]; + GLubyte img[512*512*3]; int i, j; for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { @@ -98,87 +104,138 @@ static void MakeImage(int level, int width, int height, const GLubyte color[4]) } -static void makeImages(void) +static void makeImages(int image) { - static const GLubyte colors[8][3] = { - {128, 128, 128 }, - { 0, 255, 255 }, - { 255, 255, 0 }, - { 255, 0, 255 }, - { 255, 0, 0 }, - { 0, 255, 0 }, - { 0, 0, 255 }, - { 255, 255, 255 } - }; - int i, sz = 128; - - for (i = 0; i < 8; i++) { - MakeImage(i, sz, sz, colors[i]); - sz /= 2; +#define WIDTH 512 +#define HEIGHT 512 + if (glutExtensionSupported("GL_SGIS_generate_mipmap") && image) { + /* test auto mipmap generation */ + GLint width, height, i; + GLenum format; + GLubyte *image = LoadRGBImage(TEXTURE_FILE, &width, &height, &format); + if (!image) { + printf("Error: could not load texture image %s\n", TEXTURE_FILE); + exit(1); + } + /* resize */ + if (width != WIDTH || height != HEIGHT) { + GLubyte *newImage = malloc(WIDTH * HEIGHT * 4); + gluScaleImage(format, width, height, GL_UNSIGNED_BYTE, image, + WIDTH, HEIGHT, GL_UNSIGNED_BYTE, newImage); + free(image); + image = newImage; + } + printf("Using GL_SGIS_generate_mipmap\n"); + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); + glTexImage2D(GL_TEXTURE_2D, 0, format, WIDTH, HEIGHT, 0, + format, GL_UNSIGNED_BYTE, image); + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_FALSE); + free(image); + + /* make sure mipmap was really generated correctly */ + width = WIDTH; height = HEIGHT; + for (i = 0; i < 10; i++) { + GLint w, h; + glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w); + glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_HEIGHT, &h); + printf("Level %d size: %d x %d\n", i, w, h); + width /= 2; + height /= 2; + } + } else { + static const GLubyte colors[10][3] = { + {128, 128, 128 }, + { 0, 255, 255 }, + { 255, 255, 0 }, + { 255, 0, 255 }, + { 255, 0, 0 }, + { 0, 255, 0 }, + { 0, 0, 255 }, + { 0, 255, 255 }, + { 255, 255, 0 }, + { 255, 255, 255 } + }; + int i, sz = 512; + + for (i = 0; i < 10; i++) { + MakeImage(i, sz, sz, colors[i]); + printf("Level %d size: %d x %d\n", i, sz, sz); + sz /= 2; + } } } static void myinit(void) { - InitValues(); + InitValues(); + + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + glShadeModel(GL_FLAT); - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); - glShadeModel(GL_FLAT); + glTranslatef(0.0, 0.0, -3.6); - glTranslatef(0.0, 0.0, -3.6); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glGenTextures(1, &texImage); + glBindTexture(GL_TEXTURE_2D, texImage); + makeImages(1); + glGenTextures(1, &texColor); + glBindTexture(GL_TEXTURE_2D, texColor); + makeImages(0); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - makeImages(); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); - glEnable(GL_TEXTURE_2D); + texCurrent = texImage; + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glEnable(GL_TEXTURE_2D); } static void display(void) { - GLfloat tcm = 4.0; - printf("BASE_LEVEL=%d MAX_LEVEL=%d MIN_LOD=%.2g MAX_LOD=%.2g Bias=%.2g Filter=%s\n", - BaseLevel, MaxLevel, MinLod, MaxLod, LodBias, - NearestFilter ? "NEAREST" : "LINEAR"); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, BaseLevel); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, MaxLevel); - - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, MinLod); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, MaxLod); - - if (NearestFilter) { - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, - GL_NEAREST_MIPMAP_NEAREST); - } - else { - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, - GL_LINEAR_MIPMAP_LINEAR); - } - - glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, LodBias); - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glBegin(GL_QUADS); - glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); - glTexCoord2f(0.0, tcm); glVertex3f(-2.0, 1.0, 0.0); - glTexCoord2f(tcm, tcm); glVertex3f(3000.0, 1.0, -6000.0); - glTexCoord2f(tcm, 0.0); glVertex3f(3000.0, -1.0, -6000.0); - glEnd(); - glFlush(); + GLfloat tcm = 1.0; + glBindTexture(GL_TEXTURE_2D, texCurrent); + + printf("BASE_LEVEL=%d MAX_LEVEL=%d MIN_LOD=%.2g MAX_LOD=%.2g Bias=%.2g Filter=%s\n", + BaseLevel, MaxLevel, MinLod, MaxLod, LodBias, + NearestFilter ? "NEAREST" : "LINEAR"); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, BaseLevel); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, MaxLevel); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, MinLod); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, MaxLod); + + if (NearestFilter) { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_NEAREST_MIPMAP_NEAREST); + } + else { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_LINEAR_MIPMAP_LINEAR); + } + + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, LodBias); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); + glTexCoord2f(0.0, tcm); glVertex3f(-2.0, 1.0, 0.0); + glTexCoord2f(tcm * 3000.0, tcm); glVertex3f(3000.0, 1.0, -6000.0); + glTexCoord2f(tcm * 3000.0, 0.0); glVertex3f(3000.0, -1.0, -6000.0); + glEnd(); + glFlush(); } static void myReshape(int w, int h) { - glViewport(0, 0, w, h); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30000.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30000.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); } static void @@ -228,6 +285,12 @@ key(unsigned char k, int x, int y) case 'f': NearestFilter = !NearestFilter; break; + case 't': + if (texCurrent == texColor) + texCurrent = texImage; + else + texCurrent = texColor; + break; case ' ': InitValues(); break; @@ -250,6 +313,7 @@ static void usage(void) printf(" x/X decrease/increase GL_TEXTURE_MAX_LOD\n"); printf(" l/L decrease/increase GL_TEXTURE_LOD_BIAS\n"); printf(" f toggle nearest/linear filtering\n"); + printf(" t toggle texture color/image\n"); printf(" SPACE reset values\n"); } @@ -260,6 +324,7 @@ int main(int argc, char** argv) glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize (600, 600); glutCreateWindow (argv[0]); + glewInit(); myinit(); glutReshapeFunc (myReshape); glutDisplayFunc(display); diff --git a/progs/tests/mipmap_view.c b/progs/tests/mipmap_view.c index 54607b89398..16f3584f703 100644 --- a/progs/tests/mipmap_view.c +++ b/progs/tests/mipmap_view.c @@ -10,6 +10,7 @@ #include <stdlib.h> #include <stdio.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #include <GL/glext.h> @@ -242,6 +243,7 @@ main(int argc, char *argv[]) glutInitWindowSize(WinWidth, WinHeight); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Display); diff --git a/progs/tests/multipal.c b/progs/tests/multipal.c index 7bd44735659..4a940169780 100644 --- a/progs/tests/multipal.c +++ b/progs/tests/multipal.c @@ -13,6 +13,7 @@ #include <windows.h> #endif #define GL_GLEXT_LEGACY +#include <GL/glew.h> #include <GL/glut.h> #include "../util/readtex.c" /* I know, this is a hack. */ @@ -350,6 +351,7 @@ int main( int argc, char *argv[] ) glutInitWindowPosition( 0, 0 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow(argv[0] ); + glewInit(); Init( argc, argv ); diff --git a/progs/tests/multitexarray.c b/progs/tests/multitexarray.c index b4fab004a63..518fee2992c 100644 --- a/progs/tests/multitexarray.c +++ b/progs/tests/multitexarray.c @@ -16,6 +16,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include "GL/glew.h" #include "GL/glut.h" static GLuint Window = 0; @@ -221,6 +222,7 @@ int main( int argc, char *argv[] ) glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); Window = glutCreateWindow("Texture Objects"); + glewInit(); if (!Window) { exit(1); } diff --git a/progs/tests/multiwindow.c b/progs/tests/multiwindow.c index b069bea91cc..6db552d195a 100644 --- a/progs/tests/multiwindow.c +++ b/progs/tests/multiwindow.c @@ -25,6 +25,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> @@ -145,6 +146,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 400, 400 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); Window[0] = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display0 ); @@ -155,6 +157,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 400, 400 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); Window[1] = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display1 ); diff --git a/progs/tests/no_s3tc.c b/progs/tests/no_s3tc.c index d3383ff98af..31cfb40b9d3 100644 --- a/progs/tests/no_s3tc.c +++ b/progs/tests/no_s3tc.c @@ -38,6 +38,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <GL/glew.h> #include <GL/glut.h> #include <GL/glext.h> @@ -59,6 +60,7 @@ main( int argc, char ** argv ) glutInitWindowPosition( 0, 0 ); glutInitWindowSize( 300, 300 ); glutCreateWindow( "No S3TC Test" ); + glewInit(); gl_version = strtod( (const char *) glGetString( GL_VERSION ), NULL ); if ( ! glutExtensionSupported( "GL_ARB_texture_compression" ) diff --git a/progs/tests/packedpixels.c b/progs/tests/packedpixels.c index 67ffe088259..1703b271cb0 100644 --- a/progs/tests/packedpixels.c +++ b/progs/tests/packedpixels.c @@ -8,6 +8,7 @@ #include <stdlib.h> #include <math.h> #include <string.h> +#include <GL/glew.h> #include <GL/glut.h> @@ -333,6 +334,7 @@ main(int argc, char *argv[]) glutInitWindowSize(700, 800); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Draw); diff --git a/progs/tests/pbo.c b/progs/tests/pbo.c index b31b36cc121..9974486db39 100644 --- a/progs/tests/pbo.c +++ b/progs/tests/pbo.c @@ -5,12 +5,12 @@ * 11 March 2004 */ -#define GL_GLEXT_PROTOTYPES #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #include "../util/readtex.c" /* a hack, I know */ @@ -287,6 +287,7 @@ main( int argc, char *argv[] ) glutInitWindowSize( 750, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow(argv[0]); + glewInit(); Init(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); diff --git a/progs/tests/prog_parameter.c b/progs/tests/prog_parameter.c index 96697e5bda6..6dd956c4023 100644 --- a/progs/tests/prog_parameter.c +++ b/progs/tests/prog_parameter.c @@ -35,6 +35,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #ifndef GL_EXT_gpu_program_parameters @@ -274,6 +275,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( Width, Height ); glutInitDisplayMode( GLUT_RGB ); glutCreateWindow( "Program Parameters Test" ); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/projtex.c b/progs/tests/projtex.c index e3ef948ab6a..800d81ecd67 100644 --- a/progs/tests/projtex.c +++ b/progs/tests/projtex.c @@ -18,6 +18,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #if 0 #include "texture.h" @@ -1005,6 +1006,7 @@ main(int argc, char **argv) glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); (void) glutCreateWindow("projtex"); + glewInit(); loadTexture = loadImageTextures; drawObject = drawCube; diff --git a/progs/tests/quads.c b/progs/tests/quads.c index 1bf57e6337d..2098b51ccd2 100644 --- a/progs/tests/quads.c +++ b/progs/tests/quads.c @@ -3,10 +3,10 @@ */ -#define GL_GLEXT_PROTOTYPES #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #define NUM_QUADS 20 @@ -19,7 +19,7 @@ static GLuint Vbuffer = 0; static GLfloat buf[NUM_QUADS * 6 * 4]; -static GLboolean SwapBuffers = GL_TRUE; +static GLboolean doSwapBuffers = GL_TRUE; static GLint Frames = 0, T0 = 0; @@ -48,7 +48,7 @@ Draw(void) glPopMatrix(); - if (SwapBuffers) + if (doSwapBuffers) glutSwapBuffers(); /* else @@ -91,7 +91,7 @@ Key(unsigned char key, int x, int y) (void) y; switch (key) { case 's': - SwapBuffers = !SwapBuffers; + doSwapBuffers = !doSwapBuffers; break; case 'a': Anim = !Anim; @@ -246,6 +246,7 @@ main(int argc, char *argv[]) glutInitWindowSize(600, 600); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutSpecialFunc(SpecialKey); diff --git a/progs/tests/random.c b/progs/tests/random.c index d52c338e0e1..4023674c05f 100644 --- a/progs/tests/random.c +++ b/progs/tests/random.c @@ -5,13 +5,13 @@ * 21 June 2007 */ -#define GL_GLEXT_PROTOTYPES #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> static int Win; @@ -445,6 +445,7 @@ main(int argc, char *argv[]) glutInitWindowSize(Width, Height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); Win = glutCreateWindow(argv[0]); + glewInit(); ParseArgs(argc, argv); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); diff --git a/progs/tests/readrate.c b/progs/tests/readrate.c index 42ae62d48a9..6bdda049071 100644 --- a/progs/tests/readrate.c +++ b/progs/tests/readrate.c @@ -7,11 +7,11 @@ * gcc readrate.c -L/usr/X11R6/lib -lglut -lGLU -lGL -lX11 -o readrate */ -#define GL_GLEXT_PROTOTYPES #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> /* Hack, to test drawing instead of reading */ @@ -275,6 +275,7 @@ main(int argc, char *argv[]) glutInitWindowSize(MAX_WIDTH, MAX_HEIGHT); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutSpecialFunc(SpecialKey); diff --git a/progs/tests/rubberband.c b/progs/tests/rubberband.c index a8e64bc0916..866a0f519e5 100644 --- a/progs/tests/rubberband.c +++ b/progs/tests/rubberband.c @@ -2,10 +2,10 @@ * Test rubber-band selection box w/ logicops and blend. */ -#define GL_GLEXT_PROTOTYPES #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #include "readtex.c" @@ -232,6 +232,7 @@ main(int argc, char *argv[]) glutInitWindowSize(Width, Height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutSpecialFunc(SpecialKey); diff --git a/progs/tests/seccolor.c b/progs/tests/seccolor.c index 77fd40647ba..f1ba314ef07 100644 --- a/progs/tests/seccolor.c +++ b/progs/tests/seccolor.c @@ -3,10 +3,10 @@ */ -#define GL_GLEXT_PROTOTYPES #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> static int Width = 600; @@ -136,6 +136,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( Width, Height ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/shader_api.c b/progs/tests/shader_api.c index 679f9137c82..a513ca6ba1f 100644 --- a/progs/tests/shader_api.c +++ b/progs/tests/shader_api.c @@ -5,7 +5,7 @@ #include <string.h> #include <stdio.h> #include <stdlib.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> static void assert_test(const char *file, int line, int cond, const char *msg) @@ -323,6 +323,7 @@ int main(int argc, char **argv) { glutInit(&argc, argv); glutCreateWindow("Mesa bug demo"); + glewInit(); RUN_TEST(test_uniform_size_type); RUN_TEST(test_attrib_size_type); diff --git a/progs/tests/stencil_twoside.c b/progs/tests/stencil_twoside.c index 8826c46fc26..1e18ca6b5ea 100644 --- a/progs/tests/stencil_twoside.c +++ b/progs/tests/stencil_twoside.c @@ -33,6 +33,7 @@ #include <stdio.h> #include <stdlib.h> +#include <GL/glew.h> #include <GL/glut.h> static int use20syntax = 1; @@ -288,6 +289,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( Width, Height ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL ); glutCreateWindow( "GL_ATI_separate_stencil test" ); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/stencil_wrap.c b/progs/tests/stencil_wrap.c index 88cf3809caf..28307fef4f0 100644 --- a/progs/tests/stencil_wrap.c +++ b/progs/tests/stencil_wrap.c @@ -34,6 +34,7 @@ #include <stdio.h> #include <stdlib.h> +#include <GL/glew.h> #include <GL/glut.h> static int Width = 550; @@ -248,6 +249,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( Width, Height ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL ); glutCreateWindow( "GL_EXT_stencil_wrap test" ); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/stencilwrap.c b/progs/tests/stencilwrap.c index 753375d0f3a..2e219fd8b50 100644 --- a/progs/tests/stencilwrap.c +++ b/progs/tests/stencilwrap.c @@ -8,6 +8,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> GLboolean wrapping; @@ -272,6 +273,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 400, 400 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_STENCIL ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/subtex.c b/progs/tests/subtex.c index 81ceb085aaf..86b737c01fa 100644 --- a/progs/tests/subtex.c +++ b/progs/tests/subtex.c @@ -9,6 +9,7 @@ #include <assert.h> #include <stdio.h> #include <stdlib.h> +#include "GL/glew.h" #include "GL/glut.h" static GLuint Window = 0; @@ -207,6 +208,7 @@ int main( int argc, char *argv[] ) glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); Window = glutCreateWindow("Texture Objects"); + glewInit(); if (!Window) { exit(1); } diff --git a/progs/tests/subtexrate.c b/progs/tests/subtexrate.c index 568b68d552d..4bda970d067 100644 --- a/progs/tests/subtexrate.c +++ b/progs/tests/subtexrate.c @@ -5,11 +5,11 @@ * 26 Jan 2006 */ -#define GL_GLEXT_PROTOTYPES #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> static GLint WinWidth = 1024, WinHeight = 512; @@ -337,6 +337,7 @@ main(int argc, char *argv[]) glutInitWindowSize(WinWidth, WinHeight); glutInitDisplayMode(mode); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutSpecialFunc(SpecialKey); diff --git a/progs/tests/tex1d.c b/progs/tests/tex1d.c index 1fab849dd3e..4abe1068c7b 100644 --- a/progs/tests/tex1d.c +++ b/progs/tests/tex1d.c @@ -7,6 +7,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include "GL/glew.h" #include "GL/glut.h" static GLuint Window = 0; @@ -124,6 +125,7 @@ int main( int argc, char *argv[] ) glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); Window = glutCreateWindow("Texture Objects"); + glewInit(); if (!Window) { exit(1); } diff --git a/progs/tests/texcmp.c b/progs/tests/texcmp.c index 6e822fb6895..52c504a3188 100644 --- a/progs/tests/texcmp.c +++ b/progs/tests/texcmp.c @@ -7,7 +7,7 @@ #include <stdlib.h> #include <math.h> #include <string.h> -#define GL_GLEXT_PROTOTYPES 1 +#include <GL/glew.h> #include <GL/glut.h> #include "readtex.c" /* I know, this is a hack. */ @@ -371,6 +371,7 @@ int main( int argc, char *argv[] ) glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); if (glutCreateWindow(argv[0]) <= 0) { + glewInit(); printf("Couldn't create window\n"); exit(0); } diff --git a/progs/tests/texcompress2.c b/progs/tests/texcompress2.c index e2eed756b62..3e8e9908cbe 100644 --- a/progs/tests/texcompress2.c +++ b/progs/tests/texcompress2.c @@ -3,9 +3,9 @@ */ -#define GL_GLEXT_PROTOTYPES #include <assert.h> #include <stdio.h> +#include <GL/glew.h> #include <GL/glut.h> #include <GL/glx.h> #include "readtex.c" @@ -258,6 +258,7 @@ main( int argc, char *argv[] ) glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); diff --git a/progs/tests/texfilt.c b/progs/tests/texfilt.c index 6ee4bc4eae3..fa919dba624 100644 --- a/progs/tests/texfilt.c +++ b/progs/tests/texfilt.c @@ -27,6 +27,7 @@ #include <stdlib.h> #include <string.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> const GLenum filter_modes[] = { @@ -219,8 +220,8 @@ static void Init( void ) static void generate_tunnel( unsigned num_segs, GLfloat ** pos_data, GLfloat ** tex_data ) { - const GLfloat far = 20.0f; - const GLfloat near = -90.0f; + const GLfloat far_distance = 20.0f; + const GLfloat near_distance = -90.0f; const GLfloat far_tex = 30.0f; const GLfloat near_tex = 0.0f; const GLfloat angle_step = (2 * M_PI) / num_segs; @@ -241,12 +242,12 @@ static void generate_tunnel( unsigned num_segs, GLfloat ** pos_data, for ( i = 0 ; i < num_segs ; i++ ) { position[0] = 2.5 * sinf( angle ); position[1] = 2.5 * cosf( angle ); - position[2] = (i & 1) ? far : near; + position[2] = (i & 1) ? far_distance : near_distance; position[3] = 1.0f; position[4] = position[0]; position[5] = position[1]; - position[6] = (i & 1) ? near : far; + position[6] = (i & 1) ? near_distance : far_distance; position[7] = 1.0f; position += 8; @@ -264,12 +265,12 @@ static void generate_tunnel( unsigned num_segs, GLfloat ** pos_data, position[0] = 2.5 * sinf( angle ); position[1] = 2.5 * cosf( angle ); - position[2] = (i & 1) ? near : far; + position[2] = (i & 1) ? near_distance : far_distance; position[3] = 1.0f; position[4] = position[0]; position[5] = position[1]; - position[6] = (i & 1) ? far : near; + position[6] = (i & 1) ? far_distance : near_distance; position[7] = 1.0f; position += 8; @@ -381,6 +382,7 @@ int main( int argc, char ** argv ) glutInitWindowSize( 800, 600 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow( "Texture Filter Test" ); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); diff --git a/progs/tests/texgenmix.c b/progs/tests/texgenmix.c index be8f6775c70..008da8625e2 100644 --- a/progs/tests/texgenmix.c +++ b/progs/tests/texgenmix.c @@ -6,6 +6,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <GL/glew.h> #include <GL/glut.h> #undef max @@ -618,6 +619,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( winWidth, winHeight ); glutInitWindowPosition( 0, 0 ); glutCreateWindow( "Mixed texgen/non-texgen texture coordinate test" ); + glewInit(); initialize(); instructions(); diff --git a/progs/tests/texline.c b/progs/tests/texline.c index 76dfccd9b1a..1803832b47e 100644 --- a/progs/tests/texline.c +++ b/progs/tests/texline.c @@ -9,6 +9,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #include "../util/readtex.c" /* I know, this is a hack. */ @@ -263,6 +264,7 @@ int main( int argc, char *argv[] ) glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow(argv[0] ); + glewInit(); Init(argc, argv); diff --git a/progs/tests/texrect.c b/progs/tests/texrect.c index 43edc491801..10061ee5869 100644 --- a/progs/tests/texrect.c +++ b/progs/tests/texrect.c @@ -6,11 +6,11 @@ */ -#define GL_GLEXT_PROTOTYPES #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <GL/glew.h> #include <GL/glut.h> #include "readtex.h" @@ -328,6 +328,7 @@ int main( int argc, char *argv[] ) glutInitWindowPosition( 0, 0 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow(argv[0] ); + glewInit(); Init( argc, argv ); diff --git a/progs/tests/texwrap.c b/progs/tests/texwrap.c index 8143256f8ae..12f045b72e0 100644 --- a/progs/tests/texwrap.c +++ b/progs/tests/texwrap.c @@ -8,10 +8,10 @@ */ -#define GL_GLEXT_PROTOTYPES #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> @@ -294,6 +294,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 1000, 270 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/unfilledclip.c b/progs/tests/unfilledclip.c index f25e52616aa..db6fffa3e89 100644 --- a/progs/tests/unfilledclip.c +++ b/progs/tests/unfilledclip.c @@ -26,6 +26,7 @@ */ #include <stdlib.h> +#include <GL/glew.h> #include <GL/glut.h> static int win_width, win_height; @@ -194,6 +195,7 @@ main(int argc, char *argv[]) glutInitWindowSize(win_width, win_height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(reshape); glutKeyboardFunc(key); glutDisplayFunc(display); diff --git a/progs/tests/vao-01.c b/progs/tests/vao-01.c index c2d70885f05..117fae8bd9e 100644 --- a/progs/tests/vao-01.c +++ b/progs/tests/vao-01.c @@ -49,6 +49,7 @@ typedef void (* PFNGLGENVERTEXARRAYSAPPLEPROC) (GLsizei n, GLuint *arrays); typedef GLboolean (* PFNGLISVERTEXARRAYAPPLEPROC) (GLuint array); #else +#include <GL/glew.h> #include <GL/glut.h> #endif @@ -166,6 +167,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( Width, Height ); glutInitDisplayMode( GLUT_RGB ); glutCreateWindow( "GL_APPLE_vertex_array_object demo" ); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/vao-02.c b/progs/tests/vao-02.c index 993bc368d40..7764ed51061 100644 --- a/progs/tests/vao-02.c +++ b/progs/tests/vao-02.c @@ -49,6 +49,7 @@ typedef void (* PFNGLGENVERTEXARRAYSAPPLEPROC) (GLsizei n, GLuint *arrays); typedef GLboolean (* PFNGLISVERTEXARRAYAPPLEPROC) (GLuint array); #else +#include <GL/glew.h> #include <GL/glut.h> #endif @@ -194,6 +195,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( Width, Height ); glutInitDisplayMode( GLUT_RGB ); glutCreateWindow( "GL_APPLE_vertex_array_object demo" ); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/vparray.c b/progs/tests/vparray.c index 580a670f8e1..9c2fad97d9d 100644 --- a/progs/tests/vparray.c +++ b/progs/tests/vparray.c @@ -12,7 +12,7 @@ #include <stdlib.h> #include <string.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include "GL/glew.h" #include "GL/glut.h" #define MAXVERTS 10000 @@ -280,6 +280,7 @@ int main(int argc, char **argv) glutInitWindowPosition(0, 0); glutInitWindowSize(400, 400); if (glutCreateWindow("Isosurface") <= 0) { + glewInit(); exit(0); } glutReshapeFunc(Reshape); diff --git a/progs/tests/vpeval.c b/progs/tests/vpeval.c index 8b6996d3b5c..f07737f9736 100644 --- a/progs/tests/vpeval.c +++ b/progs/tests/vpeval.c @@ -10,7 +10,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> @@ -222,6 +222,7 @@ main(int argc, char **argv) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowPosition(0, 0); glutCreateWindow(argv[0]); + glewInit(); myinit(argc, argv); glutReshapeFunc(myReshape); glutDisplayFunc(display); diff --git a/progs/tests/vptest1.c b/progs/tests/vptest1.c index 560df2c3fdc..51629192923 100644 --- a/progs/tests/vptest1.c +++ b/progs/tests/vptest1.c @@ -5,7 +5,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> @@ -161,6 +161,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/vptest2.c b/progs/tests/vptest2.c index 2158e07f042..4161b03a673 100644 --- a/progs/tests/vptest2.c +++ b/progs/tests/vptest2.c @@ -5,7 +5,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> @@ -140,6 +140,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 50, 50 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/vptest3.c b/progs/tests/vptest3.c index 2c5c8000408..4e4bfee31dc 100644 --- a/progs/tests/vptest3.c +++ b/progs/tests/vptest3.c @@ -5,7 +5,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> static float Zrot = 0.0; @@ -111,6 +111,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/tests/vptorus.c b/progs/tests/vptorus.c index 764dea4ec22..e61ffdac217 100644 --- a/progs/tests/vptorus.c +++ b/progs/tests/vptorus.c @@ -7,7 +7,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> static float Xrot = 0.0, Yrot = 0.0, Zrot = 0.0; @@ -162,6 +162,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); diff --git a/progs/tests/vpwarpmesh.c b/progs/tests/vpwarpmesh.c index 56aa8200ec8..80204ea1361 100644 --- a/progs/tests/vpwarpmesh.c +++ b/progs/tests/vpwarpmesh.c @@ -7,7 +7,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> static float Xrot = -60.0, Yrot = 0.0, Zrot = 0.0; @@ -224,6 +224,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutSpecialFunc( SpecialKey ); diff --git a/progs/tests/yuvrect.c b/progs/tests/yuvrect.c index acef4060970..aab2f80ed9a 100644 --- a/progs/tests/yuvrect.c +++ b/progs/tests/yuvrect.c @@ -9,7 +9,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> #include "../util/readtex.c" /* I know, this is a hack. */ @@ -180,6 +180,7 @@ int main( int argc, char *argv[] ) glutInitWindowPosition( 0, 0 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow(argv[0] ); + glewInit(); Init( argc, argv ); diff --git a/progs/tests/yuvsquare.c b/progs/tests/yuvsquare.c index 3601e7a31c7..658528b7996 100644 --- a/progs/tests/yuvsquare.c +++ b/progs/tests/yuvsquare.c @@ -9,7 +9,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> #include "../util/readtex.c" /* I know, this is a hack. */ @@ -219,6 +219,7 @@ int main( int argc, char *argv[] ) glutInitWindowPosition( 0, 0 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutCreateWindow(argv[0] ); + glewInit(); Init( argc, argv ); diff --git a/progs/tests/zcomp.c b/progs/tests/zcomp.c index b53079d07fc..15e35f17b09 100644 --- a/progs/tests/zcomp.c +++ b/progs/tests/zcomp.c @@ -2,10 +2,10 @@ * Test Z compositing with glDrawPixels(GL_DEPTH_COMPONENT) and stencil test. */ -#define GL_GLEXT_PROTOTYPES #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #include "../util/showbuffer.c" @@ -211,6 +211,7 @@ main(int argc, char *argv[]) glutInitWindowSize(Width, Height); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutSpecialFunc(SpecialKey); diff --git a/progs/tests/zdrawpix.c b/progs/tests/zdrawpix.c index dd222e7dd0b..ba7da571ebf 100644 --- a/progs/tests/zdrawpix.c +++ b/progs/tests/zdrawpix.c @@ -10,10 +10,10 @@ * Press 'd' to view the Z buffer as a grayscale image. */ -#define GL_GLEXT_PROTOTYPES #include <stdio.h> #include <stdlib.h> #include <math.h> +#include <GL/glew.h> #include <GL/glut.h> #include "../util/showbuffer.c" @@ -180,6 +180,7 @@ main(int argc, char *argv[]) glutInitWindowSize(400, 400); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutSpecialFunc(SpecialKey); diff --git a/progs/tests/zreaddraw.c b/progs/tests/zreaddraw.c index e2dacbf7f2f..3d8c557b370 100644 --- a/progs/tests/zreaddraw.c +++ b/progs/tests/zreaddraw.c @@ -8,7 +8,7 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES +#include <GL/glew.h> #include <GL/glut.h> static GLint WinWidth = 500, WinHeight = 500; @@ -107,6 +107,7 @@ int main(int argc, char *argv[]) glutInitWindowSize(WinWidth, WinHeight); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Display); diff --git a/progs/trivial/.gitignore b/progs/trivial/.gitignore index d77f120b96b..aec4c94527d 100644 --- a/progs/trivial/.gitignore +++ b/progs/trivial/.gitignore @@ -9,6 +9,7 @@ dlist-dangling dlist-degenerate dlist-edgeflag dlist-edgeflag-dangling +draw2arrays drawarrays drawelements drawrange @@ -58,11 +59,13 @@ quad-tex-2d quad-tex-3d quad-tex-alpha quad-tex-pbo +quad-tex-sub quad-unfilled quad-unfilled-clip quad-unfilled-stipple quads quadstrip +quadstrip-clip quadstrip-cont quadstrip-flat readtex.c @@ -83,12 +86,15 @@ tri-dlist tri-edgeflag tri-fbo tri-fbo-tex +tri-fbo-tex-mip tri-flat tri-flat-clip tri-fog tri-fp tri-fp-const-imm tri-lit +tri-logicop-none +tri-logicop-xor tri-mask-tri tri-orig tri-query @@ -102,12 +108,14 @@ tri-tri tri-unfilled tri-unfilled-clip tri-unfilled-edgeflag +tri-unfilled-fog tri-unfilled-smooth tri-unfilled-tri tri-unfilled-tri-lit tri-unfilled-userclip tri-unfilled-userclip-stip tri-userclip +tri-viewport tri-z tri-z-eq trifan diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index dce96f6bc8c..082387d86ea 100644 --- a/progs/trivial/Makefile +++ b/progs/trivial/Makefile @@ -23,6 +23,7 @@ SOURCES = \ dlist-edgeflag.c \ dlist-degenerate.c \ drawarrays.c \ + draw2arrays.c \ drawelements.c \ drawrange.c \ flat-clip.c \ @@ -69,11 +70,13 @@ SOURCES = \ quad-tex-3d.c \ quad-tex-alpha.c \ quad-tex-pbo.c \ + quad-tex-sub.c \ quad-unfilled-clip.c \ quad-unfilled-stipple.c \ quad-unfilled.c \ quad.c \ quads.c \ + quadstrip-clip.c \ quadstrip-cont.c \ quadstrip-flat.c \ quadstrip.c \ @@ -88,8 +91,11 @@ SOURCES = \ tri-clip.c \ tri-cull-both.c \ tri-cull.c \ + tri-logicop-none.c \ + tri-logicop-xor.c \ tri-dlist.c \ tri-edgeflag.c \ + tri-fbo-tex-mip.c \ tri-fbo-tex.c \ tri-fbo.c \ tri-flat-clip.c \ @@ -108,6 +114,7 @@ SOURCES = \ tri-tex.c \ tri-tex-3d.c \ tri-tri.c \ + tri-unfilled-fog.c \ tri-unfilled-edgeflag.c \ tri-unfilled-clip.c \ tri-unfilled-smooth.c \ @@ -117,6 +124,7 @@ SOURCES = \ tri-unfilled-userclip.c \ tri-unfilled.c \ tri-userclip.c \ + tri-viewport.c \ tri-z-eq.c \ tri-z.c \ tri.c \ diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index 76826d9be08..6a9ffafe509 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -19,6 +19,7 @@ progs = [ 'dlist-edgeflag', 'dlist-degenerate', 'drawarrays', + 'draw2arrays', 'drawelements', 'drawrange', 'flat-clip', @@ -65,11 +66,13 @@ progs = [ 'quad-tex-3d', 'quad-tex-alpha', 'quad-tex-pbo', + 'quad-tex-sub', 'quad-unfilled-clip', 'quad-unfilled-stipple', 'quad-unfilled', 'quad', 'quads', + 'quadstrip-clip', 'quadstrip-cont', 'quadstrip-flat', 'quadstrip', @@ -86,6 +89,7 @@ progs = [ 'tri-cull', 'tri-dlist', 'tri-edgeflag', + 'tri-fbo-tex-mip', 'tri-fbo-tex', 'tri-fbo', 'tri-flat-clip', @@ -94,15 +98,19 @@ progs = [ 'tri-fp', 'tri-fp-const-imm', 'tri-lit', + 'tri-logicop-none', + 'tri-logicop-xor', 'tri-mask-tri', 'tri-orig', 'tri-query', 'tri-repeat', 'tri-scissor-tri', 'tri-stencil', + 'tri-stipple', 'tri-tex', 'tri-tex-3d', 'tri-tri', + 'tri-unfilled-fog', 'tri-unfilled-edgeflag', 'tri-unfilled-clip', 'tri-unfilled-smooth', @@ -112,6 +120,7 @@ progs = [ 'tri-unfilled-userclip', 'tri-unfilled', 'tri-userclip', + 'tri-viewport', 'tri-z-eq', 'tri-z', 'tri', diff --git a/progs/trivial/clear-random.c b/progs/trivial/clear-random.c index 16bd83339b8..f3a67dbe8a8 100644 --- a/progs/trivial/clear-random.c +++ b/progs/trivial/clear-random.c @@ -118,7 +118,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/clear-repeat.c b/progs/trivial/clear-repeat.c index 9f9490c6c87..9c618d492f3 100644 --- a/progs/trivial/clear-repeat.c +++ b/progs/trivial/clear-repeat.c @@ -72,6 +72,24 @@ static void Draw(void) glClearColor((sin(f)+1)/2.0,(cos(f)+1)/2.0,0.5,1); glClear(GL_COLOR_BUFFER_BIT); glutSwapBuffers(); + + { + static GLint T0 = 0; + static GLint Frames = 0; + GLint t = glutGet(GLUT_ELAPSED_TIME); + + Frames++; + + if (t - T0 >= 5000) { + GLfloat seconds = (t - T0) / 1000.0; + GLfloat fps = Frames / seconds; + printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); + fflush(stdout); + T0 = t; + Frames = 0; + } + } + } glutPostRedisplay(); } @@ -91,13 +109,13 @@ int main(int argc, char **argv) exit(1); } - glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); + glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300); type = GLUT_RGB | GLUT_ALPHA; type |= GLUT_DOUBLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/clear.c b/progs/trivial/clear.c index da4fff04590..37cfd54fbe2 100644 --- a/progs/trivial/clear.c +++ b/progs/trivial/clear.c @@ -113,7 +113,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/createwin.c b/progs/trivial/createwin.c index 901048555a9..44d5b1b2c5f 100644 --- a/progs/trivial/createwin.c +++ b/progs/trivial/createwin.c @@ -106,7 +106,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/dlist-dangling.c b/progs/trivial/dlist-dangling.c index 00a75078444..64054ec96c1 100644 --- a/progs/trivial/dlist-dangling.c +++ b/progs/trivial/dlist-dangling.c @@ -135,7 +135,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/dlist-edgeflag-dangling.c b/progs/trivial/dlist-edgeflag-dangling.c index 08fae549c31..1b66244cabf 100644 --- a/progs/trivial/dlist-edgeflag-dangling.c +++ b/progs/trivial/dlist-edgeflag-dangling.c @@ -140,7 +140,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/dlist-edgeflag.c b/progs/trivial/dlist-edgeflag.c index ae799dc3557..350100681e5 100644 --- a/progs/trivial/dlist-edgeflag.c +++ b/progs/trivial/dlist-edgeflag.c @@ -144,7 +144,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/draw2arrays.c b/progs/trivial/draw2arrays.c new file mode 100644 index 00000000000..95a89981d3a --- /dev/null +++ b/progs/trivial/draw2arrays.c @@ -0,0 +1,117 @@ +/* Basic VBO */ + +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glew.h> +#include <GL/glut.h> + +GLfloat pos[][3] = + { { 0.9, -0.9, 0.0 }, + { 0.9, 0.9, 0.0 }, + { -0.9, 0.9, 0.0 }, + { -0.9, -0.9, 0.0 } }; + +GLubyte color[][4] = +{ { 0x00, 0x00, 0xff, 0x00 }, + { 0x00, 0xff, 0x00, 0x00 }, + { 0xff, 0x00, 0x00, 0x00 }, + { 0xff, 0xff, 0xff, 0x00 } }; + +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 ); + + glVertexPointer( 3, GL_FLOAT, sizeof(pos[0]), pos ); + glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(color[0]), color ); + +} + + + +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 ); + + 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; +} diff --git a/progs/trivial/line-clip.c b/progs/trivial/line-clip.c index fd79d049c4f..bcee32e25fc 100644 --- a/progs/trivial/line-clip.c +++ b/progs/trivial/line-clip.c @@ -126,7 +126,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/line-cull.c b/progs/trivial/line-cull.c index 038004b4c4a..98218731304 100644 --- a/progs/trivial/line-cull.c +++ b/progs/trivial/line-cull.c @@ -122,7 +122,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/line-stipple-wide.c b/progs/trivial/line-stipple-wide.c index 09e5e1fe089..28d96c797b0 100644 --- a/progs/trivial/line-stipple-wide.c +++ b/progs/trivial/line-stipple-wide.c @@ -134,7 +134,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/line-userclip-clip.c b/progs/trivial/line-userclip-clip.c index 5c9c1b3b291..1b9f059729c 100644 --- a/progs/trivial/line-userclip-clip.c +++ b/progs/trivial/line-userclip-clip.c @@ -128,7 +128,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/line-userclip-nop-clip.c b/progs/trivial/line-userclip-nop-clip.c index a6ee44fbd0f..9f144a6e9a3 100644 --- a/progs/trivial/line-userclip-nop-clip.c +++ b/progs/trivial/line-userclip-nop-clip.c @@ -128,7 +128,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/line-userclip-nop.c b/progs/trivial/line-userclip-nop.c index cebea5f4812..7588faeb98f 100644 --- a/progs/trivial/line-userclip-nop.c +++ b/progs/trivial/line-userclip-nop.c @@ -128,7 +128,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/line-userclip.c b/progs/trivial/line-userclip.c index ecfd28cac71..77d8228188c 100644 --- a/progs/trivial/line-userclip.c +++ b/progs/trivial/line-userclip.c @@ -128,7 +128,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/line-wide.c b/progs/trivial/line-wide.c index 543b1f67f34..f20505378cb 100644 --- a/progs/trivial/line-wide.c +++ b/progs/trivial/line-wide.c @@ -133,7 +133,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/line.c b/progs/trivial/line.c index de5f9274e41..7ccbce3750a 100644 --- a/progs/trivial/line.c +++ b/progs/trivial/line.c @@ -131,7 +131,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/lineloop-clip.c b/progs/trivial/lineloop-clip.c index 211056720fe..fbeca985b90 100644 --- a/progs/trivial/lineloop-clip.c +++ b/progs/trivial/lineloop-clip.c @@ -122,7 +122,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/lineloop.c b/progs/trivial/lineloop.c index fab7d1ea022..5863df654b8 100644 --- a/progs/trivial/lineloop.c +++ b/progs/trivial/lineloop.c @@ -122,7 +122,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/linestrip-clip.c b/progs/trivial/linestrip-clip.c index acab0f4e1cf..dae27c31d44 100644 --- a/progs/trivial/linestrip-clip.c +++ b/progs/trivial/linestrip-clip.c @@ -127,7 +127,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/linestrip-flat-stipple.c b/progs/trivial/linestrip-flat-stipple.c index b691437346a..ee79f150194 100644 --- a/progs/trivial/linestrip-flat-stipple.c +++ b/progs/trivial/linestrip-flat-stipple.c @@ -128,7 +128,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/linestrip-stipple-wide.c b/progs/trivial/linestrip-stipple-wide.c index 53dfa554e98..c6307d59941 100644 --- a/progs/trivial/linestrip-stipple-wide.c +++ b/progs/trivial/linestrip-stipple-wide.c @@ -128,7 +128,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/linestrip-stipple.c b/progs/trivial/linestrip-stipple.c index 5933d1a136f..2b40b5f1b8e 100644 --- a/progs/trivial/linestrip-stipple.c +++ b/progs/trivial/linestrip-stipple.c @@ -127,7 +127,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/linestrip.c b/progs/trivial/linestrip.c index 06dd1c10872..865a752796c 100644 --- a/progs/trivial/linestrip.c +++ b/progs/trivial/linestrip.c @@ -124,7 +124,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/long-fixed-func.c b/progs/trivial/long-fixed-func.c index 41ad25c1b3d..f2a29a9d376 100644 --- a/progs/trivial/long-fixed-func.c +++ b/progs/trivial/long-fixed-func.c @@ -139,7 +139,7 @@ main(int argc, char **argv) glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); glutInitDisplayMode(type); - if (glutCreateWindow("tri-long-fixedfunc") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } glewInit(); diff --git a/progs/trivial/point-clip.c b/progs/trivial/point-clip.c index 7fec54e1db9..6aaee0d1a5f 100644 --- a/progs/trivial/point-clip.c +++ b/progs/trivial/point-clip.c @@ -124,7 +124,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/point-sprite.c b/progs/trivial/point-sprite.c index 583bdca1b71..2f8226ee273 100644 --- a/progs/trivial/point-sprite.c +++ b/progs/trivial/point-sprite.c @@ -160,7 +160,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/point-wide-smooth.c b/progs/trivial/point-wide-smooth.c index 55cbcaec70b..63f83badf8c 100644 --- a/progs/trivial/point-wide-smooth.c +++ b/progs/trivial/point-wide-smooth.c @@ -131,7 +131,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/point-wide.c b/progs/trivial/point-wide.c index 265b20097b1..725edae49ec 100644 --- a/progs/trivial/point-wide.c +++ b/progs/trivial/point-wide.c @@ -128,7 +128,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/point.c b/progs/trivial/point.c index 8dabfb6ca64..3c472c1b91e 100644 --- a/progs/trivial/point.c +++ b/progs/trivial/point.c @@ -124,7 +124,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/poly-flat-clip.c b/progs/trivial/poly-flat-clip.c index 72c2a29a0d2..d58a3a358f8 100644 --- a/progs/trivial/poly-flat-clip.c +++ b/progs/trivial/poly-flat-clip.c @@ -126,7 +126,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/poly-flat-unfilled-clip.c b/progs/trivial/poly-flat-unfilled-clip.c index d3a14a516a4..74249eb4999 100644 --- a/progs/trivial/poly-flat-unfilled-clip.c +++ b/progs/trivial/poly-flat-unfilled-clip.c @@ -130,7 +130,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/poly-flat.c b/progs/trivial/poly-flat.c index a847d6828a7..82098bc1bbc 100644 --- a/progs/trivial/poly-flat.c +++ b/progs/trivial/poly-flat.c @@ -126,7 +126,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/poly-unfilled.c b/progs/trivial/poly-unfilled.c index ae092a830ab..5cc8523f815 100644 --- a/progs/trivial/poly-unfilled.c +++ b/progs/trivial/poly-unfilled.c @@ -125,7 +125,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/poly.c b/progs/trivial/poly.c index 2f254de4815..8944f148d09 100644 --- a/progs/trivial/poly.c +++ b/progs/trivial/poly.c @@ -124,7 +124,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quad-clip-all-vertices.c b/progs/trivial/quad-clip-all-vertices.c index 3e0f3d94948..6559adf4af8 100644 --- a/progs/trivial/quad-clip-all-vertices.c +++ b/progs/trivial/quad-clip-all-vertices.c @@ -124,7 +124,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quad-clip-nearplane.c b/progs/trivial/quad-clip-nearplane.c index 1e8056c474b..0e4f4c947c3 100644 --- a/progs/trivial/quad-clip-nearplane.c +++ b/progs/trivial/quad-clip-nearplane.c @@ -137,7 +137,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quad-clip.c b/progs/trivial/quad-clip.c index 504fef3dc59..fd3522a89a2 100644 --- a/progs/trivial/quad-clip.c +++ b/progs/trivial/quad-clip.c @@ -124,7 +124,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quad-degenerate.c b/progs/trivial/quad-degenerate.c index 83047408573..29fb2774deb 100644 --- a/progs/trivial/quad-degenerate.c +++ b/progs/trivial/quad-degenerate.c @@ -129,7 +129,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quad-flat.c b/progs/trivial/quad-flat.c index bd8be7c43e3..570eb6bc715 100644 --- a/progs/trivial/quad-flat.c +++ b/progs/trivial/quad-flat.c @@ -134,7 +134,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quad-offset-factor.c b/progs/trivial/quad-offset-factor.c index 90943d908ff..2c4946a13a6 100644 --- a/progs/trivial/quad-offset-factor.c +++ b/progs/trivial/quad-offset-factor.c @@ -142,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) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quad-offset-unfilled.c b/progs/trivial/quad-offset-unfilled.c index 1ad44cdcaec..40762825bd1 100644 --- a/progs/trivial/quad-offset-unfilled.c +++ b/progs/trivial/quad-offset-unfilled.c @@ -155,7 +155,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quad-offset-units.c b/progs/trivial/quad-offset-units.c index d5db21469e6..b4b138b4b44 100644 --- a/progs/trivial/quad-offset-units.c +++ b/progs/trivial/quad-offset-units.c @@ -143,7 +143,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quad-tex-2d.c b/progs/trivial/quad-tex-2d.c index 97c9fc54d86..ed6f4a07330 100644 --- a/progs/trivial/quad-tex-2d.c +++ b/progs/trivial/quad-tex-2d.c @@ -173,7 +173,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - win = glutCreateWindow("First Tri"); + win = glutCreateWindow(*argv); if (!win) { exit(1); } diff --git a/progs/trivial/quad-tex-3d.c b/progs/trivial/quad-tex-3d.c index ca7ea91d2f3..84acb35fd82 100644 --- a/progs/trivial/quad-tex-3d.c +++ b/progs/trivial/quad-tex-3d.c @@ -164,7 +164,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quad-tex-alpha.c b/progs/trivial/quad-tex-alpha.c index cd73f013eb0..be24255a3e2 100644 --- a/progs/trivial/quad-tex-alpha.c +++ b/progs/trivial/quad-tex-alpha.c @@ -156,7 +156,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quad-tex-pbo.c b/progs/trivial/quad-tex-pbo.c index c6f60f51fa6..dcb4ae0e7f8 100644 --- a/progs/trivial/quad-tex-pbo.c +++ b/progs/trivial/quad-tex-pbo.c @@ -167,7 +167,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quad-tex-sub.c b/progs/trivial/quad-tex-sub.c new file mode 100644 index 00000000000..aabbb9edce9 --- /dev/null +++ b/progs/trivial/quad-tex-sub.c @@ -0,0 +1,203 @@ +/* + * 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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glew.h> +#include <GL/glut.h> + + +#define CI_OFFSET_1 16 +#define CI_OFFSET_2 32 + +#define SIZE 16 +GLenum doubleBuffer; +GLint line = 0; + +static void MakeImage() +{ + GLubyte tex2d[SIZE][SIZE][3]; + GLint s, t; + + for (s = 0; s < SIZE; s++) { + for (t = 0; t < SIZE; t++) { + tex2d[t][s][0] = s*255/(SIZE-1); + tex2d[t][s][1] = t*255/(SIZE-1); + tex2d[t][s][2] = 0*255/(SIZE-1); + } + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, + SIZE, SIZE, + 0, + GL_RGB, GL_UNSIGNED_BYTE, tex2d); + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + glEnable(GL_TEXTURE_2D); +} + +static void UpdateLine() +{ + GLubyte tex[SIZE][3]; + GLubyte b = 0; + GLint s, t; + + t = line % SIZE; + if (line % (SIZE * 2) < SIZE) + b = 255; + else + b = 0; + + for (s = 0; s < SIZE; s++) { + tex[s][0] = s*255/(SIZE-1); + tex[s][1] = t*255/(SIZE-1); + tex[s][2] = b; + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexSubImage2D(GL_TEXTURE_2D, 0, + 0, t, + SIZE, 1, + GL_RGB, GL_UNSIGNED_BYTE, tex); + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); +} + +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); + + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + MakeImage(); + UpdateLine(); + line++; +} + +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: + UpdateLine(); + line++; + break; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_QUADS); + glTexCoord2f(1,0); + glVertex3f( 0.9, -0.9, -30.0); + glTexCoord2f(1,1); + glVertex3f( 0.9, 0.9, -30.0); + glTexCoord2f(0,1); + glVertex3f(-0.9, 0.9, -30.0); + glTexCoord2f(0,0); + 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 | 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; +} diff --git a/progs/trivial/quad-unfilled-clip.c b/progs/trivial/quad-unfilled-clip.c index e298bd455bf..e25a34bda85 100644 --- a/progs/trivial/quad-unfilled-clip.c +++ b/progs/trivial/quad-unfilled-clip.c @@ -125,7 +125,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quad-unfilled-stipple.c b/progs/trivial/quad-unfilled-stipple.c index 2036aacbaab..d33e5918bce 100644 --- a/progs/trivial/quad-unfilled-stipple.c +++ b/progs/trivial/quad-unfilled-stipple.c @@ -128,7 +128,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quad-unfilled.c b/progs/trivial/quad-unfilled.c index 9d0087ce08d..b60af3e7f56 100644 --- a/progs/trivial/quad-unfilled.c +++ b/progs/trivial/quad-unfilled.c @@ -125,7 +125,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quad.c b/progs/trivial/quad.c index 85424b7b388..c4773ec7dab 100644 --- a/progs/trivial/quad.c +++ b/progs/trivial/quad.c @@ -124,7 +124,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quads.c b/progs/trivial/quads.c index 307a9e07209..5bc622144ed 100644 --- a/progs/trivial/quads.c +++ b/progs/trivial/quads.c @@ -142,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) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quadstrip-clip.c b/progs/trivial/quadstrip-clip.c new file mode 100644 index 00000000000..82a6d4e0769 --- /dev/null +++ b/progs/trivial/quadstrip-clip.c @@ -0,0 +1,137 @@ +/* + * 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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + +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)); + + 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); + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glBegin(GL_QUAD_STRIP); + glColor3f(1,1,1); + glVertex3f( 1.9, -0.9, -30.0); + glVertex3f( 0.9, 0.9, -30.0); + + glColor3f(1,0,0); + glVertex3f( 0.1, -0.8, -30.0); + glVertex3f( 0.1, 0.8, -30.0); + + glColor3f(0,1,0); + glVertex3f(-0.1, -0.9, -30.0); + glVertex3f(-0.1, 0.9, -30.0); + + glColor3f(0,0,0); + glVertex3f(-0.9, -0.8, -30.0); + glVertex3f(-0.9, 0.8, -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 | GLUT_ALPHA; + 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; +} diff --git a/progs/trivial/quadstrip-cont.c b/progs/trivial/quadstrip-cont.c index c6c8f69f8ca..62208dfae75 100644 --- a/progs/trivial/quadstrip-cont.c +++ b/progs/trivial/quadstrip-cont.c @@ -147,7 +147,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quadstrip-flat.c b/progs/trivial/quadstrip-flat.c index d02135f702a..9011ee0873f 100644 --- a/progs/trivial/quadstrip-flat.c +++ b/progs/trivial/quadstrip-flat.c @@ -136,7 +136,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/quadstrip.c b/progs/trivial/quadstrip.c index ff8644be09e..6923afc04b5 100644 --- a/progs/trivial/quadstrip.c +++ b/progs/trivial/quadstrip.c @@ -130,7 +130,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-alpha-tex.c b/progs/trivial/tri-alpha-tex.c index 776f39dcc35..382d7b21029 100644 --- a/progs/trivial/tri-alpha-tex.c +++ b/progs/trivial/tri-alpha-tex.c @@ -165,7 +165,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-alpha.c b/progs/trivial/tri-alpha.c index 90cfdbe199d..1a653713bbf 100644 --- a/progs/trivial/tri-alpha.c +++ b/progs/trivial/tri-alpha.c @@ -127,7 +127,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-blend-color.c b/progs/trivial/tri-blend-color.c index d2d72d0b62f..db831e3d6e0 100644 --- a/progs/trivial/tri-blend-color.c +++ b/progs/trivial/tri-blend-color.c @@ -128,7 +128,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-clear.c b/progs/trivial/tri-clear.c index 25ea77cfa75..a3908e38e9d 100644 --- a/progs/trivial/tri-clear.c +++ b/progs/trivial/tri-clear.c @@ -129,7 +129,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-clip.c b/progs/trivial/tri-clip.c index f30445cdba1..0d31086c855 100644 --- a/progs/trivial/tri-clip.c +++ b/progs/trivial/tri-clip.c @@ -143,7 +143,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-cull-both.c b/progs/trivial/tri-cull-both.c index 51b5865ae5c..73c5583cfdd 100644 --- a/progs/trivial/tri-cull-both.c +++ b/progs/trivial/tri-cull-both.c @@ -127,7 +127,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-cull.c b/progs/trivial/tri-cull.c index 2eead841155..c6bcf444e42 100644 --- a/progs/trivial/tri-cull.c +++ b/progs/trivial/tri-cull.c @@ -158,7 +158,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-dlist.c b/progs/trivial/tri-dlist.c index c21c4714adf..1c0e320f61a 100644 --- a/progs/trivial/tri-dlist.c +++ b/progs/trivial/tri-dlist.c @@ -136,7 +136,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-edgeflag.c b/progs/trivial/tri-edgeflag.c index 41899c2eb4f..e1278dd6490 100644 --- a/progs/trivial/tri-edgeflag.c +++ b/progs/trivial/tri-edgeflag.c @@ -123,7 +123,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-fbo-tex-mip.c b/progs/trivial/tri-fbo-tex-mip.c new file mode 100644 index 00000000000..07443695011 --- /dev/null +++ b/progs/trivial/tri-fbo-tex-mip.c @@ -0,0 +1,261 @@ +/* Framebuffer object test */ + + +#include <GL/glew.h> +#include <GL/glut.h> +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +/* For debug */ + + +static int Win = 0; +static int Width = 512, Height = 512; + +static GLenum TexTarget = GL_TEXTURE_2D; +static int TexWidth = 512, TexHeight = 512; + +static GLuint MyFB; +static GLuint TexObj; +static GLboolean Anim = GL_FALSE; +static GLfloat Rot = 0.0; +static GLuint TextureLevel = 4; /* which texture level to render to */ +static GLenum TexIntFormat = GL_RGB; /* either GL_RGB or GL_RGBA */ + + +static void +CheckError(int line) +{ + GLenum err = glGetError(); + if (err) { + printf("GL Error 0x%x at line %d\n", (int) err, line); + } +} + + +static void +Idle(void) +{ + Rot = glutGet(GLUT_ELAPSED_TIME) * 0.1; + glutPostRedisplay(); +} + + +static void +RenderTexture(void) +{ + GLenum status; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -15.0); + + if (1) { + /* draw to texture image */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); + + status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + printf("Framebuffer incomplete!!!\n"); + } + + glViewport(0, 0, + TexWidth / (1 << TextureLevel), + TexHeight / (1 << TextureLevel)); + glClearColor(0.5, 0.5, 1.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + CheckError(__LINE__); + + glBegin(GL_POLYGON); + glColor3f(1, 0, 0); + glVertex2f(-1, -1); + glColor3f(0, 1, 0); + glVertex2f(1, -1); + glColor3f(0, 0, 1); + glVertex2f(0, 1); + glEnd(); + + /* Bind normal framebuffer */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + } + else { + } + + CheckError(__LINE__); +} + + + +static void +Display(void) +{ + float ar = (float) Width / (float) Height; + + RenderTexture(); + + /* draw textured quad in the window */ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-ar, ar, -1.0, 1.0, 5.0, 25.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -7.0); + + glViewport(0, 0, Width, Height); + + glClearColor(0.25, 0.25, 0.25, 0); + glClear(GL_COLOR_BUFFER_BIT); + + glPushMatrix(); + glRotatef(Rot, 0, 1, 0); + glEnable(TexTarget); + glBindTexture(TexTarget, TexObj); + + { + glBegin(GL_POLYGON); + glColor3f(0.25, 0.25, 0.25); + glTexCoord2f(0, 0); + glVertex2f(-1, -1); + glTexCoord2f(1, 0); + glVertex2f(1, -1); + glColor3f(1.0, 1.0, 1.0); + glTexCoord2f(1, 1); + glVertex2f(1, 1); + glTexCoord2f(0, 1); + glVertex2f(-1, 1); + glEnd(); + } + + glPopMatrix(); + glDisable(TexTarget); + + glutSwapBuffers(); + CheckError(__LINE__); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + Width = width; + Height = height; +} + + +static void +CleanUp(void) +{ + glDeleteFramebuffersEXT(1, &MyFB); + + glDeleteTextures(1, &TexObj); + + glutDestroyWindow(Win); + + exit(0); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case 'a': + Anim = !Anim; + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + case 's': + Rot += 2.0; + break; + case 27: + CleanUp(); + break; + } + glutPostRedisplay(); +} + + +static void +Init(int argc, char *argv[]) +{ + if (!glutExtensionSupported("GL_EXT_framebuffer_object")) { + printf("GL_EXT_framebuffer_object not found!\n"); + exit(0); + } + + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + + + /* Make texture object/image */ + glGenTextures(1, &TexObj); + glBindTexture(TexTarget, TexObj); + glTexParameteri(TexTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(TexTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(TexTarget, GL_TEXTURE_BASE_LEVEL, TextureLevel); + glTexParameteri(TexTarget, GL_TEXTURE_MAX_LEVEL, TextureLevel); + + glTexImage2D(TexTarget, 0, TexIntFormat, TexWidth, TexHeight, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(TexTarget, TextureLevel, TexIntFormat, + TexWidth / (1 << TextureLevel), TexHeight / (1 << TextureLevel), 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + + + + /* gen framebuffer id, delete it, do some assertions, just for testing */ + glGenFramebuffersEXT(1, &MyFB); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); + assert(glIsFramebufferEXT(MyFB)); + + + CheckError(__LINE__); + + /* Render color to texture */ + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, + TexTarget, TexObj, TextureLevel); + + + + CheckError(__LINE__); + + /* bind regular framebuffer */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + + +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowPosition(0, 0); + glutInitWindowSize(Width, Height); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + Win = glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Display); + if (Anim) + glutIdleFunc(Idle); + Init(argc, argv); + glutMainLoop(); + return 0; +} diff --git a/progs/trivial/tri-fbo-tex.c b/progs/trivial/tri-fbo-tex.c index 253f9310db4..72b4cf3683d 100644 --- a/progs/trivial/tri-fbo-tex.c +++ b/progs/trivial/tri-fbo-tex.c @@ -1,12 +1,4 @@ -/* - * Test GL_EXT_framebuffer_object render-to-texture - * - * Draw a teapot into a texture image with stenciling. - * Then draw a textured quad using that texture. - * - * Brian Paul - * 18 Apr 2005 - */ +/* Framebuffer object test */ #include <GL/glew.h> diff --git a/progs/trivial/tri-flat-clip.c b/progs/trivial/tri-flat-clip.c index 155b0c4f8d4..3235100385c 100644 --- a/progs/trivial/tri-flat-clip.c +++ b/progs/trivial/tri-flat-clip.c @@ -123,7 +123,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-flat.c b/progs/trivial/tri-flat.c index 0583a2a99a1..a7fdaa1f469 100644 --- a/progs/trivial/tri-flat.c +++ b/progs/trivial/tri-flat.c @@ -123,7 +123,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-fog.c b/progs/trivial/tri-fog.c index 75f3262ecf4..0099a90ad6c 100644 --- a/progs/trivial/tri-fog.c +++ b/progs/trivial/tri-fog.c @@ -42,6 +42,15 @@ static void Init(void) fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); glClearColor(0.0, 0.0, 1.0, 0.0); + + glEnable(GL_FOG); + glFogi(GL_FOG_MODE, GL_LINEAR); + glFogf(GL_FOG_START, 25); + glFogf(GL_FOG_END, 35); +#if 0 + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable (GL_BLEND); +#endif } static void Reshape(int width, int height) @@ -70,26 +79,26 @@ static void Key(unsigned char key, int x, int y) static void Draw(void) { - glClear(GL_COLOR_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_FOG); glBegin(GL_TRIANGLES); - glColor3f(0,0,.7); + glColor3f(1,1,1); glVertex3f( 0.9, -0.9, -30.0); - glColor3f(.8,0,0); + glColor3f(1,1,1); glVertex3f( 0.9, 0.9, -30.0); - glColor3f(0,.9,0); - glVertex3f(-0.9, 0.0, -30.0); + glColor3f(1,1,1); + glVertex3f(-0.9, 0.0, -40.0); glEnd(); #if 0 glBegin(GL_TRIANGLES); - glColor3f(0,0,.7); + glColor3f(0,0,.7); glVertex3f(-0.9, -0.9, -30.0); - glColor3f(.8,0,0); + glColor3f(.8,0,0); glVertex3f(-0.9, 0.9, -30.0); - glColor3f(0,.9,0); + glColor3f(0,.9,0); glVertex3f( 0.9, 0.0, -30.0); glEnd(); #endif @@ -138,7 +147,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-fp-const-imm.c b/progs/trivial/tri-fp-const-imm.c index 9e2c63a22af..2b1499903c1 100644 --- a/progs/trivial/tri-fp-const-imm.c +++ b/progs/trivial/tri-fp-const-imm.c @@ -155,7 +155,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-fp.c b/progs/trivial/tri-fp.c index fcf57f5a85f..b30f9b73e0f 100644 --- a/progs/trivial/tri-fp.c +++ b/progs/trivial/tri-fp.c @@ -153,7 +153,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-lit.c b/progs/trivial/tri-lit.c index 22f199c9828..91fac1a5981 100644 --- a/progs/trivial/tri-lit.c +++ b/progs/trivial/tri-lit.c @@ -125,7 +125,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-logicop-none.c b/progs/trivial/tri-logicop-none.c new file mode 100644 index 00000000000..aba3614bf68 --- /dev/null +++ b/progs/trivial/tri-logicop-none.c @@ -0,0 +1,178 @@ +/* + * 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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#define CI_OFFSET_1 16 +#define CI_OFFSET_2 32 + + +GLenum doubleBuffer = 1; +int win; + +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.3, 0.1, 0.3, 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(0); + default: + glutPostRedisplay(); + return; + } +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + 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); + glEnd(); + + + glLineWidth(4.0); + + glBegin(GL_LINES); + glColor3f(.1,.7,.1); + glVertex3f( 0.5, -0.5, -30.0); + glVertex3f( 0.5, 0.5, -30.0); + + glColor3f(.1,.1,.8); + glVertex3f( 0.5, 0.5, -30.0); + glVertex3f(-0.5, 0.5, -30.0); + + glColor3f(.5,.1,.1); + glVertex3f(-0.5, 0.5, -30.0); + glVertex3f(-0.5, -0.5, -30.0); + + glColor3f(.8,.8,.8); + glVertex3f(-0.5, -0.5, -30.0); + glVertex3f( 0.5, -0.5, -30.0); + glEnd(); + +// glLineWidth(12.0); + + /* Redraw parts of the lines: + */ + glBegin(GL_LINES); + glColor3f(.1,.7,.1); + glVertex3f( 0.5, -0.2, -30.0); + glVertex3f( 0.5, 0.2, -30.0); + + glColor3f(.1,.1,.8); + glVertex3f( 0.2, 0.5, -30.0); + glVertex3f(-0.2, 0.5, -30.0); + + glColor3f(.5,.1,.1); + glVertex3f(-0.5, 0.2, -30.0); + glVertex3f(-0.5, -0.2, -30.0); + + glColor3f(.8,.8,.8); + glVertex3f(-0.2, -0.5, -30.0); + glVertex3f( 0.2, -0.5, -30.0); + glEnd(); + + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + 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); + + win = glutCreateWindow(*argv); + if (!win) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/trivial/tri-logicop-xor.c b/progs/trivial/tri-logicop-xor.c new file mode 100644 index 00000000000..e2c94f9bee7 --- /dev/null +++ b/progs/trivial/tri-logicop-xor.c @@ -0,0 +1,186 @@ +/* + * 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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#define CI_OFFSET_1 16 +#define CI_OFFSET_2 32 + + +GLenum doubleBuffer = 1; +int win; + +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.3, 0.1, 0.3, 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(0); + default: + glutPostRedisplay(); + return; + } +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + 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); + glEnd(); + + + glLineWidth(4.0); + + glEnable(GL_BLEND); + glEnable(GL_COLOR_LOGIC_OP); + glLogicOp(GL_XOR); + + glBegin(GL_LINES); + glColor3f(.1,.7,.1); + glVertex3f( 0.5, -0.5, -30.0); + glVertex3f( 0.5, 0.5, -30.0); + + glColor3f(.1,.1,.8); + glVertex3f( 0.5, 0.5, -30.0); + glVertex3f(-0.5, 0.5, -30.0); + + glColor3f(.5,.1,.1); + glVertex3f(-0.5, 0.5, -30.0); + glVertex3f(-0.5, -0.5, -30.0); + + glColor3f(.8,.8,.8); + glVertex3f(-0.5, -0.5, -30.0); + glVertex3f( 0.5, -0.5, -30.0); + glEnd(); + +// glLineWidth(12.0); + + /* Redraw parts of the lines to remove them: + */ + glBegin(GL_LINES); + glColor3f(.1,.7,.1); + glVertex3f( 0.5, -0.2, -30.0); + glVertex3f( 0.5, 0.2, -30.0); + + glColor3f(.1,.1,.8); + glVertex3f( 0.2, 0.5, -30.0); + glVertex3f(-0.2, 0.5, -30.0); + + glColor3f(.5,.1,.1); + glVertex3f(-0.5, 0.2, -30.0); + glVertex3f(-0.5, -0.2, -30.0); + + glColor3f(.8,.8,.8); + glVertex3f(-0.2, -0.5, -30.0); + glVertex3f( 0.2, -0.5, -30.0); + glEnd(); + + + + glDisable(GL_COLOR_LOGIC_OP); + glDisable(GL_BLEND); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + 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); + + win = glutCreateWindow(*argv); + if (!win) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/trivial/tri-mask-tri.c b/progs/trivial/tri-mask-tri.c index 8333f7ed8ab..449125a4db7 100644 --- a/progs/trivial/tri-mask-tri.c +++ b/progs/trivial/tri-mask-tri.c @@ -143,7 +143,7 @@ int main(int argc, char **argv) glutInitWindowPosition(100, 0); glutInitWindowSize(Width, Height); glutInitDisplayMode(type); - Win = glutCreateWindow("First Tri"); + Win = glutCreateWindow(*argv); Init(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); diff --git a/progs/trivial/tri-orig.c b/progs/trivial/tri-orig.c index d5e6742ce1a..6861ff6e492 100644 --- a/progs/trivial/tri-orig.c +++ b/progs/trivial/tri-orig.c @@ -122,7 +122,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-query.c b/progs/trivial/tri-query.c index 25cfcb8e148..9b319ba2a7d 100644 --- a/progs/trivial/tri-query.c +++ b/progs/trivial/tri-query.c @@ -144,7 +144,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-repeat.c b/progs/trivial/tri-repeat.c index e894269e84b..a271fab54cc 100644 --- a/progs/trivial/tri-repeat.c +++ b/progs/trivial/tri-repeat.c @@ -104,7 +104,7 @@ int main(int argc, char **argv) type |= GLUT_DOUBLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-scissor-tri.c b/progs/trivial/tri-scissor-tri.c index dcc6d282dc2..2b5536ecd65 100644 --- a/progs/trivial/tri-scissor-tri.c +++ b/progs/trivial/tri-scissor-tri.c @@ -137,7 +137,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-square.c b/progs/trivial/tri-square.c index ef9ea63048f..9102888abd0 100644 --- a/progs/trivial/tri-square.c +++ b/progs/trivial/tri-square.c @@ -122,7 +122,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-stencil.c b/progs/trivial/tri-stencil.c index 7686e16aef1..9f68bca9149 100644 --- a/progs/trivial/tri-stencil.c +++ b/progs/trivial/tri-stencil.c @@ -144,7 +144,7 @@ int main(int argc, char **argv) type = GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH | GLUT_STENCIL; glutInitDisplayMode(type); - if (glutCreateWindow("Stencil Test") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-stipple.c b/progs/trivial/tri-stipple.c index 887de550e2c..33e6dd16a7e 100644 --- a/progs/trivial/tri-stipple.c +++ b/progs/trivial/tri-stipple.c @@ -137,7 +137,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-tex-3d.c b/progs/trivial/tri-tex-3d.c index 50f6a754189..4f276af653f 100644 --- a/progs/trivial/tri-tex-3d.c +++ b/progs/trivial/tri-tex-3d.c @@ -157,7 +157,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-tex.c b/progs/trivial/tri-tex.c index a0d75b4a331..1dbbe6aa586 100644 --- a/progs/trivial/tri-tex.c +++ b/progs/trivial/tri-tex.c @@ -154,7 +154,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-tri.c b/progs/trivial/tri-tri.c index 06a0528eb87..8b0c2dafefe 100644 --- a/progs/trivial/tri-tri.c +++ b/progs/trivial/tri-tri.c @@ -131,7 +131,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-unfilled-clip.c b/progs/trivial/tri-unfilled-clip.c index df161df3fb8..438899dc1a0 100644 --- a/progs/trivial/tri-unfilled-clip.c +++ b/progs/trivial/tri-unfilled-clip.c @@ -123,7 +123,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-unfilled-edgeflag.c b/progs/trivial/tri-unfilled-edgeflag.c index 31f41f6220b..78c5ae8e9cd 100644 --- a/progs/trivial/tri-unfilled-edgeflag.c +++ b/progs/trivial/tri-unfilled-edgeflag.c @@ -127,7 +127,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-unfilled-fog.c b/progs/trivial/tri-unfilled-fog.c new file mode 100644 index 00000000000..113b8d051df --- /dev/null +++ b/progs/trivial/tri-unfilled-fog.c @@ -0,0 +1,152 @@ +/* + * 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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#define CI_OFFSET_1 16 +#define CI_OFFSET_2 32 + +GLint Width = 250, Height = 250; + +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)); + + 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); + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glEnable(GL_FOG); + + glPolygonMode(GL_FRONT, GL_FILL); + glPolygonMode(GL_BACK, GL_FILL); + + glBegin(GL_TRIANGLES); + glColor3f(0,0,.7); + glVertex3f( 0.7, -0.7, -30.0); + glColor3f(.8,0,0); + glVertex3f( 0.7, 0.7, -30.0); + glColor3f(0,.9,0); + glVertex3f(-0.7, 0.0, -30.0); + glEnd(); + + glPolygonMode(GL_FRONT, GL_LINE); + glPolygonMode(GL_BACK, GL_LINE); + + glBegin(GL_TRIANGLES); + glColor3f(0,0,.7); + 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); + glEnd(); + + glDisable(GL_FOG); + + 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(100, 0); glutInitWindowSize(Width, Height); + + 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; +} diff --git a/progs/trivial/tri-unfilled-point.c b/progs/trivial/tri-unfilled-point.c index 71ac453d603..b0502801552 100644 --- a/progs/trivial/tri-unfilled-point.c +++ b/progs/trivial/tri-unfilled-point.c @@ -124,7 +124,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-unfilled-smooth.c b/progs/trivial/tri-unfilled-smooth.c index f70c1cd9d4d..9306af849a4 100644 --- a/progs/trivial/tri-unfilled-smooth.c +++ b/progs/trivial/tri-unfilled-smooth.c @@ -136,7 +136,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-unfilled-tri-lit.c b/progs/trivial/tri-unfilled-tri-lit.c index f9e1d009884..775c3530b7e 100644 --- a/progs/trivial/tri-unfilled-tri-lit.c +++ b/progs/trivial/tri-unfilled-tri-lit.c @@ -164,7 +164,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-unfilled-tri.c b/progs/trivial/tri-unfilled-tri.c index d9a9faeb9f5..ce789255fd9 100644 --- a/progs/trivial/tri-unfilled-tri.c +++ b/progs/trivial/tri-unfilled-tri.c @@ -161,7 +161,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-unfilled-userclip-stip.c b/progs/trivial/tri-unfilled-userclip-stip.c index 4aefa85032f..6835b53c0f5 100644 --- a/progs/trivial/tri-unfilled-userclip-stip.c +++ b/progs/trivial/tri-unfilled-userclip-stip.c @@ -133,7 +133,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-unfilled-userclip.c b/progs/trivial/tri-unfilled-userclip.c index 9201f9d433c..aab5abc2303 100644 --- a/progs/trivial/tri-unfilled-userclip.c +++ b/progs/trivial/tri-unfilled-userclip.c @@ -127,7 +127,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-unfilled.c b/progs/trivial/tri-unfilled.c index 1e44823db5a..4f50d083c2d 100644 --- a/progs/trivial/tri-unfilled.c +++ b/progs/trivial/tri-unfilled.c @@ -124,7 +124,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-userclip.c b/progs/trivial/tri-userclip.c index ccf631dff80..43d19cebab5 100644 --- a/progs/trivial/tri-userclip.c +++ b/progs/trivial/tri-userclip.c @@ -126,7 +126,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-viewport.c b/progs/trivial/tri-viewport.c new file mode 100644 index 00000000000..3205b9ee9c3 --- /dev/null +++ b/progs/trivial/tri-viewport.c @@ -0,0 +1,129 @@ +/* + * 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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + +GLenum doubleBuffer = 1; +int win; + +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.3, 0.1, 0.3, 0.0); +} + +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(); +} + +static void Key(unsigned char key, int x, int y) +{ + switch (key) { + case 27: + exit(0); + default: + glutPostRedisplay(); + return; + } +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + 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); + glEnd(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + 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); + + win = glutCreateWindow(*argv); + if (!win) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/trivial/tri-z-9.c b/progs/trivial/tri-z-9.c index 4bd99861660..e7d4184bdb0 100644 --- a/progs/trivial/tri-z-9.c +++ b/progs/trivial/tri-z-9.c @@ -125,7 +125,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri-z-eq.c b/progs/trivial/tri-z-eq.c index ad5f31a5588..4ec55ac080a 100644 --- a/progs/trivial/tri-z-eq.c +++ b/progs/trivial/tri-z-eq.c @@ -125,7 +125,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tri.c b/progs/trivial/tri.c index d3c6b59ea5d..d99d5872a90 100644 --- a/progs/trivial/tri.c +++ b/progs/trivial/tri.c @@ -41,28 +41,28 @@ 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.3, 0.1, 0.3, 0.0); + glClearColor(0.3, 0.1, 0.3, 0.0); } static void Reshape(int width, int height) { - glViewport(0, 0, (GLint)width, (GLint)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); + 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(0); - default: - glutPostRedisplay(); - return; + case 27: + exit(0); + default: + glutPostRedisplay(); + return; } } @@ -88,47 +88,47 @@ static void Draw(void) static GLenum Args(int argc, char **argv) { - GLint i; - - 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; + GLint i; + + 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; + GLenum type; - glutInit(&argc, argv); + glutInit(&argc, argv); - if (Args(argc, argv) == GL_FALSE) { - exit(1); - } + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } - glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); + glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); - type = GLUT_RGB | GLUT_ALPHA; - type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; - glutInitDisplayMode(type); + type = GLUT_RGB | GLUT_ALPHA; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); - win = glutCreateWindow("First Tri"); - if (!win) { - exit(1); - } + win = glutCreateWindow(*argv); + if (!win) { + exit(1); + } - Init(); + Init(); - glutReshapeFunc(Reshape); - glutKeyboardFunc(Key); - glutDisplayFunc(Draw); - glutMainLoop(); - return 0; + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; } diff --git a/progs/trivial/trifan-flat-clip.c b/progs/trivial/trifan-flat-clip.c index 04042fac704..ec7a50a75e0 100644 --- a/progs/trivial/trifan-flat-clip.c +++ b/progs/trivial/trifan-flat-clip.c @@ -126,7 +126,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/trifan-flat-unfilled-clip.c b/progs/trivial/trifan-flat-unfilled-clip.c index 25224412cc9..4887b5a30c5 100644 --- a/progs/trivial/trifan-flat-unfilled-clip.c +++ b/progs/trivial/trifan-flat-unfilled-clip.c @@ -130,7 +130,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/trifan-flat.c b/progs/trivial/trifan-flat.c index 737eccdcae7..cf75d4cf08f 100644 --- a/progs/trivial/trifan-flat.c +++ b/progs/trivial/trifan-flat.c @@ -126,7 +126,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/trifan-unfilled.c b/progs/trivial/trifan-unfilled.c index 8e7454108c0..491fe5b3df2 100644 --- a/progs/trivial/trifan-unfilled.c +++ b/progs/trivial/trifan-unfilled.c @@ -125,7 +125,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/trifan.c b/progs/trivial/trifan.c index ecb0424393e..ee9854dc94a 100644 --- a/progs/trivial/trifan.c +++ b/progs/trivial/trifan.c @@ -124,7 +124,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tristrip-clip.c b/progs/trivial/tristrip-clip.c index f95c66a62aa..eeab676ea90 100644 --- a/progs/trivial/tristrip-clip.c +++ b/progs/trivial/tristrip-clip.c @@ -124,7 +124,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tristrip-flat.c b/progs/trivial/tristrip-flat.c index e048233e67c..49bb432b9df 100644 --- a/progs/trivial/tristrip-flat.c +++ b/progs/trivial/tristrip-flat.c @@ -134,7 +134,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/tristrip.c b/progs/trivial/tristrip.c index 51ea4f23251..023e6475c0d 100644 --- a/progs/trivial/tristrip.c +++ b/progs/trivial/tristrip.c @@ -124,7 +124,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/vp-tri-cb-pos.c b/progs/trivial/vp-tri-cb-pos.c index 430a4d3964c..42bf9806b19 100644 --- a/progs/trivial/vp-tri-cb-pos.c +++ b/progs/trivial/vp-tri-cb-pos.c @@ -142,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) == GL_FALSE) { exit(1); } diff --git a/progs/trivial/vp-tri-cb-tex.c b/progs/trivial/vp-tri-cb-tex.c index 57fd2cdbbd1..8290226675e 100644 --- a/progs/trivial/vp-tri-cb-tex.c +++ b/progs/trivial/vp-tri-cb-tex.c @@ -175,7 +175,7 @@ int main(int argc, char **argv) type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(type); - if (glutCreateWindow("First Tri") == GL_FALSE) { + if (glutCreateWindow(*argv) == GL_FALSE) { exit(1); } diff --git a/progs/util/readtex.c b/progs/util/readtex.c index 37d5fcd0d3a..8e923b6eb47 100644 --- a/progs/util/readtex.c +++ b/progs/util/readtex.c @@ -102,9 +102,15 @@ static rawImageRec *RawImageOpen(const char *fileName) fprintf(stderr, "Out of memory!\n"); return NULL; } - if ((raw->file = fopen(fileName, "rb")) == NULL) { - perror(fileName); - return NULL; + raw->file = fopen(fileName, "rb"); + if (raw->file == NULL) { + const char *baseName = strrchr(fileName, '/'); + if(baseName) + raw->file = fopen(baseName + 1, "rb"); + if(raw->file == NULL) { + perror(fileName); + return NULL; + } } fread(raw, 1, 12, raw->file); diff --git a/progs/vp/addimm.txt b/progs/vp/addimm.txt new file mode 100644 index 00000000000..f5796d78100 --- /dev/null +++ b/progs/vp/addimm.txt @@ -0,0 +1,5 @@ +!!ARBvp1.0 +TEMP R0; +ADD result.color, vertex.color, {.5}.x; +MOV result.position, vertex.position; +END diff --git a/progs/vp/arl-static.txt b/progs/vp/arl-static.txt new file mode 100644 index 00000000000..aea87b79a49 --- /dev/null +++ b/progs/vp/arl-static.txt @@ -0,0 +1,7 @@ +!!ARBvp1.0 +PARAM arr[5] = { {.0,.1,.2,.3}, {.4,.5,.6,.7}, {.8,.9,.10,.1}, {.12,.3,.4,.14}, {.5,.8,.1,.9}, {.2,0,.4,.1}, {.6,.1,.8,.9}}; +ADDRESS addr; +ARL addr.x, {3}.x; +MOV result.color, arr[addr.x]; +MOV result.position, vertex.position; +END diff --git a/progs/vp/arl-unused.txt b/progs/vp/arl-unused.txt new file mode 100644 index 00000000000..7bdbb8e86c7 --- /dev/null +++ b/progs/vp/arl-unused.txt @@ -0,0 +1,7 @@ +!!ARBvp1.0 +PARAM arr[5] = { {.0,.1,.2,.3}, {.4,.5,.6,.7}, {.8,.9,.10,.1}, {.12,.3,.4,.14}, {.5,.8,.1,.9}, {.2,0,.4,.1}, {.6,.1,.8,.9}}; +ADDRESS addr; +ARL addr.x, {3}.x; # not actually used +MOV result.color, arr[3]; +MOV result.position, vertex.position; +END diff --git a/progs/vp/exp-no-w.txt b/progs/vp/exp-no-w.txt new file mode 100644 index 00000000000..98ed4b7a981 --- /dev/null +++ b/progs/vp/exp-no-w.txt @@ -0,0 +1,6 @@ +!!ARBvp1.0 +TEMP R0; +EXP R0, vertex.color.x; +SUB result.color, R0.z, {1.0}.x; +MOV result.position, vertex.position; +END diff --git a/progs/vp/msk.txt b/progs/vp/msk.txt new file mode 100644 index 00000000000..9e925aca11e --- /dev/null +++ b/progs/vp/msk.txt @@ -0,0 +1,7 @@ +!!ARBvp1.0 +TEMP R0; +MOV R0.xz, vertex.color; +MOV R0.yw, {0.5}.x; +MOV result.color, R0; +MOV result.position, vertex.position; +END diff --git a/progs/vp/psiz-mul.txt b/progs/vp/psiz-mul.txt new file mode 100644 index 00000000000..a74df66de29 --- /dev/null +++ b/progs/vp/psiz-mul.txt @@ -0,0 +1,6 @@ +!!ARBvp1.0 +MOV result.color, vertex.color; +MUL result.pointsize, vertex.color.x, {10.0}.x; +MOV result.position, vertex.position; +END + diff --git a/progs/vp/vp-tris.c b/progs/vp/vp-tris.c index 87cb12b9846..97995accdd1 100644 --- a/progs/vp/vp-tris.c +++ b/progs/vp/vp-tris.c @@ -16,6 +16,10 @@ static const char *filename = NULL; static GLuint nr_steps = 4; +static GLuint prim = GL_TRIANGLES; +static GLfloat psz = 1.0; +static GLboolean pointsmooth = 0; +static GLboolean program_point_size = 0; static void usage( char *name ) { @@ -186,6 +190,14 @@ static void subdiv( union vert *v0, } } +static void enable( GLenum value, GLboolean flag ) +{ + if (flag) + glEnable(value); + else + glDisable(value); +} + /** Assignment */ #define ASSIGN_3V( V, V0, V1, V2 ) \ do { \ @@ -198,8 +210,12 @@ static void Display( void ) { glClearColor(0.3, 0.3, 0.3, 1); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + glPointSize(psz); + + enable( GL_POINT_SMOOTH, pointsmooth ); + enable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB, program_point_size ); - glBegin(GL_TRIANGLES); + glBegin(prim); { @@ -243,9 +259,40 @@ static void Key( unsigned char key, int x, int y ) (void) x; (void) y; switch (key) { - case 27: - exit(0); - break; + case 'p': + prim = GL_POINTS; + break; + case 't': + prim = GL_TRIANGLES; + break; + case 's': + psz += .5; + break; + case 'S': + if (psz > .5) + psz -= .5; + break; + case 'm': + pointsmooth = !pointsmooth; + break; + case 'z': + program_point_size = !program_point_size; + break; + case '+': + nr_steps++; + break; + case '-': + if (nr_steps) + nr_steps--; + break; + case ' ': + psz = 1.0; + prim = GL_TRIANGLES; + nr_steps = 4; + break; + case 27: + exit(0); + break; } glutPostRedisplay(); } diff --git a/progs/vpglsl/Makefile b/progs/vpglsl/Makefile index 313b4dfa227..3982aca5650 100644 --- a/progs/vpglsl/Makefile +++ b/progs/vpglsl/Makefile @@ -7,7 +7,7 @@ TOP = ../.. include $(TOP)/configs/current -LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) +LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLEW_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) SOURCES = \ vp-tris.c diff --git a/progs/vpglsl/mov.glsl b/progs/vpglsl/mov.glsl new file mode 100644 index 00000000000..63b16f4754b --- /dev/null +++ b/progs/vpglsl/mov.glsl @@ -0,0 +1,5 @@ + +void main() { + gl_FrontColor = gl_Color; + gl_Position = gl_Vertex; +} diff --git a/progs/vpglsl/vp-tris.c b/progs/vpglsl/vp-tris.c index 9108d3f1978..9ae410bf984 100644 --- a/progs/vpglsl/vp-tris.c +++ b/progs/vpglsl/vp-tris.c @@ -4,7 +4,8 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> -#define GL_GLEXT_PROTOTYPES + +#include <GL/glew.h> #include <GL/glut.h> static const char *filename = NULL; @@ -99,27 +100,29 @@ static void setup_uniforms() } - GLuint loc1f = glGetUniformLocationARB(program, "KernelValue1f"); - GLuint loc2f = glGetUniformLocationARB(program, "KernelValue2f"); - GLuint loc4f = glGetUniformLocationARB(program, "KernelValue4f"); - GLfloat vecKer[] = - { 1.0, 0.0, 0.0, 0.25, - 0.0, 1.0, 0.0, 0.25, - 0.0, 0.0, 1.0, 0.25, - 0.0, 0.0, 0.0, 0.25, - 0.5, 0.0, 0.0, 0.35, - 0.0, 0.5, 0.0, 0.35, - 0.0, 0.0, 0.5, 0.35, - 0.0, 0.0, 0.0, 0.35 - }; - if (loc1f >= 0) - glUniform1fv(loc1f, 16, vecKer); - - if (loc2f >= 0) - glUniform2fv(loc2f, 8, vecKer); - - if (loc4f >= 0) - glUniform4fv(loc4f, 4, vecKer); + { + GLuint loc1f = glGetUniformLocationARB(program, "KernelValue1f"); + GLuint loc2f = glGetUniformLocationARB(program, "KernelValue2f"); + GLuint loc4f = glGetUniformLocationARB(program, "KernelValue4f"); + GLfloat vecKer[] = + { 1.0, 0.0, 0.0, 0.25, + 0.0, 1.0, 0.0, 0.25, + 0.0, 0.0, 1.0, 0.25, + 0.0, 0.0, 0.0, 0.25, + 0.5, 0.0, 0.0, 0.35, + 0.0, 0.5, 0.0, 0.35, + 0.0, 0.0, 0.5, 0.35, + 0.0, 0.0, 0.0, 0.35 + }; + if (loc1f >= 0) + glUniform1fv(loc1f, 16, vecKer); + + if (loc2f >= 0) + glUniform2fv(loc2f, 8, vecKer); + + if (loc4f >= 0) + glUniform4fv(loc4f, 4, vecKer); + } } static void prepare_shaders() @@ -303,6 +306,7 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH ); glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); glutDisplayFunc( Display ); diff --git a/progs/wgl/SConscript b/progs/wgl/SConscript new file mode 100644 index 00000000000..b7cf35b7fce --- /dev/null +++ b/progs/wgl/SConscript @@ -0,0 +1,23 @@ +Import('*') + +if env['platform'] != 'windows': + Return() + +env = env.Clone() + +env.Append(LIBS = [ + 'kernel32', + 'user32', + 'gdi32', +]) + +progs = [ + 'sharedtex_mt', + 'wglthreads', +] + +for prog in progs: + env.Program( + target = prog, + source = prog + '/' + prog + '.c', + ) diff --git a/progs/wgl/sharedtex_mt/sharedtex_mt.c b/progs/wgl/sharedtex_mt/sharedtex_mt.c new file mode 100644 index 00000000000..137c9c10af2 --- /dev/null +++ b/progs/wgl/sharedtex_mt/sharedtex_mt.c @@ -0,0 +1,540 @@ +/* + * Test sharing of display lists and texture objects between GLX contests. + * Brian Paul + * Summer 2000 + * + * + * Copyright (C) 2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Modified 2009 for multithreading by Thomas Hellstrom. + * + * Port to windows by Michal Krol. + */ + + +#include <windows.h> +#include <GL/gl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#pragma comment(lib, "opengl32.lib") + +struct thread_init_arg { + int id; +}; + +struct window { + CRITICAL_SECTION drawMutex; + HDC hDC; + HWND Win; + HGLRC Context; + float Angle; + int Id; +}; + + +#define MAX_WINDOWS 20 +static struct window Windows[MAX_WINDOWS]; +static int NumWindows = 0; +static HANDLE terminate = NULL; +static HGLRC gCtx = NULL; +static HDC gHDC = NULL; +static GLuint Textures[3]; + + + +static void +Error(const char *msg) +{ + fprintf(stderr, "Error - %s\n", msg); + exit(1); +} + +static void +Resize(struct window *h, unsigned int width, unsigned int height); + +static LRESULT CALLBACK +WndProc(HWND hWnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam ) +{ + switch (uMsg) { + case WM_KEYDOWN: + SetEvent(terminate); + break; + case WM_SIZE: + { + LONG index = GetWindowLong(hWnd, GWL_USERDATA); + + if (index >= 0 && index < MAX_WINDOWS) { + RECT r; + + GetClientRect(hWnd, &r); + Resize(&Windows[index], r.right, r.bottom); + } + } + break; + case WM_CREATE: + { + CREATESTRUCT *pcs = (CREATESTRUCT *) lParam; + + SetWindowLong(hWnd, GWL_USERDATA, (LONG) pcs->lpCreateParams); + } + break; + case WM_DESTROY: + PostQuitMessage(0); + break; + default: + return DefWindowProc(hWnd, uMsg, wParam, lParam); + } + + return 0; +} + +static int +initMainthread(void) +{ + WNDCLASS wc = {0}; + HWND win; + PIXELFORMATDESCRIPTOR pfd = {0}; + int visinfo; + + wc.lpfnWndProc = WndProc; + wc.lpszClassName = "sharedtex_mt.hidden"; + wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; + RegisterClass(&wc); + + win = CreateWindowEx(0, + wc.lpszClassName, + "sharedtex_mt.hidden", + WS_CLIPSIBLINGS | WS_CLIPCHILDREN, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + NULL, + NULL, + wc.hInstance, + (LPVOID) -1); + if (!win) { + Error("Couldn't create window"); + } + + gHDC = GetDC(win); + if (!gHDC) { + Error("Couldn't obtain HDC"); + } + + pfd.cColorBits = 24; + pfd.cDepthBits = 24; + pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; + pfd.iLayerType = PFD_MAIN_PLANE; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.nSize = sizeof(pfd); + pfd.nVersion = 1; + + visinfo = ChoosePixelFormat(gHDC, &pfd); + if (!visinfo) { + Error("Unable to find RGB, Z, double-buffered visual"); + } + + SetPixelFormat(gHDC, visinfo, &pfd); + gCtx = wglCreateContext(gHDC); + if (!gCtx) { + Error("Couldn't create WGL context"); + } + + return 0; +} + +static struct window * +AddWindow(int xpos, int ypos, HGLRC sCtx) +{ + struct window *win = &Windows[NumWindows]; + WNDCLASS wc = {0}; + PIXELFORMATDESCRIPTOR pfd = {0}; + int visinfo; + int width = 300, height = 300; + + if (NumWindows >= MAX_WINDOWS) + return NULL; + + memset(win, 0, sizeof(*win)); + InitializeCriticalSection(&win->drawMutex); + win->Angle = 0.0; + win->Id = NumWindows++; + + wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wc.lpfnWndProc = WndProc; + wc.lpszClassName = "sharedtex_mt"; + wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; + RegisterClass(&wc); + + win->Win = CreateWindowEx(0, + wc.lpszClassName, + "sharedtex_mt", + WS_SIZEBOX | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, + xpos, + ypos, + width, + height, + NULL, + NULL, + wc.hInstance, + (LPVOID) win->Id); + if (!win->Win) { + Error("Couldn't create window"); + } + + win->hDC = GetDC(win->Win); + if (!win->hDC) { + Error("Couldn't obtain HDC"); + } + + pfd.cColorBits = 24; + pfd.cDepthBits = 24; + pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; + pfd.iLayerType = PFD_MAIN_PLANE; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.nSize = sizeof(pfd); + pfd.nVersion = 1; + + visinfo = ChoosePixelFormat(win->hDC, &pfd); + if (!visinfo) { + Error("Unable to find RGB, Z, double-buffered visual"); + } + + SetPixelFormat(win->hDC, visinfo, &pfd); + win->Context = wglCreateContext(win->hDC); + if (!win->Context) { + Error("Couldn't create WGL context"); + } + + if (sCtx) { + wglShareLists(sCtx, win->Context); + } + + ShowWindow(win->Win, SW_SHOW); + + return win; +} + + +static void +InitGLstuff(void) + +{ + glGenTextures(3, Textures); + + /* setup first texture object */ + { + GLubyte image[16][16][4]; + GLint i, j; + glBindTexture(GL_TEXTURE_2D, Textures[0]); + + /* red/white checkerboard */ + for (i = 0; i < 16; i++) { + for (j = 0; j < 16; j++) { + if ((i ^ j) & 1) { + image[i][j][0] = 255; + image[i][j][1] = 255; + image[i][j][2] = 255; + image[i][j][3] = 255; + } + else { + image[i][j][0] = 255; + image[i][j][1] = 0; + image[i][j][2] = 0; + image[i][j][3] = 255; + } + } + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, + GL_UNSIGNED_BYTE, image); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + + /* setup second texture object */ + { + GLubyte image[8][8][3]; + GLint i, j; + glBindTexture(GL_TEXTURE_2D, Textures[1]); + + /* green/yellow checkerboard */ + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { + if ((i ^ j) & 1) { + image[i][j][0] = 0; + image[i][j][1] = 255; + image[i][j][2] = 0; + } + else { + image[i][j][0] = 255; + image[i][j][1] = 255; + image[i][j][2] = 0; + } + } + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 2); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, + GL_UNSIGNED_BYTE, image); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + + /* setup second texture object */ + { + GLubyte image[4][4][3]; + GLint i, j; + glBindTexture(GL_TEXTURE_2D, Textures[2]); + + /* blue/gray checkerboard */ + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + if ((i ^ j) & 1) { + image[i][j][0] = 0; + image[i][j][1] = 0; + image[i][j][2] = 255; + } + else { + image[i][j][0] = 200; + image[i][j][1] = 200; + image[i][j][2] = 200; + } + } + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 2); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGB, + GL_UNSIGNED_BYTE, image); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + + /* Now make the cube object display list */ + + printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION: %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR: %s\n", (char *) glGetString(GL_VENDOR)); +} + +static void +Redraw(struct window *h) +{ + EnterCriticalSection(&h->drawMutex); + if (!wglMakeCurrent(h->hDC, h->Context)) { + LeaveCriticalSection(&h->drawMutex); + Error("wglMakeCurrent failed in Redraw"); + return; + } + + h->Angle += 1.0; + + glShadeModel(GL_FLAT); + glClearColor(0.25, 0.25, 0.25, 1.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glEnable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + glColor3f(1, 1, 1); + + glPushMatrix(); + if (h->Id == 0) + glRotatef(h->Angle, 0, 1, -1); + else if (h->Id == 1) + glRotatef(-(h->Angle), 0, 1, -1); + else if (h->Id == 2) + glRotatef(h->Angle, 0, 1, 1); + else if (h->Id == 3) + glRotatef(-(h->Angle), 0, 1, 1); + glBindTexture(GL_TEXTURE_2D, Textures[0]); + glBegin(GL_POLYGON); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f(-1, 1, -1); + glTexCoord2f(1, 1); glVertex3f(-1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); + glEnd(); + glBegin(GL_POLYGON); + glTexCoord2f(0, 0); glVertex3f(1, -1, -1); + glTexCoord2f(1, 0); glVertex3f(1, 1, -1); + glTexCoord2f(1, 1); glVertex3f(1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(1, -1, 1); + glEnd(); + + glBindTexture(GL_TEXTURE_2D, Textures[1]); + glBegin(GL_POLYGON); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, -1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); + glEnd(); + glBegin(GL_POLYGON); + glTexCoord2f(0, 0); glVertex3f(-1, 1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, 1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); + glEnd(); + + glBindTexture(GL_TEXTURE_2D, Textures[2]); + glBegin(GL_POLYGON); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, -1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, -1); + glEnd(); + glBegin(GL_POLYGON); + glTexCoord2f(0, 0); glVertex3f(-1, -1, 1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, 1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); + glEnd(); + + glPopMatrix(); + + SwapBuffers(h->hDC); + + if (!wglMakeCurrent(NULL, NULL)) { + Error("wglMakeCurrent failed in Redraw"); + } + LeaveCriticalSection(&h->drawMutex); +} + +static DWORD WINAPI +threadRunner (void *arg) +{ + struct thread_init_arg *tia = (struct thread_init_arg *) arg; + struct window *win; + + win = &Windows[tia->id]; + + while (1) { + MSG msg; + + /* wait 1 ms for signal either to exit or process messages */ + switch (MsgWaitForMultipleObjects(1, &terminate, FALSE, 1, QS_ALLINPUT)) { + case WAIT_OBJECT_0: + SendMessage(win->Win, WM_CLOSE, 0, 0); + break; + case WAIT_OBJECT_0 + 1: + break; + } + + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + if (msg.message == WM_QUIT) { + return 0; + } + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + Redraw(win); + } + + return 0; +} + +static void +Resize(struct window *h, unsigned int width, unsigned int height) +{ + EnterCriticalSection(&h->drawMutex); + + if (!wglMakeCurrent(h->hDC, h->Context)) { + LeaveCriticalSection(&h->drawMutex); + Error("wglMakeCurrent failed in Resize()"); + return; + } + + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1, 1, -1, 1, 2, 10); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0, 0, -4.5); + if (!wglMakeCurrent(NULL, NULL)) { + Error("wglMakeCurrent failed in Resize()"); + } + LeaveCriticalSection(&h->drawMutex); +} + +int +main(int argc, char *argv[]) +{ + struct thread_init_arg tia[MAX_WINDOWS]; + struct window *h[MAX_WINDOWS]; + HANDLE threads[MAX_WINDOWS]; + int i; + + terminate = CreateEvent(NULL, TRUE, FALSE, NULL); + + if (initMainthread()) + return -1; + + /* four windows and contexts sharing display lists and texture objects */ + h[0] = AddWindow( 10, 10, gCtx); + h[1] = AddWindow(330, 10, gCtx); + h[2] = AddWindow( 10, 350, gCtx); + h[3] = AddWindow(330, 350, gCtx); + + if (!wglMakeCurrent(gHDC, gCtx)) { + Error("wglMakeCurrent failed for init thread."); + return -1; + } + + InitGLstuff(); + + for (i = 0; i < NumWindows; i++) { + DWORD id; + + tia[i].id = i; + threads[i] = CreateThread(NULL, 0, threadRunner, &tia[i], 0, &id); + } + + while (1) { + MSG msg; + + /* wait 1 ms for signal either to exit or process messages */ + switch (MsgWaitForMultipleObjects(NumWindows, threads, TRUE, 1, QS_ALLINPUT)) { + case WAIT_OBJECT_0: + return 0; + } + + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + if (msg.message == WM_QUIT) { + return 0; + } + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + return 0; +} diff --git a/progs/wgl/wglthreads/wglthreads.c b/progs/wgl/wglthreads/wglthreads.c new file mode 100644 index 00000000000..32f3e45edf5 --- /dev/null +++ b/progs/wgl/wglthreads/wglthreads.c @@ -0,0 +1,614 @@ +/* + * Copyright (C) 2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Port to windows done by Michal Krol. + */ + + +/* + * This program tests WGL thread safety. + * Command line options: + * -h Print usage + * -l Enable application-side locking + * -n <num threads> Number of threads to create (default is 2) + * -t Use texture mapping + * -s Force single-threaded. + * + * Brian Paul 20 July 2000 + */ + + +/* + * Notes: + * - Each thread gets its own WGL context. + * + * - The WGL contexts share texture objects. + * + * - When 't' is pressed to update the texture image, the window/thread which + * has input focus is signalled to change the texture. The other threads + * should see the updated texture the next time they call glBindTexture. + */ + + +#include <assert.h> +#include <windows.h> +#include <GL/gl.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#pragma comment(lib, "opengl32.lib") + + +/* + * Each window/thread/context: + */ +struct winthread { + int Index; + HANDLE Thread; + HWND Win; + HDC hDC; + HGLRC Context; + float Angle; + int WinWidth, WinHeight; + GLboolean NewSize; + HANDLE hEventInitialised; + GLboolean MakeNewTexture; + HANDLE hEventRedraw; +}; + + +#define MAX_WINTHREADS 100 +static struct winthread WinThreads[MAX_WINTHREADS]; +static int NumWinThreads = 2; +static HANDLE ExitEvent = NULL; + +static GLboolean Locking = 0; +static GLboolean Texture = GL_FALSE; +static GLboolean SingleThreaded = GL_FALSE; +static GLuint TexObj = 12; +static GLboolean Animate = GL_TRUE; + +static CRITICAL_SECTION Mutex; + + +static void +Error(const char *msg) +{ + fprintf(stderr, "Error: %s\n", msg); + exit(1); +} + + +static void +signal_redraw(void) +{ + int i; + + for (i = 0; i < NumWinThreads; i++) { + SetEvent(WinThreads[i].hEventRedraw); + } +} + + +static void +MakeNewTexture(struct winthread *wt) +{ +#define TEX_SIZE 128 + static float step = 0.0; + GLfloat image[TEX_SIZE][TEX_SIZE][4]; + GLint width; + int i, j; + + for (j = 0; j < TEX_SIZE; j++) { + for (i = 0; i < TEX_SIZE; i++) { + float dt = 5.0 * (j - 0.5 * TEX_SIZE) / TEX_SIZE; + float ds = 5.0 * (i - 0.5 * TEX_SIZE) / TEX_SIZE; + float r = dt * dt + ds * ds + step; + image[j][i][0] = + image[j][i][1] = + image[j][i][2] = 0.75 + 0.25 * cos(r); + image[j][i][3] = 1.0; + } + } + + step += 0.5; + + glBindTexture(GL_TEXTURE_2D, TexObj); + + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width); + if (width) { + assert(width == TEX_SIZE); + /* sub-tex replace */ + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEX_SIZE, TEX_SIZE, + GL_RGBA, GL_FLOAT, image); + } + else { + /* create new */ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEX_SIZE, TEX_SIZE, 0, + GL_RGBA, GL_FLOAT, image); + } +} + + + +/* draw a colored cube */ +static void +draw_object(void) +{ + glPushMatrix(); + glScalef(0.75, 0.75, 0.75); + + glColor3f(1, 0, 0); + + if (Texture) { + glBindTexture(GL_TEXTURE_2D, TexObj); + glEnable(GL_TEXTURE_2D); + } + else { + glDisable(GL_TEXTURE_2D); + } + + glBegin(GL_QUADS); + + /* -X */ + glColor3f(0, 1, 1); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f(-1, 1, -1); + glTexCoord2f(1, 1); glVertex3f(-1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); + + /* +X */ + glColor3f(1, 0, 0); + glTexCoord2f(0, 0); glVertex3f(1, -1, -1); + glTexCoord2f(1, 0); glVertex3f(1, 1, -1); + glTexCoord2f(1, 1); glVertex3f(1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(1, -1, 1); + + /* -Y */ + glColor3f(1, 0, 1); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, -1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); + + /* +Y */ + glColor3f(0, 1, 0); + glTexCoord2f(0, 0); glVertex3f(-1, 1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, 1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); + + /* -Z */ + glColor3f(1, 1, 0); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, -1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, -1); + + /* +Y */ + glColor3f(0, 0, 1); + glTexCoord2f(0, 0); glVertex3f(-1, -1, 1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, 1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); + + glEnd(); + + glPopMatrix(); +} + + +/* signal resize of given window */ +static void +resize(struct winthread *wt, int w, int h) +{ + wt->NewSize = GL_TRUE; + wt->WinWidth = w; + wt->WinHeight = h; + if (!Animate) + SetEvent(wt->hEventRedraw); +} + + +/* + * We have an instance of this for each thread. + */ +static void +draw_loop(struct winthread *wt) +{ + while (1) { + GLboolean draw = Animate; + MSG msg; + + if (Animate) { + /* wait 5 ms for signal either to exit or process messages */ + switch (MsgWaitForMultipleObjects(1, &ExitEvent, FALSE, 5, QS_ALLINPUT)) { + case WAIT_OBJECT_0: + SendMessage(wt->Win, WM_CLOSE, 0, 0); + break; + case WAIT_OBJECT_0 + 1: + break; + } + } + else { + HANDLE events[2]; + + events[0] = wt->hEventRedraw; + events[1] = ExitEvent; + + /* wait for signal either to draw, exit or process messages */ + switch (MsgWaitForMultipleObjects(2, events, FALSE, INFINITE, QS_ALLINPUT)) { + case WAIT_OBJECT_0: + draw = GL_TRUE; + break; + case WAIT_OBJECT_0 + 1: + SendMessage(wt->Win, WM_CLOSE, 0, 0); + break; + case WAIT_OBJECT_0 + 2: + break; + } + } + + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + if (msg.message == WM_QUIT) { + return; + } + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + if (!draw) + continue; + + if (Locking) + EnterCriticalSection(&Mutex); + + wglMakeCurrent(wt->hDC, wt->Context); + + if (Locking) + LeaveCriticalSection(&Mutex); + + glEnable(GL_DEPTH_TEST); + + if (wt->NewSize) { + GLfloat w = (float) wt->WinWidth / (float) wt->WinHeight; + glViewport(0, 0, wt->WinWidth, wt->WinHeight); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-w, w, -1.0, 1.0, 1.5, 10); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0, 0, -2.5); + wt->NewSize = GL_FALSE; + } + + if (wt->MakeNewTexture) { + MakeNewTexture(wt); + wt->MakeNewTexture = GL_FALSE; + } + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glPushMatrix(); + glRotatef(wt->Angle, 0, 1, 0); + glRotatef(wt->Angle, 1, 0, 0); + glScalef(0.7, 0.7, 0.7); + draw_object(); + glPopMatrix(); + + if (Locking) + EnterCriticalSection(&Mutex); + SwapBuffers(wt->hDC); + if (Locking) + LeaveCriticalSection(&Mutex); + + wt->Angle += 1.0; + } +} + + +static void +keypress(WPARAM keySym, struct winthread *wt) +{ + switch (keySym) { + case VK_ESCAPE: + /* tell all threads to exit */ + SetEvent(ExitEvent); + /*printf("exit draw_loop %d\n", wt->Index);*/ + return; + case 't': + case 'T': + if (Texture) { + wt->MakeNewTexture = GL_TRUE; + if (!Animate) + signal_redraw(); + } + break; + case 'a': + case 'A': + Animate = !Animate; + if (Animate) + signal_redraw(); + break; + case 's': + case 'S': + if (!Animate) + signal_redraw(); + break; + default: + ; /* nop */ + } +} + + +static LRESULT CALLBACK +WndProc(HWND hWnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam ) +{ + int i; + + switch (uMsg) { + case WM_KEYDOWN: + for (i = 0; i < NumWinThreads; i++) { + struct winthread *wt = &WinThreads[i]; + + if (hWnd == wt->Win) { + keypress(wParam, wt); + break; + } + } + break; + case WM_SIZE: + for (i = 0; i < NumWinThreads; i++) { + struct winthread *wt = &WinThreads[i]; + + if (hWnd == wt->Win) { + RECT r; + + GetClientRect(hWnd, &r); + resize(wt, r.right, r.bottom); + break; + } + } + break; + case WM_DESTROY: + PostQuitMessage(0); + break; + default: + return DefWindowProc(hWnd, uMsg, wParam, lParam); + } + + return 0; +} + +/* + * we'll call this once for each thread, before the threads are created. + */ +static void +create_window(struct winthread *wt, HGLRC shareCtx) +{ + WNDCLASS wc = {0}; + int width = 160, height = 160; + int xpos = (wt->Index % 8) * (width + 10); + int ypos = (wt->Index / 8) * (width + 20); + HWND win; + HDC hdc; + PIXELFORMATDESCRIPTOR pfd = {0}; + int visinfo; + HGLRC ctx; + + wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wc.lpfnWndProc = WndProc; + wc.lpszClassName = "wglthreads"; + wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; + RegisterClass(&wc); + + win = CreateWindowEx(0, + wc.lpszClassName, + "wglthreads", + WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, + xpos, + ypos, + width, + height, + NULL, + NULL, + wc.hInstance, + (LPVOID) wt); + if (!win) { + Error("Couldn't create window"); + } + + hdc = GetDC(win); + if (!hdc) { + Error("Couldn't obtain HDC"); + } + + pfd.cColorBits = 24; + pfd.cDepthBits = 24; + pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; + pfd.iLayerType = PFD_MAIN_PLANE; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.nSize = sizeof(pfd); + pfd.nVersion = 1; + + visinfo = ChoosePixelFormat(hdc, &pfd); + if (!visinfo) { + Error("Unable to find RGB, Z, double-buffered visual"); + } + + SetPixelFormat(hdc, visinfo, &pfd); + ctx = wglCreateContext(hdc); + if (!ctx) { + Error("Couldn't create WGL context"); + } + + if (shareCtx) { + wglShareLists(shareCtx, ctx); + } + + /* save the info for this window/context */ + wt->Win = win; + wt->hDC = hdc; + wt->Context = ctx; + wt->Angle = 0.0; + wt->WinWidth = width; + wt->WinHeight = height; + wt->NewSize = GL_TRUE; + + printf("wglthreads: %d: GL_RENDERER = %s\n", wt->Index, (char *) glGetString(GL_RENDERER)); + + if (Texture/* && wt->Index == 0*/) { + MakeNewTexture(wt); + } +} + + +/* + * Called by pthread_create() + */ +static DWORD WINAPI +ThreadProc(void *p) +{ + struct winthread *wt = (struct winthread *) p; + HGLRC share; + + share = (Texture && wt->Index > 0) ? WinThreads[0].Context : 0; + create_window(wt, share); + SetEvent(wt->hEventInitialised); + + draw_loop(wt); + return 0; +} + + +static void +usage(void) +{ + printf("wglthreads: test of GL thread safety (any key = exit)\n"); + printf("Usage:\n"); + printf(" wglthreads [options]\n"); + printf("Options:\n"); + printf(" -h Show this usage screen\n"); + printf(" -n NUMTHREADS Number of threads to create\n"); + printf(" -l Use application-side locking\n"); + printf(" -t Enable texturing\n"); + printf(" -s Force single-threaded\n"); + printf("Keyboard:\n"); + printf(" Esc Exit\n"); + printf(" t Change texture image (requires -t option)\n"); + printf(" a Toggle animation\n"); + printf(" s Step rotation (when not animating)\n"); +} + + +int +main(int argc, char *argv[]) +{ + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-h") == 0) { + usage(); + } + else if (strcmp(argv[i], "-l") == 0) { + Locking = 1; + } + else if (strcmp(argv[i], "-t") == 0) { + Texture = 1; + } + else if (strcmp(argv[i], "-n") == 0 && i + 1 < argc) { + NumWinThreads = atoi(argv[i + 1]); + if (NumWinThreads < 1) + NumWinThreads = 1; + else if (NumWinThreads > MAX_WINTHREADS) + NumWinThreads = MAX_WINTHREADS; + i++; + } + else if (strcmp(argv[i], "-s") == 0) { + SingleThreaded = GL_TRUE; + } + else { + usage(); + exit(1); + } + } + + if (SingleThreaded) + printf("wglthreads: Forcing single-threaded, no other threads will be created.\n"); + + if (Locking) + printf("wglthreads: Using explicit locks around WGL calls.\n"); + else + printf("wglthreads: No explict locking.\n"); + + InitializeCriticalSection(&Mutex); + ExitEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + + if (SingleThreaded) { + NumWinThreads = 1; + + WinThreads[0].Index = 0; + WinThreads[0].hEventInitialised = CreateEvent(NULL, TRUE, FALSE, NULL); + WinThreads[0].hEventRedraw = CreateEvent(NULL, FALSE, FALSE, NULL); + + ThreadProc((void*) &WinThreads[0]); + } + else { + HANDLE threads[MAX_WINTHREADS]; + + printf("wglthreads: creating threads\n"); + + /* Create the threads */ + for (i = 0; i < NumWinThreads; i++) { + DWORD id; + + WinThreads[i].Index = i; + WinThreads[i].hEventInitialised = CreateEvent(NULL, TRUE, FALSE, NULL); + WinThreads[i].hEventRedraw = CreateEvent(NULL, FALSE, FALSE, NULL); + WinThreads[i].Thread = CreateThread(NULL, + 0, + ThreadProc, + (void*) &WinThreads[i], + 0, + &id); + printf("wglthreads: Created thread %p\n", (void *) WinThreads[i].Thread); + + WaitForSingleObject(WinThreads[i].hEventInitialised, INFINITE); + + threads[i] = WinThreads[i].Thread; + } + + /* Wait for all threads to finish. */ + WaitForMultipleObjects(NumWinThreads, threads, TRUE, INFINITE); + } + + return 0; +} diff --git a/progs/xdemos/.gitignore b/progs/xdemos/.gitignore index 084dee5d844..92446dd9fc3 100644 --- a/progs/xdemos/.gitignore +++ b/progs/xdemos/.gitignore @@ -18,6 +18,7 @@ overlay pbdemo pbinfo sharedtex +sharedtex_mt texture_from_pixmap wincopy xdemo diff --git a/progs/xdemos/Makefile b/progs/xdemos/Makefile index 8d248fb0a92..bb353e318c9 100644 --- a/progs/xdemos/Makefile +++ b/progs/xdemos/Makefile @@ -31,6 +31,7 @@ PROGS = \ pbinfo \ pbdemo \ sharedtex \ + sharedtex_mt \ texture_from_pixmap \ wincopy \ xfont \ diff --git a/progs/xdemos/glsync.c b/progs/xdemos/glsync.c index 95cd1af4004..34167d339f3 100644 --- a/progs/xdemos/glsync.c +++ b/progs/xdemos/glsync.c @@ -112,6 +112,7 @@ int main(int argc, char *argv[]) int attrib[14]; GLint last_val = -1, count = 0; Window winGL; + GLXContext context; int dummy; Atom wmDelete; enum sync_type waitforsync = none; @@ -185,7 +186,6 @@ int main(int argc, char *argv[]) attrib[10] = None; } - GLXContext context; pvi = glXChooseVisual(disp, DefaultScreen(disp), attrib); if (!pvi) { fprintf(stderr, "failed to choose visual, exiting\n"); diff --git a/progs/xdemos/glxpixmap.c b/progs/xdemos/glxpixmap.c index 9db4df2c8b8..e1abd22ceef 100644 --- a/progs/xdemos/glxpixmap.c +++ b/progs/xdemos/glxpixmap.c @@ -178,6 +178,7 @@ int main( int argc, char *argv[] ) glColor3f( 0.0, 1.0, 1.0 ); glRectf( -0.75, -0.75, 0.75, 0.75 ); glFlush(); + glXWaitGL(); XMapWindow( dpy, win ); diff --git a/progs/xdemos/manywin.c b/progs/xdemos/manywin.c index cfea555210a..ee357f32a40 100644 --- a/progs/xdemos/manywin.c +++ b/progs/xdemos/manywin.c @@ -286,7 +286,7 @@ EventLoop(void) XLookupString(&event.xkey, buf, sizeof(buf), &keySym, &stat); switch (keySym) { case XK_Escape: - exit(0); + return; break; case XK_d: case XK_D: diff --git a/progs/xdemos/sharedtex_mt.c b/progs/xdemos/sharedtex_mt.c new file mode 100644 index 00000000000..07c1bfcc388 --- /dev/null +++ b/progs/xdemos/sharedtex_mt.c @@ -0,0 +1,486 @@ +/* $Id: sharedtex.c,v 1.2 2002/01/16 14:32:46 joukj Exp $ */ + +/* + * Test sharing of display lists and texture objects between GLX contests. + * Brian Paul + * Summer 2000 + * + * + * Copyright (C) 2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + * Modified 2009 for multithreading by Thomas Hellstrom. + */ + + +#include <GL/gl.h> +#include <GL/glx.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <pthread.h> +#include <X11/X.h> + +struct thread_init_arg { + int id; +}; + +struct window { + pthread_mutex_t drawMutex; + char DisplayName[1000]; + Display *Dpy; + Window Win; + GLXContext Context; + float Angle; + int Id; + XVisualInfo *visInfo; +}; + + +#define MAX_WINDOWS 20 +static struct window Windows[MAX_WINDOWS]; +static int NumWindows = 0; +static int terminate = 0; +static GLXContext gCtx; +static Display *gDpy; +static GLuint Textures[3]; + + + +static void +Error(const char *display, const char *msg) +{ + fprintf(stderr, "Error on display %s - %s\n", display, msg); + exit(1); +} + + +static int +initMainthread(Display *dpy, const char *displayName) +{ + int scrnum; + XVisualInfo *visinfo; + int attrib[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + GLX_DEPTH_SIZE, 1, + None }; + + scrnum = DefaultScreen(dpy); + visinfo = glXChooseVisual(dpy, scrnum, attrib); + if (!visinfo) { + Error(displayName, "Unable to find RGB, double-buffered visual"); + return -1; + } + gCtx = glXCreateContext(dpy, visinfo, NULL, True); + if (!gCtx) { + Error(displayName, "Couldn't create GLX context"); + return -1; + } + return 0; +} + +static struct window * +AddWindow(Display *dpy, const char *displayName, int xpos, int ypos, + GLXContext sCtx) +{ + Window win; + GLXContext ctx; + int attrib[] = { GLX_RGBA, + GLX_RED_SIZE, 1, + GLX_GREEN_SIZE, 1, + GLX_BLUE_SIZE, 1, + GLX_DOUBLEBUFFER, + GLX_DEPTH_SIZE, 1, + None }; + int scrnum; + XSetWindowAttributes attr; + unsigned long mask; + Window root; + XVisualInfo *visinfo; + int width = 300, height = 300; + + if (NumWindows >= MAX_WINDOWS) + return NULL; + + scrnum = DefaultScreen(dpy); + root = RootWindow(dpy, scrnum); + + visinfo = glXChooseVisual(dpy, scrnum, attrib); + if (!visinfo) { + Error(displayName, "Unable to find RGB, double-buffered visual"); + return NULL; + } + + /* window attributes */ + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + mask = CWBorderPixel | CWColormap | CWEventMask; + + win = XCreateWindow(dpy, root, xpos, ypos, width, height, + 0, visinfo->depth, InputOutput, + visinfo->visual, mask, &attr); + if (!win) { + Error(displayName, "Couldn't create window"); + return NULL; + } + + { + XSizeHints sizehints; + sizehints.x = xpos; + sizehints.y = ypos; + sizehints.width = width; + sizehints.height = height; + sizehints.flags = USSize | USPosition; + XSetNormalHints(dpy, win, &sizehints); + XSetStandardProperties(dpy, win, displayName, displayName, + None, (char **)NULL, 0, &sizehints); + } + + + ctx = glXCreateContext(dpy, visinfo, + sCtx ? sCtx : NULL, True); + + if (!ctx) { + Error(displayName, "Couldn't create GLX context"); + return NULL; + } + + XMapWindow(dpy, win); + + /* save the info for this window */ + { + static int id = 0; + struct window *h = &Windows[NumWindows]; + strcpy(h->DisplayName, displayName); + h->Dpy = dpy; + h->Win = win; + h->Context = ctx; + h->Angle = 0.0; + h->Id = id++; + h->visInfo = visinfo; + pthread_mutex_init(&h->drawMutex, NULL); + NumWindows++; + return &Windows[NumWindows-1]; + } +} + + +static void +InitGLstuff(void) + +{ + glGenTextures(3, Textures); + + /* setup first texture object */ + { + GLubyte image[16][16][4]; + GLint i, j; + glBindTexture(GL_TEXTURE_2D, Textures[0]); + + /* red/white checkerboard */ + for (i = 0; i < 16; i++) { + for (j = 0; j < 16; j++) { + if ((i ^ j) & 1) { + image[i][j][0] = 255; + image[i][j][1] = 255; + image[i][j][2] = 255; + image[i][j][3] = 255; + } + else { + image[i][j][0] = 255; + image[i][j][1] = 0; + image[i][j][2] = 0; + image[i][j][3] = 255; + } + } + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, + GL_UNSIGNED_BYTE, image); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + + /* setup second texture object */ + { + GLubyte image[8][8][3]; + GLint i, j; + glBindTexture(GL_TEXTURE_2D, Textures[1]); + + /* green/yellow checkerboard */ + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { + if ((i ^ j) & 1) { + image[i][j][0] = 0; + image[i][j][1] = 255; + image[i][j][2] = 0; + } + else { + image[i][j][0] = 255; + image[i][j][1] = 255; + image[i][j][2] = 0; + } + } + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 2); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 8, 8, 0, GL_RGB, + GL_UNSIGNED_BYTE, image); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + + /* setup second texture object */ + { + GLubyte image[4][4][3]; + GLint i, j; + glBindTexture(GL_TEXTURE_2D, Textures[2]); + + /* blue/gray checkerboard */ + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + if ((i ^ j) & 1) { + image[i][j][0] = 0; + image[i][j][1] = 0; + image[i][j][2] = 255; + } + else { + image[i][j][0] = 200; + image[i][j][1] = 200; + image[i][j][2] = 200; + } + } + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 2); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGB, + GL_UNSIGNED_BYTE, image); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + + /* Now make the cube object display list */ + + printf("GL_RENDERER: %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION: %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR: %s\n", (char *) glGetString(GL_VENDOR)); +} + +static void +Redraw(struct window *h) +{ + pthread_mutex_lock(&h->drawMutex); + if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) { + Error(h->DisplayName, "glXMakeCurrent failed in Redraw"); + pthread_mutex_unlock(&h->drawMutex); + return; + } + + h->Angle += 1.0; + + glShadeModel(GL_FLAT); + glClearColor(0.25, 0.25, 0.25, 1.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glEnable(GL_TEXTURE_2D); + glEnable(GL_DEPTH_TEST); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + glColor3f(1, 1, 1); + + glPushMatrix(); + if (h->Id == 0) + glRotatef(h->Angle, 0, 1, -1); + else if (h->Id == 1) + glRotatef(-(h->Angle), 0, 1, -1); + else if (h->Id == 2) + glRotatef(h->Angle, 0, 1, 1); + else if (h->Id == 3) + glRotatef(-(h->Angle), 0, 1, 1); + glBindTexture(GL_TEXTURE_2D, Textures[0]); + glBegin(GL_POLYGON); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f(-1, 1, -1); + glTexCoord2f(1, 1); glVertex3f(-1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); + glEnd(); + glBegin(GL_POLYGON); + glTexCoord2f(0, 0); glVertex3f(1, -1, -1); + glTexCoord2f(1, 0); glVertex3f(1, 1, -1); + glTexCoord2f(1, 1); glVertex3f(1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(1, -1, 1); + glEnd(); + + glBindTexture(GL_TEXTURE_2D, Textures[1]); + glBegin(GL_POLYGON); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, -1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, -1, 1); + glEnd(); + glBegin(GL_POLYGON); + glTexCoord2f(0, 0); glVertex3f(-1, 1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, 1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); + glEnd(); + + glBindTexture(GL_TEXTURE_2D, Textures[2]); + glBegin(GL_POLYGON); + glTexCoord2f(0, 0); glVertex3f(-1, -1, -1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, -1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, -1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, -1); + glEnd(); + glBegin(GL_POLYGON); + glTexCoord2f(0, 0); glVertex3f(-1, -1, 1); + glTexCoord2f(1, 0); glVertex3f( 1, -1, 1); + glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); + glTexCoord2f(0, 1); glVertex3f(-1, 1, 1); + glEnd(); + + glPopMatrix(); + + glXSwapBuffers(h->Dpy, h->Win); + + if (!glXMakeCurrent(h->Dpy, None, NULL)) { + Error(h->DisplayName, "glXMakeCurrent failed in Redraw"); + } + pthread_mutex_unlock(&h->drawMutex); +} + +static void *threadRunner (void *arg) +{ + struct thread_init_arg *tia = (struct thread_init_arg *) arg; + struct window *win; + + win = &Windows[tia->id]; + + while(!terminate) { + usleep(1000); + Redraw(win); + } + + return NULL; +} + +static void +Resize(struct window *h, unsigned int width, unsigned int height) +{ + pthread_mutex_lock(&h->drawMutex); + + if (!glXMakeCurrent(h->Dpy, h->Win, h->Context)) { + Error(h->DisplayName, "glXMakeCurrent failed in Resize()"); + pthread_mutex_unlock(&h->drawMutex); + return; + } + + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1, 1, -1, 1, 2, 10); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0, 0, -4.5); + if (!glXMakeCurrent(h->Dpy, None, NULL)) { + Error(h->DisplayName, "glXMakeCurrent failed in Resize()"); + } + pthread_mutex_unlock(&h->drawMutex); +} + + +static void +EventLoop(void) +{ + while (1) { + int i; + XEvent event; + XNextEvent(gDpy, &event); + for (i = 0; i < NumWindows; i++) { + struct window *h = &Windows[i]; + if (event.xany.window == h->Win) { + switch (event.type) { + case Expose: + Redraw(h); + break; + case ConfigureNotify: + Resize(h, event.xconfigure.width, event.xconfigure.height); + break; + case KeyPress: + terminate = 1; + return; + default: + /*no-op*/ ; + } + } + } + } +} + +int +main(int argc, char *argv[]) +{ + const char *dpyName = XDisplayName(NULL); + pthread_t t0, t1, t2, t3; + struct thread_init_arg tia0, tia1, tia2, tia3; + struct window *h0, *h1, *h2, *h3; + + XInitThreads(); + + gDpy = XOpenDisplay(dpyName); + if (!gDpy) { + Error(dpyName, "Unable to open display"); + return -1; + } + + if (initMainthread(gDpy, dpyName)) + return -1; + + /* four windows and contexts sharing display lists and texture objects */ + h0 = AddWindow(gDpy, dpyName, 10, 10, gCtx); + h1 = AddWindow(gDpy, dpyName, 330, 10, gCtx); + h2 = AddWindow(gDpy, dpyName, 10, 350, gCtx); + h3 = AddWindow(gDpy, dpyName, 330, 350, gCtx); + + if (!glXMakeCurrent(gDpy, h0->Win, gCtx)) { + Error(dpyName, "glXMakeCurrent failed for init thread."); + return -1; + } + + InitGLstuff(); + + tia0.id = 0; + pthread_create(&t0, NULL, threadRunner, &tia0); + tia1.id = 1; + pthread_create(&t1, NULL, threadRunner, &tia1); + tia2.id = 2; + pthread_create(&t2, NULL, threadRunner, &tia2); + tia3.id = 3; + pthread_create(&t3, NULL, threadRunner, &tia3); + EventLoop(); + return 0; +} |