Texture Error

Started by
12 comments, last by BitMaster 11 years, 9 months ago

oh sorry,
I found another. vertor operator [] returns a "reference" not an "int".

So my advice is to use a GLint* (int pointer) instead of vector<GLint>

example:
GLint* SpriteSheep = new GLint[nSize];
then
u can use uploadImage(image, SpriteSheet);


I would advice you to completely ignore that advice. Passing a vector element by reference to uploadImage (and then taking its address for glGenTextures) as in your original code was completely correct and the most natural and least error-prone way to do it. The problem was in the way you filled that vector (not counting possible other bugs in the code). I'm not completely sure what the standard says about passing a default constructed iterator to std::vector::insert but I assume that puts us in the happy land of undefined behavior.

For the way you use the vector I would suggest textures.resize(imagefiles.size()) instead of the wonky insert. If not, a short debugging session or an update of this thread with the current code and behavior should put you much closer to your goal.

I would also advise to take what else KhoaVN said with a lot of grains of salt. I freely admit being biased against excessive user of 1337-speak but at the very least the post I quoted is very much not helpful and shows a serious lack of understanding regarding the issues at hand.

There are two schools of thought about using glDeleteTextures. On the one hand, resources you allocated should be freed again. On the other hand the operating system will free all resources claimed by your application when it terminates. Freeing resources after you are done with them is only required if the program does something else for a while before terminating (for example loading another level, and then another). That said, for anything bigger you need to learn about proper resource management anyway, so why not start now in a project where it will not shoot you in the foot for a while?
Advertisement


I would also advise to take what else KhoaVN said with a lot of grains of salt. I freely admit being biased against excessive user of 1337-speak but at the very least the post I quoted is very much not helpful and shows a serious lack of understanding regarding the issues at hand.



@BitMaster: You're right. That's my fault.
@BeginGamer: Sorry for bad things.

For the way you use the vector I would suggest textures.resize(imagefiles.size()) instead of the wonky insert. If not, a short debugging session or an update of this thread with the current code and behavior should put you much closer to your goal.
[/quote]
Yes! You was absolutely right...

Though, I still have this problem of drawing both images.... It draws the background fine but not the sprite image...

I updated both the renderer and image upload with debug feed back. Usually, it tells me that it couldn't open the certain sprite file from IMG_LOAD.. Though, I have the filename correct and the format isn't wrong, it's just a simple png with transparent background. I even tested with a another sprite that work in another program I made just to make sure... The dlls are correct, because I just copy/paste from another working program.. So, I'm kind of scratching my head why it isn't working... I did test if my program receive the proper vertices and texvertices as well for the render function.. No errors was shown and had the positional values that I wanted..
How does "it tells me that it couldn't open the certain sprite file from IMG_LOAD"? What happens? Are both images PNG files? Because if not, the SDL Wiki entry of IMG_Load [1] suggests that PNG support requires the presence of both the PNG and ZLIB dynamic libraries.

[1] http://sdl.beuc.net/sdl.wiki/SDL_image

This topic is closed to new replies.

Advertisement