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?
Problem with Textures
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:
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.
How to create a texture and mipmaps
http://www.opengl.org/wiki/index.php/Common_Mistakes#Creating_a_Texture
http://www.opengl.org/wiki/index.php/Common_Mistakes#Creating_a_Texture
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?
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?
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 :)
This is also why it's good to call glGetError once in a while :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement