delta_luca
May 31st, 2006, 07:01 AM
in my program, i have a multitude of 'bitmap' objects containing data loaded from .bmp files, and i now have it so that an opengl texture is created for this bitmap, to be drawn to the screen later. however. im having problems that, whatever the last texture to be created was, is what every other texture is being drawn as.
This is a code snippet containing all the opengl code related to creating the textures from the bitmap data.
glGenTextures(1,&bit->texnum);
glBindTexture( GL_TEXTURE_2D, bit->texnum );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);
glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_NEARES );
glTexImage2D( GL_TEXTURE_2D, 0, 3, bit->renderbit.width, bit->renderbit.height, 0,GL_RGB, GL_UNSIGNED_BYTE, bit->renderbit.data );
delete [] bit->renderbit.data;
and this is the code relating to when i draw the quads with the texture
glEnable(GL_TEXTURE_2D);
glColor3f(1,1,1);
glBegin(GL_QUADS);
glBindTexture( GL_TEXTURE_2D, bit->texnum );
glTexCoord2d(0.0,1.0); glVertex2f(ww*xsca,-hh*ysca);
glTexCoord2d(1.0,1.0); glVertex2f((ww+float(bit->x2))*xsca,-hh*ysca);
glTexCoord2d(1.0,0.0); glVertex2f((ww+float(bit->x2))*xsca,-(hh+float(bit->y2))*ysca);
glTexCoord2d(0.0,0.0); glVertex2f(ww*xsca,-(hh+float(bit->y2))*ysca);
glEnd();
glDisable(GL_TEXTURE_2D);
now.. first of all, while all the textures are being created, GL_TEXTURE_2D has been enabled, and then disabled after all the textures are created. Ive already tryed some debugging relating to the texture name being stored in texnum of each bitmap, and it is a unique number that is being used in the drawing
but the problem is like this for example:
if i have two bitmap objects, for the first one i use the bitmap "hello.bmp" which is lets say a big red circle, and then for the second i use "hu.bmp" which is lets say a big blue square, such that the first code snippet is run for the first bitmap, and then for the second.
when drawing the quads with the corresponding bitmaps, both will be a big blue square
This is a code snippet containing all the opengl code related to creating the textures from the bitmap data.
glGenTextures(1,&bit->texnum);
glBindTexture( GL_TEXTURE_2D, bit->texnum );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);
glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_NEARES );
glTexImage2D( GL_TEXTURE_2D, 0, 3, bit->renderbit.width, bit->renderbit.height, 0,GL_RGB, GL_UNSIGNED_BYTE, bit->renderbit.data );
delete [] bit->renderbit.data;
and this is the code relating to when i draw the quads with the texture
glEnable(GL_TEXTURE_2D);
glColor3f(1,1,1);
glBegin(GL_QUADS);
glBindTexture( GL_TEXTURE_2D, bit->texnum );
glTexCoord2d(0.0,1.0); glVertex2f(ww*xsca,-hh*ysca);
glTexCoord2d(1.0,1.0); glVertex2f((ww+float(bit->x2))*xsca,-hh*ysca);
glTexCoord2d(1.0,0.0); glVertex2f((ww+float(bit->x2))*xsca,-(hh+float(bit->y2))*ysca);
glTexCoord2d(0.0,0.0); glVertex2f(ww*xsca,-(hh+float(bit->y2))*ysca);
glEnd();
glDisable(GL_TEXTURE_2D);
now.. first of all, while all the textures are being created, GL_TEXTURE_2D has been enabled, and then disabled after all the textures are created. Ive already tryed some debugging relating to the texture name being stored in texnum of each bitmap, and it is a unique number that is being used in the drawing
but the problem is like this for example:
if i have two bitmap objects, for the first one i use the bitmap "hello.bmp" which is lets say a big red circle, and then for the second i use "hu.bmp" which is lets say a big blue square, such that the first code snippet is run for the first bitmap, and then for the second.
when drawing the quads with the corresponding bitmaps, both will be a big blue square