diff options
Diffstat (limited to 'progs')
-rw-r--r-- | progs/demos/dinoshade.c | 4 | ||||
-rw-r--r-- | progs/demos/ipers.c | 18 | ||||
-rw-r--r-- | progs/demos/readpix.c | 67 | ||||
-rw-r--r-- | progs/demos/shadowtex.c | 2 | ||||
-rw-r--r-- | progs/demos/teapot.c | 11 | ||||
-rw-r--r-- | progs/demos/tunnel.c | 9 | ||||
-rw-r--r-- | progs/demos/tunnel2.c | 9 | ||||
-rw-r--r-- | progs/demos/vao_demo.c | 2 | ||||
-rw-r--r-- | progs/redbook/polyoff.c | 3 | ||||
-rw-r--r-- | progs/tests/.gitignore | 15 | ||||
-rw-r--r-- | progs/tests/Makefile | 1 | ||||
-rw-r--r-- | progs/tests/SConscript | 1 | ||||
-rw-r--r-- | progs/tests/floattex.c | 43 | ||||
-rw-r--r-- | progs/tests/mipmap_comp.c | 295 | ||||
-rw-r--r-- | progs/tests/mipmap_view.c | 267 | ||||
-rw-r--r-- | progs/trivial/Makefile | 3 | ||||
-rw-r--r-- | progs/trivial/SConscript | 3 | ||||
-rw-r--r-- | progs/trivial/line-flat.c | 147 | ||||
-rw-r--r-- | progs/trivial/vbo-noninterleaved.c | 139 | ||||
-rw-r--r-- | progs/trivial/vp-tri-invariant.c | 147 | ||||
-rw-r--r-- | progs/xdemos/glxcontexts.c | 4 |
21 files changed, 1105 insertions, 85 deletions
diff --git a/progs/demos/dinoshade.c b/progs/demos/dinoshade.c index 451da2ec89..cbf8751e25 100644 --- a/progs/demos/dinoshade.c +++ b/progs/demos/dinoshade.c @@ -382,7 +382,7 @@ static GLfloat floorShadow[4][4]; static void redraw(void) { - int start, end; + int start = 0, end = 0; if (reportSpeed) { start = glutGet(GLUT_ELAPSED_TIME); @@ -624,6 +624,7 @@ redraw(void) glFinish(); end = glutGet(GLUT_ELAPSED_TIME); printf("Speed %.3g frames/sec (%d ms)\n", 1000.0/(end-start), end-start); + fflush(stdout); } glutSwapBuffers(); @@ -878,6 +879,7 @@ main(int argc, char **argv) polygonOffsetVersion = MISSING; printf("\ndinoshine: Missing polygon offset.\n"); printf(" Expect shadow depth aliasing artifacts.\n\n"); + fflush(stdout); } } diff --git a/progs/demos/ipers.c b/progs/demos/ipers.c index 6e153c04e1..5d82b0dc92 100644 --- a/progs/demos/ipers.c +++ b/progs/demos/ipers.c @@ -237,10 +237,27 @@ special(int k, int x, int y) } static void +cleanup(void) +{ + int i; + + glDeleteTextures(1, &t1id); + glDeleteTextures(1, &t2id); + + glDeleteLists(skydlist, 1); + for (i = 0; i < MAX_LOD; i++) { + glDeleteLists(LODdlist[i], 1); + glDeleteLists(LODnumpoly[i], 1); + } +} + + +static void key(unsigned char k, int x, int y) { switch (k) { case 27: + cleanup(); exit(0); break; @@ -707,6 +724,7 @@ main(int ac, char **av) glutIdleFunc(draw); glutMainLoop(); + cleanup(); return 0; } diff --git a/progs/demos/readpix.c b/progs/demos/readpix.c index c0aac2272f..bbb3a68eff 100644 --- a/progs/demos/readpix.c +++ b/progs/demos/readpix.c @@ -17,6 +17,7 @@ #define IMAGE_FILE "../images/girl.rgb" static int ImgWidth, ImgHeight; +static int WinWidth, WinHeight; static GLenum ImgFormat; static GLubyte *Image = NULL; @@ -27,6 +28,7 @@ static int CPosX, CPosY; /* copypixels */ static GLboolean DrawFront = GL_FALSE; static GLboolean ScaleAndBias = GL_FALSE; static GLboolean Benchmark = GL_FALSE; +static GLboolean Triangle = GL_FALSE; static GLubyte *TempImage = NULL; #define COMBO 1 @@ -150,11 +152,60 @@ Display( void ) /* draw original image */ glRasterPos2i(APosX, 5); PrintString("Original"); - glRasterPos2i(APosX, APosY); - glEnable(GL_DITHER); - SetupPixelTransfer(GL_FALSE); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image); + if (!Triangle) { + glRasterPos2i(APosX, APosY); + glEnable(GL_DITHER); + SetupPixelTransfer(GL_FALSE); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image); + } + else { + float z = 0; + + glViewport(APosX, APosY, ImgWidth, ImgHeight); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); + glDisable(GL_CULL_FACE); + + /* Red should never be seen + */ + glBegin(GL_POLYGON); + glColor3f(1,0,0); + glVertex3f(-2, -2, z); + glVertex3f(-2, 2, z); + glVertex3f(2, 2, z); + glVertex3f(2, -2, z); + glEnd(); + + /* Blue background + */ + glBegin(GL_POLYGON); + glColor3f(.5,.5,1); + glVertex3f(-1, -1, z); + glVertex3f(-1, 1, z); + glVertex3f(1, 1, z); + glVertex3f(1, -1, z); + glEnd(); + + /* Triangle + */ + glBegin(GL_TRIANGLES); + glColor3f(.8,0,0); + glVertex3f(-0.9, -0.9, z); + glColor3f(0,.9,0); + glVertex3f( 0.9, -0.9, z); + glColor3f(0,0,.7); + glVertex3f( 0.0, 0.9, z); + glEnd(); + + glColor3f(1,1,1); + + glViewport( 0, 0, WinWidth, WinHeight ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( 0.0, WinWidth, 0.0, WinHeight, -1.0, 1.0 ); + } /* might try alignment=4 here for testing */ glPixelStorei(GL_UNPACK_ALIGNMENT, 1); @@ -218,6 +269,9 @@ Display( void ) static void Reshape( int width, int height ) { + WinWidth = width; + WinHeight = height; + glViewport( 0, 0, width, height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); @@ -236,6 +290,9 @@ Key( unsigned char key, int x, int y ) case 'b': Benchmark = GL_TRUE; break; + case 't': + Triangle = !Triangle; + break; case 's': ScaleAndBias = !ScaleAndBias; break; diff --git a/progs/demos/shadowtex.c b/progs/demos/shadowtex.c index f10a01ec26..dc5a4bbc48 100644 --- a/progs/demos/shadowtex.c +++ b/progs/demos/shadowtex.c @@ -788,6 +788,7 @@ Key(unsigned char key, int x, int y) exit(0); break; } + fflush(stdout); glutPostRedisplay(); } @@ -1014,6 +1015,7 @@ PrintHelp(void) printf(" <shift> + cursor keys = rotate light source\n"); if (HaveEXTshadowFuncs) printf(" o = cycle through comparison modes\n"); + fflush(stdout); } diff --git a/progs/demos/teapot.c b/progs/demos/teapot.c index 38ede7ac3e..6bf6e06409 100644 --- a/progs/demos/teapot.c +++ b/progs/demos/teapot.c @@ -173,10 +173,20 @@ static void special(int k, int x, int y) } } +static void cleanup(void) +{ + glDeleteTextures(1, &t1id); + glDeleteTextures(1, &t2id); + glDeleteLists(teapotdlist, 1); + glDeleteLists(basedlist, 1); + glDeleteLists(lightdlist, 1); +} + static void key(unsigned char k, int x, int y) { switch(k) { case 27: + cleanup(); exit(0); break; @@ -670,6 +680,7 @@ int main(int ac, char **av) glutIdleFunc(draw); glutMainLoop(); + cleanup(); return 0; } diff --git a/progs/demos/tunnel.c b/progs/demos/tunnel.c index 6a240580e8..6981da3298 100644 --- a/progs/demos/tunnel.c +++ b/progs/demos/tunnel.c @@ -203,10 +203,18 @@ special(int k, int x, int y) } static void +cleanup(void) +{ + glDeleteTextures(1, &t1id); + glDeleteTextures(1, &t2id); +} + +static void key(unsigned char k, int x, int y) { switch (k) { case 27: + cleanup(); exit(0); break; @@ -531,5 +539,6 @@ main(int ac, char **av) glutMainLoop(); + cleanup(); return 0; } diff --git a/progs/demos/tunnel2.c b/progs/demos/tunnel2.c index f4171a8346..0288ea0f8c 100644 --- a/progs/demos/tunnel2.c +++ b/progs/demos/tunnel2.c @@ -201,12 +201,20 @@ special(int k, int x, int y) } static void +cleanup(void) +{ + glDeleteTextures(1, &t1id); + glDeleteTextures(1, &t2id); +} + +static void key(unsigned char k, int x, int y) { switch (k) { case 27: glutDestroyWindow(channel[0]); glutDestroyWindow(channel[1]); + cleanup(); exit(0); break; @@ -602,6 +610,7 @@ main(int ac, char **av) calcposobs(); glutMainLoop(); + cleanup(); return 0; } diff --git a/progs/demos/vao_demo.c b/progs/demos/vao_demo.c index ce416712fe..206e06fc6c 100644 --- a/progs/demos/vao_demo.c +++ b/progs/demos/vao_demo.c @@ -260,6 +260,8 @@ static void Key( unsigned char key, int x, int y ) (void) y; switch (key) { case 27: + (*delete_vertex_arrays)( 1, & cube_array_obj ); + (*delete_vertex_arrays)( 1, & oct_array_obj ); glutDestroyWindow(Win); exit(0); break; diff --git a/progs/redbook/polyoff.c b/progs/redbook/polyoff.c index 2017b4d8ee..de34b2e767 100644 --- a/progs/redbook/polyoff.c +++ b/progs/redbook/polyoff.c @@ -153,6 +153,7 @@ static void Benchmark( float xdiff, float ydiff ) double seconds, fps; printf("Benchmarking...\n"); + fflush(stdout); draws = 0; startTime = glutGet(GLUT_ELAPSED_TIME); @@ -169,6 +170,7 @@ static void Benchmark( float xdiff, float ydiff ) seconds = (double) (endTime - startTime) / 1000.0; fps = draws / seconds; printf("Result: fps: %g\n", fps); + fflush(stdout); } @@ -263,6 +265,7 @@ void keyboard (unsigned char key, int x, int y) default: break; } + fflush(stdout); } static void diff --git a/progs/tests/.gitignore b/progs/tests/.gitignore index e6369de3ab..959ddcc51f 100644 --- a/progs/tests/.gitignore +++ b/progs/tests/.gitignore @@ -16,22 +16,20 @@ blendminmax blendsquare blendxor bufferobj -bumpmap bug_3050 bug_3101 bug_3195 bug_texstore_i8 +bumpmap calibrate_rast copypixrate crossbar cva -dinoshade drawbuffers extfuncs.h exactrast fbotest1 fbotest2 -fbotexture fillrate floattex fog @@ -40,6 +38,7 @@ fptest1 fptexture getprocaddress getproclist.h +glutfx interleave invert jkrahntest @@ -49,6 +48,7 @@ mapbufrange mapvbo minmag mipgen +mipmap_comp mipmap_limits mipmap_view multipal @@ -56,7 +56,6 @@ no_s3tc packedpixels pbo prog_parameter -projtex quads random readrate @@ -64,22 +63,22 @@ readtex.c readtex.h rubberband seccolor -sharedtex shader_api shaderutil.c shaderutil.h +sharedtex stencil_twoside -stencil_wrap stencilwrap stencil_wrap +streaming_rect subtex subtexrate tex1d -texcmp texcompress2 +texdown texfilt -texgenmix texline +texobj texobjshare texrect texwrap diff --git a/progs/tests/Makefile b/progs/tests/Makefile index f5fbf374f7..628ca41535 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -58,6 +58,7 @@ SOURCES = \ mapvbo.c \ minmag.c \ mipgen.c \ + mipmap_comp.c \ mipmap_limits.c \ mipmap_view.c \ multipal.c \ diff --git a/progs/tests/SConscript b/progs/tests/SConscript index 4f22ca735c..453fcecd9c 100644 --- a/progs/tests/SConscript +++ b/progs/tests/SConscript @@ -81,6 +81,7 @@ progs = [ 'mapvbo', 'minmag', 'mipgen', + 'mipmap_comp', 'mipmap_limits', 'mipmap_view', 'multipal', diff --git a/progs/tests/floattex.c b/progs/tests/floattex.c index dd99d836c6..ad14cacdcb 100644 --- a/progs/tests/floattex.c +++ b/progs/tests/floattex.c @@ -1,6 +1,5 @@ /* * Test floating point textures. - * No actual rendering, yet. */ @@ -103,7 +102,6 @@ Key(unsigned char key, int x, int y) } - static void InitTexture(void) { @@ -141,6 +139,8 @@ InitTexture(void) GL_RGB, GL_FLOAT, ftex); + CheckError(__LINE__); + /* sanity checks */ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_TYPE_ARB, &t); assert(t == GL_FLOAT); @@ -152,32 +152,26 @@ InitTexture(void) assert(t == GL_FLOAT); free(image); - free(ftex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); -#if 0 - /* read back the texture and make sure values are correct */ - glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, tex2); - CheckError(__LINE__); - for (i = 0; i < 16; i++) { - for (j = 0; j < 16; j++) { - if (tex[i][j][0] != tex2[i][j][0] || - tex[i][j][1] != tex2[i][j][1] || - tex[i][j][2] != tex2[i][j][2] || - tex[i][j][3] != tex2[i][j][3]) { - printf("tex[%d][%d] %g %g %g %g != tex2[%d][%d] %g %g %g %g\n", - i, j, - tex[i][j][0], tex[i][j][1], tex[i][j][2], tex[i][j][3], - i, j, - tex2[i][j][0], tex2[i][j][1], tex2[i][j][2], tex2[i][j][3]); + if (1) { + /* read back the texture and make sure values are correct */ + GLfloat *tex2 = (GLfloat *) + malloc(imgWidth * imgHeight * 4 * sizeof(GLfloat)); + glGetTexImage(GL_TEXTURE_2D, 0, imgFormat, GL_FLOAT, tex2); + CheckError(__LINE__); + for (i = 0; i < imgWidth * imgHeight * 4; i++) { + if (ftex[i] != tex2[i]) { + printf("tex[%d] %g != tex2[%d] %g\n", + i, ftex[i], i, tex2[i]); } } } -#endif + + free(ftex); } @@ -193,7 +187,9 @@ CreateProgram(void) assert(program); - // InitUniforms(program, Uniforms); + glUseProgram_func(program); + + InitUniforms(program, Uniforms); return program; } @@ -211,8 +207,9 @@ Init(void) exit(1); } - if (!glutExtensionSupported("GL_MESAX_texture_float")) { - printf("Sorry, this test requires GL_MESAX_texture_float\n"); + if (!glutExtensionSupported("GL_MESAX_texture_float") && + !glutExtensionSupported("GL_ARB_texture_float")) { + printf("Sorry, this test requires GL_MESAX/ARB_texture_float\n"); exit(1); } diff --git a/progs/tests/mipmap_comp.c b/progs/tests/mipmap_comp.c new file mode 100644 index 0000000000..5842e2b880 --- /dev/null +++ b/progs/tests/mipmap_comp.c @@ -0,0 +1,295 @@ +/* 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. + */ + +/* mipmap_comp + * Test compressed texture mipmaps + * + * Based on mipmap_limits + */ + +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <GL/glew.h> +#include <GL/glut.h> + +#include "readtex.h" + +#define SIZE 16 /* not larger then 16 */ + +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; + + +static void +initValues(void) +{ + BaseLevel = 0; + MaxLevel = 9; + MinLod = -1; + MaxLod = 2; + LodBias = 5.0; + NearestFilter = GL_TRUE; +} + + +static void +makeImage(int level, int width, int height) +{ +#if 0 + GLubyte img[SIZE*SIZE*3]; + int i, j; + + (void)size; + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + int k = (i * width + j) * 3; + img[k + 0] = 255 * ((level + 1) % 2); + img[k + 1] = 255 * ((level + 1) % 2); + img[k + 2] = 255 * ((level + 1) % 2); + } + } + + glTexImage2D(GL_TEXTURE_2D, level, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, width, height, 0, + GL_RGB, GL_UNSIGNED_BYTE, img); +#else + GLubyte img[128]; + GLint size[] = { + 128, /* 16x16 */ + 32, /* 8x8 */ + 8, /* 4x4 */ + 8, /* 2x2 */ + 8, /* 1x1 */ + }; + int i; + int value = ((level + 1) % 2) * 0xffffffff; + memset(img, 0, 128); + + /* generate black and white mipmap levels */ + if (value) + for (i = 0; i < size[level] / 4; i += 2) + ((int*)img)[i] = value; + + glCompressedTexImage2D(GL_TEXTURE_2D, level, + GL_COMPRESSED_RGB_S3TC_DXT1_EXT, + width, height, 0, + size[level], img); +#endif +} + + +static void +makeImages(void) +{ + int i, sz; + + for (i = 0, sz = SIZE; sz >= 1; i++, sz /= 2) { + makeImage(i, sz, sz); + printf("Level %d size: %d x %d\n", i, sz, sz); + } +} + + +static void +myInit(void) +{ + + initValues(); + + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + glShadeModel(GL_FLAT); + + glTranslatef(0.0, 0.0, -3.6); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glGenTextures(1, &texImage); + glBindTexture(GL_TEXTURE_2D, texImage); + 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); +} + + +static void +display(void) +{ + GLfloat tcm = 1.0; + glBindTexture(GL_TEXTURE_2D, texImage); + + 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(); +} + + +static void +key(unsigned char k, int x, int y) +{ + (void) x; + (void) y; + switch (k) { + case 'b': + BaseLevel--; + if (BaseLevel < 0) + BaseLevel = 0; + break; + case 'B': + BaseLevel++; + if (BaseLevel > 10) + BaseLevel = 10; + break; + case 'm': + MaxLevel--; + if (MaxLevel < 0) + MaxLevel = 0; + break; + case 'M': + MaxLevel++; + if (MaxLevel > 10) + MaxLevel = 10; + break; + case 'l': + LodBias -= 0.25; + break; + case 'L': + LodBias += 0.25; + break; + case 'n': + MinLod -= 0.25; + break; + case 'N': + MinLod += 0.25; + break; + case 'x': + MaxLod -= 0.25; + break; + case 'X': + MaxLod += 0.25; + break; + case 'f': + NearestFilter = !NearestFilter; + break; + case ' ': + initValues(); + break; + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + + +static void +usage(void) +{ + printf("usage:\n"); + printf(" b/B decrease/increase GL_TEXTURE_BASE_LEVEL\n"); + printf(" m/M decrease/increase GL_TEXTURE_MAX_LEVEL\n"); + printf(" n/N decrease/increase GL_TEXTURE_MIN_LOD\n"); + 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(" SPACE reset values\n"); +} + + +int +main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); + 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_view.c b/progs/tests/mipmap_view.c index 85fc67ac79..808d348699 100644 --- a/progs/tests/mipmap_view.c +++ b/progs/tests/mipmap_view.c @@ -18,12 +18,27 @@ #define TEXTURE_FILE "../images/arch.rgb" -static int TexWidth = 256, TexHeight = 256; +#define LEVELS 8 +#define SIZE (1<<LEVELS) +static int TexWidth = SIZE, TexHeight = SIZE; static int WinWidth = 1044, WinHeight = 900; static GLfloat Bias = 0.0; static GLboolean ScaleQuads = GL_FALSE; static GLboolean Linear = GL_FALSE; static GLint Win = 0; +static GLint RenderTextureLevel = 0; +static GLuint TexObj; + + + +static void +CheckError(int line) +{ + GLenum err = glGetError(); + if (err) { + printf("GL Error 0x%x at line %d\n", (int) err, line); + } +} @@ -37,6 +52,178 @@ PrintString(const char *s) } + + +static void +MipGenTexture( void ) +{ + /* 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 to TexWidth x TexHeight */ + if (width != TexWidth || height != TexHeight) { + GLubyte *newImage = malloc(TexWidth * TexHeight * 4); + + fprintf(stderr, "rescale %d %d to %d %d\n", width, height, + TexWidth, TexHeight); + fflush(stderr); + + gluScaleImage(format, width, height, GL_UNSIGNED_BYTE, image, + TexWidth, TexHeight, 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, TexWidth, TexHeight, 0, + format, GL_UNSIGNED_BYTE, image); + free(image); + + /* make sure mipmap was really generated correctly */ + width = TexWidth; + height = TexHeight; + for (i = 0; i < 9; 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); + assert(w == width); + assert(h == height); + width /= 2; + height /= 2; + } + + + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_FALSE); +} + + + +static void +ResetTextureLevel( int i ) +{ + GLubyte tex2d[SIZE*SIZE][4]; + + { + GLint Width = TexWidth / (1 << i); + GLint Height = TexHeight / (1 << i); + GLint s, t; + + for (s = 0; s < Width; s++) { + for (t = 0; t < Height; t++) { + tex2d[t*Width+s][0] = ((s / 16) % 2) ? 0 : 255; + tex2d[t*Width+s][1] = ((t / 16) % 2) ? 0 : 255; + tex2d[t*Width+s][2] = 128; + tex2d[t*Width+s][3] = 255; + } + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glTexImage2D(GL_TEXTURE_2D, i, GL_RGB, Width, Height, 0, + GL_RGBA, GL_UNSIGNED_BYTE, tex2d); + } +} + + +static void +ResetTexture( void ) +{ +#if 0 + /* This doesn't work so well as the arch texture is 512x512. + */ + LoadRGBMipmaps(TEXTURE_FILE, GL_RGB); +#else + { + int i; + + for (i = 0; i <= LEVELS; i++) + { + ResetTextureLevel(i); + } + } +#endif +} + + + + + + + +static void +RenderTexture( void ) +{ + GLenum status; + GLuint MyFB; + + fprintf(stderr, "RenderTextureLevel %d\n", RenderTextureLevel); + fflush(stderr); + + /* 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, + GL_TEXTURE_2D, TexObj, + RenderTextureLevel); + + + + CheckError(__LINE__); + + + 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); + + status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + printf("Framebuffer incomplete!!!\n"); + } + + glViewport(0, 0, + TexWidth / (1 << RenderTextureLevel), + TexHeight / (1 << RenderTextureLevel)); + + 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); + CheckError(__LINE__); + + glDeleteFramebuffersEXT(1, &MyFB); + CheckError(__LINE__); + + glClearColor(0, 0, 0, 0); +} + static void Display(void) { @@ -44,6 +231,8 @@ Display(void) char str[100]; int texWidth = TexWidth, texHeight = TexHeight; + glViewport(0, 0, WinHeight, WinHeight); + glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); @@ -126,7 +315,6 @@ Reshape(int width, int height) { WinWidth = width; WinHeight = height; - glViewport(0, 0, width, height); } @@ -145,6 +333,21 @@ Key(unsigned char key, int x, int y) case 'l': Linear = !Linear; break; + case 'v': + RenderTextureLevel++; + break; + case 'V': + RenderTextureLevel--; + break; + case 'r': + RenderTexture(); + break; + case 'X': + ResetTexture(); + break; + case 'x': + ResetTextureLevel(RenderTextureLevel); + break; case '0': case '1': case '2': @@ -160,6 +363,14 @@ Key(unsigned char key, int x, int y) case 's': ScaleQuads = !ScaleQuads; break; + case ' ': + MipGenTexture(); + Bias = 0; + Linear = 0; + RenderTextureLevel = 0; + ScaleQuads = 0; + break; + case 27: glutDestroyWindow(Win); exit(0); @@ -186,53 +397,13 @@ Init(void) glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - if (1) { - /* 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 to TexWidth x TexHeight */ - if (width != TexWidth || height != TexHeight) { - GLubyte *newImage = malloc(TexWidth * TexHeight * 4); - gluScaleImage(format, width, height, GL_UNSIGNED_BYTE, image, - TexWidth, TexHeight, 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, TexWidth, TexHeight, 0, - format, GL_UNSIGNED_BYTE, image); - free(image); - - /* make sure mipmap was really generated correctly */ - width = TexWidth; - height = TexHeight; - for (i = 0; i < 9; 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); - assert(w == width); - assert(h == height); - width /= 2; - height /= 2; - } - } - else { - if (LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { - printf("Using gluBuildMipmaps()\n"); - } - else { - printf("Error: could not load texture image %s\n", TEXTURE_FILE); - exit(1); - } - } + glGenTextures(1, &TexObj); + glBindTexture(GL_TEXTURE_2D, TexObj); + if (1) + MipGenTexture(); + else + ResetTexture(); /* mipmapping required for this extension */ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index 69c71cbaf6..22de83fa79 100644 --- a/progs/trivial/Makefile +++ b/progs/trivial/Makefile @@ -30,6 +30,7 @@ SOURCES = \ fs-tri.c \ line-clip.c \ line-cull.c \ + line-flat.c \ line-smooth.c \ line-stipple-wide.c \ line-userclip-clip.c \ @@ -138,6 +139,7 @@ SOURCES = \ tristrip-flat.c \ tristrip.c \ vbo-drawarrays.c \ + vbo-noninterleaved.c \ vbo-drawelements.c \ vbo-drawrange.c \ vp-array.c \ @@ -145,6 +147,7 @@ SOURCES = \ vp-clip.c \ vp-line-clip.c \ vp-tri.c \ + vp-tri-invariant.c \ vp-tri-swap.c \ vp-tri-tex.c \ vp-tri-imm.c \ diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index 480630e210..9a1f3575bd 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -26,6 +26,7 @@ progs = [ 'fs-tri', 'line-clip', 'line-cull', + 'line-flat', 'line-smooth', 'line-stipple-wide', 'line-userclip-clip', @@ -134,6 +135,7 @@ progs = [ 'tristrip-flat', 'tristrip', 'vbo-drawarrays', + 'vbo-noninterleaved', 'vbo-drawelements', 'vbo-drawrange', 'vp-array', @@ -141,6 +143,7 @@ progs = [ 'vp-clip', 'vp-line-clip', 'vp-tri', + 'vp-tri-invariant', 'vp-tri-swap', 'vp-tri-tex', 'vp-tri-imm', diff --git a/progs/trivial/line-flat.c b/progs/trivial/line-flat.c new file mode 100644 index 0000000000..14f0ac0782 --- /dev/null +++ b/progs/trivial/line-flat.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF + * ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <GL/glut.h> + + +#define CI_OFFSET_1 16 +#define CI_OFFSET_2 32 + + +GLenum doubleBuffer; + +static void Init(void) +{ + fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + fflush(stderr); + + glClearColor(0.0, 0.0, 1.0, 0.0); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + glShadeModel(GL_FLAT); + + glBegin(GL_LINES); + glColor3f(0,0,.7); + glVertex3f( 0.9, -0.9, -30.0); + glColor3f(.8,0,0); + glVertex3f( 0.9, 0.9, -30.0); + + glColor3f(.8,0,0); + glVertex3f( 0.9, 0.9, -30.0); + glColor3f(0,.9,0); + glVertex3f(-0.9, 0.0, -30.0); + + + glColor3f(0,.9,0); + glVertex3f(-0.9, 0.0, -30.0); + glColor3f(0,0,.7); + glVertex3f( 0.9, -0.9, -30.0); + glEnd(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + fprintf(stderr, "%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); + + type = GLUT_RGB; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow(*argv) == GL_FALSE) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/trivial/vbo-noninterleaved.c b/progs/trivial/vbo-noninterleaved.c new file mode 100644 index 0000000000..0672ca50ff --- /dev/null +++ b/progs/trivial/vbo-noninterleaved.c @@ -0,0 +1,139 @@ +/* Basic VBO */ + +#include <assert.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glew.h> +#include <GL/glut.h> + + +struct { + GLfloat pos[4][4]; + GLfloat col[4][4]; +} verts = +{ + /* Position: a quad + */ + { + { 0.9, -0.9, 0.0, 1.0 }, + { 0.9, 0.9, 0.0, 1.0 }, + { -0.9, 0.9, 0.0, 1.0 }, + { -0.9, -0.9, 0.0, 1.0 }, + }, + + /* Color: all red + */ + { + { 1.0, 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 0.0, 1.0 }, + }, + + +}; + +GLuint arrayObj, elementObj; + +static void Init( void ) +{ + GLint errno; + GLuint prognum; + + static const char *prog1 = + "!!ARBvp1.0\n" + "MOV result.color, vertex.color;\n" + "MOV result.position, vertex.position;\n" + "END\n"; + + glGenProgramsARB(1, &prognum); + glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum); + glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(prog1), (const GLubyte *) prog1); + + assert(glIsProgramARB(prognum)); + errno = glGetError(); + printf("glGetError = %d\n", errno); + if (errno != GL_NO_ERROR) + { + GLint errorpos; + + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); + printf("errorpos: %d\n", errorpos); + printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + } + + + glEnableClientState( GL_VERTEX_ARRAY ); + glEnableClientState( GL_COLOR_ARRAY ); + + glGenBuffersARB(1, &arrayObj); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrayObj); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), &verts, GL_STATIC_DRAW_ARB); + + glVertexPointer( 4, GL_FLOAT, sizeof(verts.pos[0]), 0 ); + glColorPointer( 4, GL_FLOAT, sizeof(verts.col[0]), (void *)(4*4*sizeof(float)) ); + +} + + + +static void Display( void ) +{ + glClearColor(0.3, 0.3, 0.3, 1); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glEnable(GL_VERTEX_PROGRAM_ARB); + +// glDrawArrays( GL_TRIANGLES, 0, 3 ); +// glDrawArrays( GL_TRIANGLES, 1, 3 ); + glDrawArrays( GL_QUADS, 0, 4 ); + + glFlush(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + /*glTranslatef( 0.0, 0.0, -15.0 );*/ +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 250, 250 ); + glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH ); + glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} diff --git a/progs/trivial/vp-tri-invariant.c b/progs/trivial/vp-tri-invariant.c new file mode 100644 index 0000000000..ff24139365 --- /dev/null +++ b/progs/trivial/vp-tri-invariant.c @@ -0,0 +1,147 @@ +/* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glew.h> +#include <GL/glut.h> + + +#define CI_OFFSET_1 16 +#define CI_OFFSET_2 32 + + +GLenum doubleBuffer; + +static void Init(void) +{ + GLint errno; + GLuint prognum; + + static const char *prog1 = + "!!ARBvp1.0\n" + "OPTION ARB_position_invariant ;" + "MOV result.color, vertex.color;\n" + "END\n"; + + + glGenProgramsARB(1, &prognum); + + glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum); + glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(prog1), (const GLubyte *) prog1); + + errno = glGetError(); + printf("glGetError = %d\n", errno); + if (errno != GL_NO_ERROR) + { + GLint errorpos; + + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); + printf("errorpos: %d\n", errorpos); + printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + } + + fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + fflush(stderr); + + glClearColor(0.0, 0.0, 1.0, 0.0); +} + +static void Reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); +/* glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); */ + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glEnable(GL_VERTEX_PROGRAM_ARB); + + glBegin(GL_TRIANGLES); + glColor3f(0,0,.7); + glVertex3f( 0.9, -0.9, -0.0); + glColor3f(.8,0,0); + glVertex3f( 0.9, 0.9, -0.0); + glColor3f(0,.9,0); + glVertex3f(-0.9, 0.0, -0.0); + glEnd(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + fprintf(stderr, "%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); + + type = GLUT_RGB | GLUT_ALPHA; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow(*argv) == GL_FALSE) { + exit(1); + } + + glewInit(); + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} diff --git a/progs/xdemos/glxcontexts.c b/progs/xdemos/glxcontexts.c index a9ff326ed5..a97b62a908 100644 --- a/progs/xdemos/glxcontexts.c +++ b/progs/xdemos/glxcontexts.c @@ -385,6 +385,10 @@ draw( Display *dpy, Window win ) } else do_draw(); + glDeleteLists(gear1, 1); + glDeleteLists(gear2, 1); + glDeleteLists(gear3, 1); + glXSwapBuffers(dpy, win); glXDestroyContext(dpy, ctx); } |