Original Post
Hi! I've got some trouble with OpenGL recently. I am writing a Tetris clone, and it is working fine with Direct3D and SDL rendering. However, when using OpenGL, the _last_ loaded texture is not displayed. Its containing rectangle is there, but pure white. I tried changing the order, but every time, the texture in the last "loadfile" line is missing. FYI, texname and image are properties of the sprite_gl class. The loading routine: The drawing routine: Thanks in advance, Thunder
int sprite_gl::loadfile(char *picfile, SDL_Rect *surfrects, int rectnum)
{
SDL_Surface *img=IMG_Load(picfile);
if(!img)
{
printf("IMG_Load_RW failed: %s\n", IMG_GetError());
return -1;
}
image=img;
framenum=rectnum;
for(int i=0;i<framenum;i++)
{
framepos=surfrects;
}
glGenTextures(1,&texname);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, &texname);
glTexImage2D(GL_TEXTURE_2D, 0, 4, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
return 0;
}
int blitter_gl::draw(sprite *spr, int x, int y)
{
SDL_Rect src,dest;
SDL_Surface *image;
src=spr->getsrcrect();
image=spr->getimage();
glBindTexture(GL_TEXTURE_2D, spr->gettexname());
glBegin(GL_QUADS);
glTexCoord2f(((float)src.x/(float)image->w),((float)src.y/(float)image->h));
glVertex3f((float)x, (float)y, 0.0f);
glTexCoord2f((((float)src.x+(float)src.w)/(float)image->w),((float)src.y/(float)image->h));
glVertex3f(float(x+src.w),float(y) , 0.0f);
glTexCoord2f((((float)src.x+(float)src.w)/(float)image->w),(((float)src.y+(float)src.h)/(float)image->h));
glVertex3f(float(x+src.w),float(y+src.h), 0.0f);
glTexCoord2f(((float)src.x/(float)image->w),(((float)src.y+(float)src.h)/(float)image->h));
glVertex3f(float(x),float(y+src.h), 0.0f);
glEnd();
}