I'm making a sprite system for opengl; I can load the bitmaps (plural bitmaps, because there's an alpha mask) ok. I can make the quad ok. Then I render it. What is not ok is what happens when I try to draw other things on the screen. Even with an "alpha" component of 255 (completly on) weird things happen. For example, when I display a brown 16x16 quad after drawing a white rectangle, the white quad turns brown too. Here's the important parts of my code (tell me if there's something else I should include as important):
This is in my initalization code:
Code:
glOrtho(0,W-1,H-1,0,1,-1);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
W and H are the width and heigth of the screen, respectivly.
This is how I create the texture:
Code:
/*Make the texture*/
glGenTextures(1,&(f->tex));
glBindTexture(GL_TEXTURE_2D,f->tex);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,w,h,0,GL_RGBA,GL_UNSIGNED_BYTE,final_bmp);
w and h are the width and heigth of the texture, final_bmp is a pointer to the color+alpha chanel. f->tex is the tex id thingy.
Finally, I draw the texture like this:
Code:
glBindTexture(GL_TEXTURE_2D,f->tex);
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2i(x,y+f->h);
glTexCoord2f(1,0);
glVertex2i(x+f->w,y+f->h);
glTexCoord2f(1,1);
glVertex2i(x+f->w,y);
glTexCoord2f(0,1);
glVertex2i(x,y);
glEnd();
x and y are the positions on the screen; they are representative of the upper left corner of the texture. f->h and f->w are the heigth and width of the texture, respectivly.
Please help me. I'm really lost right now.