Skip to main content
gamedev.net
🔒 Locked

Texture problem

Started by C3rial 2 replies 1k views
Original Post
C3rial
C3rial
When drawing only a background image (one big square from Z:-500 to Z:500) everything works just fine. But when I add a 3ds-model things get screwy. The model appears as it should, but the background image changes from the selected texture to whichever color the model has. code from the RenderScene function (I'm a newb, so bare with me please;)): void RenderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(camPosX,camPosY,camPosZ,camViewX,camViewY,camViewZ,camUpX,camUpY,camUpZ); glPushMatrix(); glDisable(GL_BLEND); static float trans = 0.0f; trans += 0.01f; glBindTexture(GL_TEXTURE_2D,landscape->getTexture()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glBegin(GL_QUADS); glTexCoord2f(-1,-1 + trans); glVertex3f(-500,-50,-500); glTexCoord2f(0,-1 + trans); glVertex3f(500,-50,-500); glTexCoord2f(0,0 + trans); glVertex3f(500,-50,500); glTexCoord2f(-1,0 + trans); glVertex3f(-500,-50,500); glEnd(); glEnable(GL_BLEND); glPopMatrix(); glTranslatef((camPosX-3),(camPosY-30),(camPosZ+50)); glPushMatrix(); glDisable(GL_BLEND); model->paint(); glEnable(GL_BLEND); glPopMatrix(); glutPostRedisplay(); glutSwapBuffers(); } Apprechiate any help I can get:)
CrazyPoly
Crisium
Crisium
I don't see any:

glEnable( GL_TEXTURE_2D );
or
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );

perhaps the model->paint() changes states for you, can't you post the code for that too?

http://osghelp.com - great place to get OpenScenGraph help
C3rial
C3rial
Sorry about that.
I've got the glEnable(GL_TEXTURE_2D); in the init function, and
I put the glTexEnvf in the init also (wasn't there before).

paint() function from the 3dsloader:

void GL3DS::paint()
{
setLights();
for(int i = 0; i< modell->nrOfObjects;i++)
{
if(modell->object_tab.visible)
{
setMaterial(i);
bool bmpFile = false;
if(modell->object_tab.hasTexture)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,modell->object_tab.texture);
bmpFile = true;
}
glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
glEnableClientState( GL_TEXTURE_COORD_ARRAY );

glVertexPointer( 3, GL_FLOAT, sizeof(vector3f), modell->object_tab.pol_vertex); // Set The Vertex Pointer To Our Vertex Data
glTexCoordPointer( 2, GL_FLOAT, sizeof(vector2f), modell->object_tab.pol_mapcoord );

glDrawArrays( GL_TRIANGLES, 0, modell->object_tab.polygon_count*3);

glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays
glDisableClientState( GL_TEXTURE_COORD_ARRAY );

glFlush();
glDisable(GL_TEXTURE_2D);
}
}
}



What's strange about it is that when I debug it, it looks as it should the first iteration, but second time around it's all white...
CrazyPoly
dpadam450
dpadam450
Is the BG image supposed to be lit? Cuz if not, just Disable(GL_LIGHTING);

Materials only affect objects with lighting. If it does need to be lit, before drawing the BG, make the color material all white, and that should probably work. Or just change your glTexGen from replace to the other options to see if that works. Replace I believe is replacing the texture with the material.

Again the first iteration, you draw the BG, then call material (settting everything after this to have a material).
NBA2K, Madden, Maneater, Killing Floor, Sims 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.