Sign in to follow this  
C3rial

Texture problem

Recommended Posts

C3rial    113
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:)

Share this post


Link to post
Share on other sites
Crisium    100
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?

Share this post


Link to post
Share on other sites
C3rial    113
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[i].visible)
{
setMaterial(i);
bool bmpFile = false;
if(modell->object_tab[i].hasTexture)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,modell->object_tab[i].texture);
bmpFile = true;
}
glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
glEnableClientState( GL_TEXTURE_COORD_ARRAY );

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

glDrawArrays( GL_TRIANGLES, 0, modell->object_tab[i].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...

Share this post


Link to post
Share on other sites
dpadam450    2357
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).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this