Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

thesleeper

problem with texture colors

This topic is 5272 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have a textured heightmap and a number of textured objects moving over it..the textures for both are loaded correctly but the color of the texture for my heightmap(terrain) seems to effect the color of the objects..does anybody know the possible cause for this???.. one man army guns cant harm me

Share this post


Link to post
Share on other sites
Advertisement
Are you using multi texturing on the terrain and not on the objects? If you are you may be leaving the second unit switched on, but with a single texture coordinate, thus changing the colour of the object.

Share this post


Link to post
Share on other sites
thank you all for replies..)
what i am doing is that,i use single textures for both objects(.rgb) and the terrain(.bmp)..here is the code for terrain:
// Function : compile_height_field
// Purpose : OpenGL call list to render height field
//
void compile_height_field( void )
{
float f1, f2, f3;
int x,z;
listid=glGenLists(1);
glNewList(listid,GL_COMPILE);
LoadGLTextures();
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glBegin(GL_TRIANGLE_STRIP);
for(x = 0; x < AREA_SIZE-step; x+=step)
{
for(z = 0; z < AREA_SIZE-step; z+=step)
{
f1 = F*(x+step);
f2 = F*height_field[x+step][z];
f3 = F*z;
glTexCoord2f(f1/100, f3/100);
glVertex3f(f1, f2, f3);
f1 = F*x;
f2 = F*height_field[x][z];
f3 = F*z;
glTexCoord2f(f1/100, f3/100);
glVertex3f(f1, f2, f3);
}
}
glEnd();
glEndList();
}

// Function : render_height_field
// Purpose : Call OpenGL call list to render height field
//
void render_height_field( void )
{

glPushMatrix();
glScalef(2.1,1,1.5);
glTranslatef(-76,-19,0);
glCallList(listid);
glPopMatrix();

}

i call the compile_height_field function in my initGL() method and i call the render_height_field function in my displayfunction..when i comment the render_height_field() line in my display function and keep the compile_height_field() line in my initGL function,objects are rendered completely correct..

in the original code part of the textures for objects are correct but some part of them are the same as the terrain''s texture..
here is the code for loading the objects texture and mapping:
Prototype int ac_load_texture(char *name)
{
int id = ac_load_rgb_image(name);
if (id > -1)
{
ACImage *i = ac_get_texture(id);


glBindTexture(GL_TEXTURE_2D, id);

gluBuild2DMipmaps(GL_TEXTURE_2D,
i->depth, i->width, i->height,
(i->depth==1)?GL_LUMINANCE:
(i->depth==2)?GL_LUMINANCE_ALPHA:
(i->depth==3)?GL_RGB:
GL_RGBA,
GL_UNSIGNED_BYTE,
i->data);
}
return(id);
}

one man army
guns cant harm me

Share this post


Link to post
Share on other sites
It''s hard to tell what exactly is the problem without having the whole source,beacause I don''t know if there is something you have omitted.Since you have trouble with textures and only when you call the list for the terrain,the problem must be:

1)LoadGLTextures();
Why is this INSIDE the list?If the function contains any gl calls,those calls will be executing each time you render the terrain.Since this function obviously loads textures,there is no need to have it inside the list.
2)glTexImage2D()
Same as the above:Why is it inside the list?It only has to execute once.Put it outside of the list.Just bind to a texture object for the terrain,load the texture into VRAM and that''s it.
3)glBindTexture()
Ok,this probably has to be in the list(in addition,it has to be outside too,as i described in 2).Just check if you use glGenTextures to load the value into texture[0](and any other texture object).

Share this post


Link to post
Share on other sites
thanks mike..i have taken them all out of the list and now objects load perfectly..but now the terrain has the same texture as the objects..i think the problem is with the ids given to textures..i will now debug it all over to see..

Share this post


Link to post
Share on other sites
ok..problem solved..it is about binding the texture..while loading the objects glBindTexture binds GL_TEXTURE_2D to the objects texture..so when i render the terrain that texture is used..i have fixed it by calling glBindTexture at the beginning of render_terrain function..

but i admit that opengl codes are a little bit hard to reverse engineer..i swear to the god of graphics that i will learn opengl if i successfully finish this project by the deadline..

one man army
guns cant harm me

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!