However I'm having some trouble understanding binding textures.
So at first I had great lag because of creating and destroying a new texture every time I needed to draw. I fixed this by creating only one texture of each image I need and re-using that texture to draw.
So I do something like this:
GLuint tex,tex2;
surface = IMG_Load("Images/Joe.png");
GShapes.CreateTexture(tex,surface);
surface2 = IMG_Load("Images/Shape2.png");
GShapes.CreateTexture(tex2,surface2);
//CreateTexture function is here:
void CreateTexture(GLuint texture,SDL_Surface* surface){
glGenTextures( 1, &texture );
glBindTexture( GL_TEXTURE_2D, texture );
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
assert(surface != NULL);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, (surface->w), (surface->h), 0,GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels );
}
And then if I proceed to draw without binding any texture, it will draw the last created texture. Makes sense.
However, if I call:
glBindTexture( GL_TEXTURE_2D, tex );
OR
glBindTexture( GL_TEXTURE_2D, tex2 );
Neither of the two PNG's appear. Just a white box.
Confused, I output tex and tex2, they are both 0's. Now if I manually bind "1" when I need tex, and bind "2" when I need tex2, it works. But aren't they supposed to store their values? I'm not sure what I'm doing wrong.
I mean I could make my own system to assign a number to each PNG I create, but I'd like to know how others do it.
Thanks in advance!






