From 6cdf09749c31423b0237c2a4fa493944301b21af Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 23 Oct 2000 23:32:22 +0000 Subject: Put a white texel in each corner of each texture. Draw polygons using the texture's aspect ratio. The tdfx-3-0-0 texcoord bug is obvious with the -randomsize option. --- progs/tests/manytex.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/progs/tests/manytex.c b/progs/tests/manytex.c index be776249e1..06e67bdbcc 100644 --- a/progs/tests/manytex.c +++ b/progs/tests/manytex.c @@ -1,4 +1,4 @@ -/* $Id: manytex.c,v 1.1 2000/08/02 17:57:56 brianp Exp $ */ +/* $Id: manytex.c,v 1.2 2000/10/23 23:32:22 brianp Exp $ */ /* * test handling of many texture maps @@ -18,6 +18,7 @@ static GLint NumTextures = 20; static GLuint *TextureID = NULL; +static GLint *TextureWidth = NULL, *TextureHeight = NULL; static GLboolean *TextureResidency = NULL; static GLint TexWidth = 128, TexHeight = 128; static GLfloat Zrot = 0; @@ -30,7 +31,6 @@ static GLint Rows, Columns; static GLuint LowPriorityCount = 0; - static void Idle( void ) { Zrot += 1.0; @@ -45,6 +45,7 @@ static void Display( void ) GLint i; /* test residency */ + if (0) { GLboolean b; GLint i, resident; @@ -71,6 +72,11 @@ static void Display( void ) GLfloat x = col * spacing + spacing * 0.5; GLfloat y = row * spacing + spacing * 0.5; + GLfloat maxDim = (TextureWidth[i] > TextureHeight[i]) + ? TextureWidth[i] : TextureHeight[i]; + GLfloat w = TextureWidth[i] / maxDim; + GLfloat h = TextureHeight[i] / maxDim; + glPushMatrix(); glTranslatef(x, y, 0.0); glRotatef(Zrot, 0, 0, 1); @@ -78,10 +84,17 @@ static void Display( void ) glBindTexture(GL_TEXTURE_2D, TextureID[i]); glBegin(GL_POLYGON); +#if 0 glTexCoord2f(0, 0); glVertex2f(-1, -1); glTexCoord2f(1, 0); glVertex2f( 1, -1); glTexCoord2f(1, 1); glVertex2f( 1, 1); glTexCoord2f(0, 1); glVertex2f(-1, 1); +#else + glTexCoord2f(0, 0); glVertex2f(-w, -h); + glTexCoord2f(1, 0); glVertex2f( w, -h); + glTexCoord2f(1, 1); glVertex2f( w, h); + glTexCoord2f(0, 1); glVertex2f(-w, h); +#endif glEnd(); glPopMatrix(); } @@ -103,6 +116,17 @@ static void Reshape( int width, int height ) } +/* + * Return a random int in [min, max]. + */ +static int RandomInt(int min, int max) +{ + int i = rand(); + int j = i % (max - min + 1); + return min + j; +} + + static void Init( void ) { @@ -148,6 +172,15 @@ static void Init( void ) assert(TextureResidency); } + if (!TextureWidth) { + TextureWidth = (GLint *) malloc(sizeof(GLint) * NumTextures); + assert(TextureWidth); + } + if (!TextureHeight) { + TextureHeight = (GLint *) malloc(sizeof(GLint) * NumTextures); + assert(TextureHeight); + } + for (i = 0; i < NumTextures; i++) { GLubyte color[4]; GLubyte *texImage; @@ -162,11 +195,20 @@ static void Init( void ) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, 0.5F); if (RandomSize) { +#if 0 int k = (glutGet(GLUT_ELAPSED_TIME) % 7) + 2; TexWidth = 1 << k; TexHeight = 1 << k; +#else + TexWidth = 1 << RandomInt(2, 7); + TexHeight = 1 << RandomInt(2, 7); + printf("Random size of %3d: %d x %d\n", i, TexWidth, TexHeight); +#endif } + TextureWidth[i] = TexWidth; + TextureHeight[i] = TexHeight; + texImage = (GLubyte*) malloc(4 * TexWidth * TexHeight * sizeof(GLubyte)); assert(texImage); @@ -211,6 +253,16 @@ static void Init( void ) } } else { + /* Set corners to white */ + int k = 0; + texImage[k+0] = texImage[k+1] = texImage[k+2] = texImage[k+3] = 255; + k = (TexWidth - 1) * 4; + texImage[k+0] = texImage[k+1] = texImage[k+2] = texImage[k+3] = 255; + k = (TexWidth * TexHeight - TexWidth) * 4; + texImage[k+0] = texImage[k+1] = texImage[k+2] = texImage[k+3] = 255; + k = (TexWidth * TexHeight - 1) * 4; + texImage[k+0] = texImage[k+1] = texImage[k+2] = texImage[k+3] = 255; + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TexWidth, TexHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, texImage); if (LinearFilter) { @@ -243,6 +295,9 @@ static void Key( unsigned char key, int x, int y ) else glutIdleFunc(NULL); break; + case 's': + Idle(); + break; case 'z': Zrot -= step; break; -- cgit v1.2.3