PDA

View Full Version : Multitexture Crashes


Jake
2004.09.06, 01:57 PM
I am going to try to make a lightmap plus a detail texture for my terrain engine, and I can not get it to render without crashing. It just loads the window and then crashes with a signal 11 (I think it was 11). Here is my code -

EDIT : The 1 texture code works fine, so the data should be correct.

Render -

glDisable( GL_LIGHTING );

glActiveTextureARB( GL_TEXTURE0_ARB );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, gv->texture[4] );
// TEXTURE-UNIT #1:
glActiveTextureARB( GL_TEXTURE1_ARB );
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, gv->texture[5] );

for (j = 0; j < theQuadCount[i]; j++)
{
glMultiTexCoord2fARB( GL_TEXTURE0_ARB, (theVertex[theQuad[ i ][ j ].w]/1024.0), (theVertex[2+theQuad[ i ][ j ].w])/1024.0);
glMultiTexCoord2fARB( GL_TEXTURE1_ARB, theUV[theQuad[ i ][ j ].a]/div,theUV[1+theQuad[ i ][ j ].a]/div );
glVertex3f(theVertex[theQuad[ i ][ j ].w],theVertex[1+theQuad[ i ][ j ].w],theVertex[2+theQuad[ i ][ j ].w]);
glMultiTexCoord2fARB( GL_TEXTURE0_ARB, (theVertex[theQuad[ i ][ j ].x]/1024.0), (theVertex[2+theQuad[ i ][ j ].x])/1024.0);
glMultiTexCoord2fARB( GL_TEXTURE1_ARB, theUV[theQuad[ i ][ j ].b]/div,theUV[1+theQuad[ i ][ j ].b]/div );
glVertex3f(theVertex[theQuad[ i ][ j ].x],theVertex[1+theQuad[ i ][ j ].x],theVertex[2+theQuad[ i ][ j ].x]);
glMultiTexCoord2fARB( GL_TEXTURE0_ARB, (theVertex[theQuad[ i ][ j ].y]/1024.0), (theVertex[2+theQuad[ i ][ j ].y])/1024.0);
glMultiTexCoord2fARB( GL_TEXTURE1_ARB, theUV[theQuad[ i ][ j ].c]/div,theUV[1+theQuad[ i ][ j ].c]/div );
glVertex3f(theVertex[theQuad[ i ][ j ].y],theVertex[1+theQuad[ i ][ j ].y],theVertex[2+theQuad[ i ][ j ].y]);

glMultiTexCoord2fARB( GL_TEXTURE0_ARB, (theVertex[theQuad[ i ][ j ].z]/1024.0), (theVertex[2+theQuad[ i ][ j ].z])/1024.0);
glMultiTexCoord2fARB( GL_TEXTURE1_ARB, theUV[theQuad[ i ][ j ].d]/div,theUV[1+theQuad[ i ][ j ].d]/div );
glVertex3f(theVertex[theQuad[ i ][ j ].z],theVertex[1+theQuad[ i ][ j ].z],theVertex[2+theQuad[ i ][ j ].z]);
}
glEnd();

Load detail -
glBindTexture( GL_TEXTURE_2D, texture[ textureOn ] );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST );
gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB, size[textureOn], size[textureOn], GL_RGB,GL_UNSIGNED_BYTE, [imageRep[textureOn] bitmapData]);


Load lightmap -
glBindTexture(GL_TEXTURE_2D, texture[ textureOn ]);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
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_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D, 0, 3, size[textureOn],size[textureOn], 0, GL_RGB, GL_UNSIGNED_BYTE, [imageRep[textureOn] bitmapData]);

arekkusu
2004.09.06, 02:55 PM
Well, where does it crash? At glTexImage? Do you really want an RGB detail texture? Usually they are greyscale.

Jake
2004.09.06, 03:22 PM
It crashes on this line

glVertex3f(theVertex[theQuad[ i ][ j ].w],theVertex[1+theQuad[ i ][ j ].w],theVertex[2+theQuad[ i ][ j ].w]);, here are the threads -


#0 0x04bb1bd8 in gldDestroyQuery
#1 0x025bad5c in Stage3<true>::doIt(GLDContextRec*, Vertex const*, Vertex const*, Vertex const*, Vertex const*)
#2 0x02559d34 in Stage3<true>::doIt(GLDContextRec*, Vertex const*, Vertex const*, Vertex const*, Vertex const*)


The texture is just as much of a surface type map as a light map, if not more. It will be nice to have a surface map pre-calculated instead of doing lighting at runtime with normals.

arekkusu
2004.09.06, 03:29 PM
In that case, check your i and j; you're probably going past the end of your array.

Jake
2004.09.06, 03:33 PM
Everythinghad a value of 0x0, and I am sure thats not the problem because it is the same exact loop code as one right before it that works (the one that uses a single texture).

Also, this code started as the NeHe basecode, and I checked number 22 which uses bump map multitexturing and I am getting the same error symptoms, window shows for a second and then crashes.

Do I need to do any other setup to get the second texture unit to work?

arekkusu
2004.09.06, 04:10 PM
The OSX port of NeHe lesson 22 has obvious memory problems in -LoadGLTextures (it is using data after freeing it.) If you fix that, the multitexturing works fine.

There's no other setup you need to do besides turning on texturing and binding for each texture unit.

Jake
2004.09.06, 04:46 PM
Doh, I forgot a GL_Begin, it got deleted while I was changing the code.

EDIT : Fixed, Thanks!