Jump to content
  • Advertisement

Archived

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

zealouselixir

Freaky Weird Texture Problem

This topic is 6015 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

This is by far the weirdest OGL error I''ve ever had to deal with. Basically, when I try to load a texture, it winds up being overwritten - the texture ID of the newly loaded image is the same as a texture that was previously loaded and has not yet been removed from memory! I can hack-fix this by loading all the textures I need in the function they''re used in, ala
static bool Load = true;
if(Load)
{
    Load = false;
    Texture.Load("...");
} 
however, this method is ugly and inefficient, and I can''t just keep shifting stuff around. I first noticed this when my water texture was overwritten by a menu crosshair. I moved the water texture loading to the water drawing function using the method above, and it worked, but NOW, all my particles are being drawn as the crosshair! ARARRAHGHHGHGHHGHGGHGHHGGGGGGGGGGGG!!!! If anyone has had a problem like this, especially if you''ve found a solution, please help me out. Much appreciated. Peace, ZE. //email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[if you have a link proposal, email me.]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Post your texture loading code dude, that would help more than that little snippet. Sounds to me like you arent using glGenTextures()?

Share this post


Link to post
Share on other sites
Perhaps you arent using glBindTexture to change the active texture ID.

-----------------------
"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else''s drivers, I assume it is their fault" - John Carmack

Share this post


Link to post
Share on other sites

#include "texture.h"

bool CTexture::Load(char* file_name)
{
unsigned char *BitmapData;

glGenTextures(1, &ID);

BitmapData = LoadBitmap(file_name, Height, Width);

if(!BitmapData)
MessageBox(0, "No BMP data!", file_name, MB_OK);

glBindTexture(GL_TEXTURE_2D, ID);

glTexImage2D(GL_TEXTURE_2D, 0, 3, Width, Height, 0, GL_RGB, GL_UNSIGNED_BYTE, BitmapData);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

if(BitmapData)
delete [] BitmapData;

/*char TexInfo[80];
strcpy(TexInfo, file_name);
strcat(TexInfo, " - ");
sprintf(TexInfo+strlen(TexInfo), "%i", ID);

Popup(TexInfo);*/

if(ID)
return true;
else
return false;
}

void CTexture::Use()
{
glBindTexture(GL_TEXTURE_2D, ID);
}

CTexture::~CTexture()
{
if(ID)
glDeleteTextures(GL_TEXTURE_2D, &ID);
}


So far, both posters have assumed my stupidity. This is not a 30-second error, so don''t suggest that I''ve left out some fundamental call that''ll magically fix my code. I''m telling you, the texture ID is getting assigned to a NEW TEXTURE UPON LOADING without the original texture being deleted.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]

Share this post


Link to post
Share on other sites
Here's a log file.

data/models/ammobox/ammo.bmp - 1
data/fonts/trent.bmp - 2
data/level1/colormap.bmp - 3
data/particle/spark.bmp - 4
data/particle/spark_mask.bmp - 5
data/cut1/malygris.bmp - 6
data/cut1/zealous.bmp - 7
data/cut1/caffeine.bmp - 8
data/cut1/gamedev.bmp - 9
data/fonts/trent.bmp - 10
data/gui/main_menu.bmp - 1 // bad - ammo still in memory!
data/gui/cursor.bmp - 4 // bad - spark still in memory
data/level1/water.bmp - 6 // okay - malygris removed from memory
data/gui/gun2.bmp - 7 // okay - zealous removed from memory
data/gui/gun2mask.bmp - 8 // okay...
data/gui/hud.bmp - 9 // okay...
data/gui/hudmask.bmp - 10 // okay...
data/gui/crosshair.bmp - 11
data/gui/crosshairmask.bmp - 12
data/fonts/trent.bmp - 13


The question is - why are texture IDs being recycled when they still ought to be attached to a texture in memory?

[edited by - zealouselixir on May 30, 2002 1:15:57 PM]

Share this post


Link to post
Share on other sites
It looks like you pass in a file name when you create each texture, but you reuse the ID.

Edit:
Ok, you posted the log after I posted above. Doing some more thinking..

[edited by - yakuza on May 30, 2002 1:14:29 PM]

Share this post


Link to post
Share on other sites
I had the same error when I made a texture class. In mine, the cause was my Context::setTexture function, which, to avoid unnessary GL calls, checked the Context::s_currentTexture variable to see if this texture was already the current texture.

This broke when I was doing text output - I used glPushAttributes (I think that's what it's called...) to save various bits of state, including GL's current texture name. When I popped the attributes off again, GL's texture changed back, but Context::s_currentTexture, which was set to the font texture, did not. Now when I draw text again, it thinks the font texture is already bound, so it doesn't bother changing it.

I solved my problem by maintaining my own state stack in parallel to GL's, so that my texture pointer and GL's texture name are always in synch.

Although this doesn't sound quite like the problem you're experiencing, perhaps something similar is going on.

Just a quick comment on your code - you should probably check to see if glGenTextures failed right after you call it, rather than right at the end.

Looks like that isn't the problem, then...



Just Plain Wrong



[edited by - Mayrel on May 30, 2002 1:20:45 PM]

Share this post


Link to post
Share on other sites
quote:

glDeleteTextures(GL_TEXTURE_2D, &ID);



Just a thought, the prototype for this is:


void glDeleteTextures( sizei n, uint *textures );


Maybe it is killing more textures than you mean to (not sure what GL_TEXTURE_2D is defined to and I can''t be bothered to look right now).

Other than that, have you tried on other computers or using other drivers? possible crap drivers but I guess you must have tried OGL games and stuff which do this.

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!