PDA

View Full Version : problem with selecting multiple textures



jono_123
10-04-2003, 11:41 AM
hi there
i want to have more than one texture in my program but the problem is that no matter which one i bind before drawing it always uses the texture that i built last here is my code :

GLuint texture[2];///space for 2 textures

...//in my initilization function
glEnable(GL_TEXTURE_2D);
...

void GenerateTexture(void) {
glGenTextures(2,&texture[0]);

HBITMAP hBMP;
BITMAP BMP;
byte crosshairtex[] = { IDB_CROSSHAIRMASK1 };
hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL),MAKE INTRESOURCE(crosshairtex[0]),IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);

glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST_MIPMAP_NEAREST);

gluBuild2DMipmaps(GL_TEXTURE_2D, 3,mesh.texsizex,mesh.texsizey, GL_RGB, GL_UNSIGNED_BYTE, mesh.texdata);

if (hBMP) {
GetObject(hBMP,sizeof(BMP), &BMP);
glPixelStorei(GL_UNPACK_ALIGNMENT,4);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, BMP.bmWidth, BMP.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);
DeleteObject(hBMP);
}

if(mesh.texdata)
free(mesh.texdata);
}

...//in my drawscene function
glBindTexture(GL_TEXTURE_2D,texture[0]);// here is the problem. what nomatter what i do here it always selects the same texture. what am i doing wrong?
DrawObject();
...

jono_123
10-06-2003, 09:44 PM
oh its ok i found the problem , it was that i didnt bind the texture outside of the the glBegin and glEnd block