-/* $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
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;
static GLuint LowPriorityCount = 0;
-
static void Idle( void )
{
Zrot += 1.0;
GLint i;
/* test residency */
+ if (0)
{
GLboolean b;
GLint i, resident;
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);
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();
}
}
+/*
+ * 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 )
{
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;
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);
}
}
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) {
else
glutIdleFunc(NULL);
break;
+ case 's':
+ Idle();
+ break;
case 'z':
Zrot -= step;
break;