Click to See Complete Forum and Search --> : problems with openGL textures (one changes, they all change)


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

delta_luca
May 31st, 2006, 07:08 AM
ok im rather confused, but i wont delete this thread, because it might be useful to someone else.

i changed my drawing code so that it looks like this


glEnable(GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D, bit->texnum );
glColor3f(1,1,1);
glBegin(GL_QUADS);
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);
;

note, that i now have the glBindTexture before glBegin, and suddnely everything is working fine.. could anyone give me a specific reason as to why this has fixed my problems? ive been trying to figure this out for a few days, and now ive just changed the order of the functions, and its worked...

Hobson
May 31st, 2006, 08:35 AM
from MSDN:


You can use only a subset of OpenGL functions between glBegin and glEnd. The functions you can use are:

glVertex
glColor
glIndex
glNormal
glTexCoord
glEvalCoord
glEvalPoint
glMaterial
glEdgeFlag

You can also use glCallList or glCallLists to execute display lists that include only the preceding functions. If any other OpenGL function is called between glBegin and glEnd, the error flag is set and the function is ignored.

delta_luca
May 31st, 2006, 08:58 AM
i see...