Jump to content
  • Advertisement

Archived

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

penetrator

binding textures

This topic is 5686 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 usually load textures during startup with a script like this: LoadTGA(&textures[1], "textures/etna.tga"); glBindTexture(GL_TEXTURE_2D, textures[1].texID); I want to "unbind" the current texture and load and bind a new one, so i call a function that does the same operation, just like this: LoadTGA(&textures[1], "textures/etna_new.tga"); glBindTexture(GL_TEXTURE_2D, textures[1].texID); but the new texture won''t work. I suppose there is a way to clear the texture buffer and fill it again

Share this post


Link to post
Share on other sites
Advertisement
I found this line in gl.h

WINGDIAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures);

aparently it deletes the texture and from the looks of it you use it like this.

glDeleteTextures(GL_TEXTURE_2D, textures[1].texID);

Normaly you wouldn''t even start to care about deleting the textures just load a new one like this.

LoadTGA(&textures[2], "textures/etna_new.tga");
glBindTexture(GL_TEXTURE_2D, textures[2].texID);

Share this post


Link to post
Share on other sites
i use to load a new texture just clicking on a key, i.e:

if (keys[''X''])
{
keys[''X'']=FALSE;
LoadTGA(&textures[2], "textures/currentmap.tga");
}

but texture is not loaded/displayed on the object, while if i run the loadtga at startup (i.e. in the initgl() ) it does work...

Share this post


Link to post
Share on other sites
i arrived to the point that i must load all my textures at startup, and switch the texture applied to one object like this:

if (texture_change==TRUE) glBindTexture(GL_TEXTURE_2D, textures[1].texID );
if (texture_change==FALSE) glBindTexture(GL_TEXTURE_2D, textures[2].texID );

but i''m sure there must be a way to load and apply texture at run-time ...

Share this post


Link to post
Share on other sites
also, if i try to delete a texture with:

glDeleteTextures(GL_TEXTURE_2D, textures[1].texID);

i get this compiler error:

error C2664: ''glDeleteTextures'' : cannot convert parameter 2 from ''unsigned int'' to ''const unsigned int *''

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Try this : glDeleteTextures (1, &textures[1].texID)

Share this post


Link to post
Share on other sites
Yes, infact that works, i forgot to point at the correct texture element. After deleting the texture, my teapot is grey again (i.e. no texture on it), so deleting the texture went ok. So i load a different tga file and i expect to see it on the teapot, but it keep to be still grey !?!
In practice this is the code:

glDeleteTextures(1, &textures[1].texID );
LoadTGA(&textures[1] , "textures/currentmap2.tga");

In the function that render the teapot, of course there is a line
glBindTexture(GL_TEXTURE_2D, textures[1].texID );

Share this post


Link to post
Share on other sites
I also tried to modify nehe''s code of lesson 33, thinking my code was totally screwed up, but the result is the same: deleting a texture and loading a new one doesn''t work, or better, it just delete the texture from memory, but the new one is not loaded. Any idea ?

Share this post


Link to post
Share on other sites
You still have to use glGenTextures (1, &textures[1].texID);
and setup your texture parameters again. Post all relevant code if that isn''t the problem.

_____________________________

And the Phoenix shall rise from the ashes...

--Thunder_Hawk -- ¦þ
______________________________

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!