Archived

This topic is now archived and is closed to further replies.

TempusElf

Binding Texture.... I don't get it

Recommended Posts

TempusElf    186
I have successfully loaded a windows bitmap as a texture in my little demo and it looks great... however, the only reason I was able to do this is because I was only using one texture and not binding it... I was just loading it and using glTexImage2D. Now I''d like to bind it to a ''name'' so that I can actually delete it when I''m done or maybe have more than one texture... so I add these two lines from just about every tutorial on the subject:
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
 
Now, when my object moves I get randomly moving black strips over the surface that is textured... when I comment out the glBindTexture, this problem goes away.. I don''t get it... how could attempting to bind the texture cause this problem? Here is my code for loading the texture:
void LoadTexture()
{
	TextureTest = (HBITMAP)LoadImage(0,
					"tex1.bmp",
					IMAGE_BITMAP,
					0, 0,
					LR_LOADFROMFILE | LR_CREATEDIBSECTION);
	GLvoid * Pixels;
	BITMAP bmpTex;
	GetObject(TextureTest, sizeof(BITMAP), &bmpTex);
	Pixels = bmpTex.bmBits;


	glPixelStorei(GL_UNPACK_ALIGNMENT, 8);//needed for windows bitmaps


	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	//GLuint textures[1]; //moved to global

	glGenTextures(1, &texture[0]);
	glBindTexture(GL_TEXTURE_2D, texture[0]); //when I comment out this line it works just fine... however clearly not bound


	/*This is for debugging
	the message has been showing up so I know it is being
	generated, correct?*/
	if (glIsTexture(texture[0])==GL_TRUE)
	{
		MessageBox(NULL, "texture was generated", "supposedly", MB_OK);
	}
   
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bmpTex.bmWidth, bmpTex.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, Pixels);
	
	DeleteObject(TextureTest); //release from system ram

}
My texture is 64x64 and I''m using MingW... does anyone have any clue why this would happen?

Share this post


Link to post
Share on other sites