Jump to content
  • Advertisement
Sign in to follow this  
HugoSoaresBr

OpenGL Problem with Textures

This topic is 3638 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, what's up? I've searched for my problem's solution, but I'm kind stucked. See... I am loading different Textures from different Bitmap files, but it seems that the only avaiable texture is the last loaded... I don't know where i am messing up, if you guys can give me a hand it would be nice... here's the code:
bool LoadGLTexture(char *fileName, GLuint &textBox)
{
	Bitmap *image	=	new Bitmap();
	
	if(image==NULL) {
		return false;
	}
        // Loads the img data to image->data
	if (image->loadBMP(fileName)) {
		glGenTextures(1, &textBox); 
		glBindTexture(GL_TEXTURE_2D, textBox);

		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, image->width, image->height, 0, 
					GL_RGB, GL_UNSIGNED_BYTE, image->data);
		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 
			image->width, 
			image->height, GL_RGB, GL_UNSIGNED_BYTE, image->data);
	}
	else {
		return false;
	}

	if (image) {
		delete image;
	}

	return true;
}
I think this should work like this: opengl would make a unique id and store it textBox, after that, you only have to call glBindTexture(GL_TEXTURE_2D, textureId) to select each texture previously loaded. Where am i messing up?

Share this post


Link to post
Share on other sites
Advertisement
As far as i can tell that code looks correct. Check the identifiers returned by glGenTextures, also be sure that you have valid GL context at the time you call the function. Other than that, i would look for error somewhere else.

Share this post


Link to post
Share on other sites
Ok, let's say that everything is ok and that we have 2 uint text1 and text2, each one "pointing" to an unique texture.

would we draw like this:

void renderFrame()
{
glColor3f(1.0f, 1.0f, 1.0f);

glBegin(GL_QUADS);

glBindTexture(GL_TEXTURE_2D, text1);
glTexCoord3f(-1.0, -1.0, -1.0); glVertex3f(CG_-1.0, -1.0, -1.0);
glTexCoord3f(-1.0, -1.0, 1.0); glVertex3f(-1.0, -1.0, 1.0);
glTexCoord3f(1.0, -1.0, 1.0); glVertex3f(1.0, -1.0, 1.0);
glTexCoord3f(1.0, -1.0, -1.0); glVertex3f(1.0, -1.0, -1.0);

glBindTexture(GL_TEXTURE_2D, text2);

glTexCoord3f(-1.0, 1.0, -1.0); glVertex3f(CG_-1.0, -1.0, -1.0);
glTexCoord3f(-1.0, 1.0, 1.0); glVertex3f(-1.0, -1.0, 1.0);
glTexCoord3f(1.0, 1.0, 1.0); glVertex3f(1.0, -1.0, 1.0);
glTexCoord3f(1.0, 1.0, -1.0); glVertex3f(1.0, -1.0, -1.0);

glEnd();
}

Is that right?

Share this post


Link to post
Share on other sites
Um yes, except you can't call glBindTexture inside glBegin/glEnd.

This is also why it's good to call glGetError once in a while :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!