int LoadTexture()
{
int STATUS = FALSE;
SDL_Surface * TextureImage[2];
if ((TextureImage[0] = SDL_LoadBMP("test.bmp")) || (TextureImage[1] = SDL_LoadBMP("nehe.bmp")))
{
STATUS = TRUE;
glGenTextures(2, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->w, TextureImage[0]->h, 0,
GL_BGR, GL_UNSIGNED_BYTE, TextureImage[0]->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->w, TextureImage[1]->h, 0,
GL_BGR, GL_UNSIGNED_BYTE, TextureImage[1]->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
if (TextureImage[0])
SDL_FreeSurface(TextureImage[0]);
if (TextureImage[1])
SDL_FreeSurface(TextureImage[1]);
return STATUS;
}
loading multiple textures
Hello, I went over lesson 6 of the nehe tutorial and I'm having trouble loading multiple textures.
Here is the function that loads two textures
Before beginning to draw the front face of a cube I first add this line:
glBindTexture(GL_TEXTURE_2D, texture[1]);
and for the rest of the faces of the cuble I bind the 1st texture
glBindTexture(GL_TEXTURE_2D, texture[0]);
As a result I got the front face looking completly white and the rest of the faces are mapped with the 1st texture the way it's supposed to be.
Just to inform you, OpenGL is a state machine.
If you do this, it will remain the same untill you tell OpenGL otherwise:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Just wanted to tell you ;-)
BTW. the glTexParameteri calls has to the executed before glTexImage2D, since glTexImage2D "asks" OpenGL to upload the texture.
If you do this, it will remain the same untill you tell OpenGL otherwise:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Just wanted to tell you ;-)
BTW. the glTexParameteri calls has to the executed before glTexImage2D, since glTexImage2D "asks" OpenGL to upload the texture.
Killers don't end up in jailThey end up on a high-score!
Quote: Original post by nife
Just to inform you, OpenGL is a state machine.
If you do this, it will remain the same untill you tell OpenGL otherwise:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
Just wanted to tell you ;-)
glTexParameter sets parameters per texture object, so if you have two textures, you must set it two times; one for each texture. But you're right though that the state will remain untill you change it, but it's just that there's one such state for each texture.
Quote: Original post by nife
BTW. the glTexParameteri calls has to the executed before glTexImage2D, since glTexImage2D "asks" OpenGL to upload the texture.
No you don't have to do that. glBindTexture activates a new texture ID, glTexParameter sets a parameter for that texture ID and glTexImage associates texture data with that texture ID. You can call these two last functions in any order you like, as long as the correct texture ID is active. If you can't call glTexParameter after uploading the texture data, it would mean you can't change any texture parameters once the texture is uploaded, and that isn't true, because things like filtering CAN be changed at any time.
You shouldn't load the images in the if thing. Load them before the if. The code should look something like this.
Also, one of the textures maybe isn't power of 2 which means opengl won't display it.
int LoadTexture(){ int STATUS = FALSE; SDL_Surface * TextureImage[2]; TextureImage[0] = SDL_LoadBMP("test.bmp"); TextureImage[1] = SDL_LoadBMP("nehe.bmp"); if ((TextureImage[0] != NULL) && (TextureImage[1] != NULL)) { STATUS = TRUE; glGenTextures(2, &texture[0]); glBindTexture(GL_TEXTURE_2D, texture[0]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->w, TextureImage[0]->h, 0, GL_BGR, GL_UNSIGNED_BYTE, TextureImage[0]->pixels); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, texture[1]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->w, TextureImage[1]->h, 0, GL_BGR, GL_UNSIGNED_BYTE, TextureImage[1]->pixels); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } if (TextureImage[0]) SDL_FreeSurface(TextureImage[0]); if (TextureImage[1]) SDL_FreeSurface(TextureImage[1]); return STATUS;}
Also, one of the textures maybe isn't power of 2 which means opengl won't display it.
http://sourceforge.net/projects/pingux/ <-- you know you wanna see my 2D Engine which supports DirectX and OpenGL or insert your renderer here :)
that was such a dumb mistake, can't believe I didn't notice that. Thank you.
Hey, I'm a complete beginner and am having trouble trying to change the texture in tutorial 6 aswell. Just wondering why you're using SDL_surface in your code and what does it do.
i've tried altering the code given by NeHe and this is what i have in the LoadGLTextures method:
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator
AUX_RGBImageRec *TextureImage[2]; // Create Storage Space For The Texture
//memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
TextureImage[0]=LoadBMP("Data/NeHe.bmp");
TextureImage[1]=LoadBMP("Data/NeHe3.bmp");
// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if ((TextureImage[0]!=NULL) && (TextureImage[1]!=NULL))
{
Status=TRUE; // Set The Status To TRUE
glGenTextures(2, &texture[0]); // Create The Texture
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
}
free(TextureImage[0]); // Free The Image Structure
}
if (TextureImage[1]) // If Texture Exists
{
if (TextureImage[1]->data) // If Texture Image Exists
{
free(TextureImage[1]->data); // Free The Texture Image Memory
}
free(TextureImage[1]); // Free The Image Structure
}
return Status; // Return The Status
}
This is compiling alright but when i execute the program it comes up with 'instalization failed'.
any help would be great :)
i've tried altering the code given by NeHe and this is what i have in the LoadGLTextures method:
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator
AUX_RGBImageRec *TextureImage[2]; // Create Storage Space For The Texture
//memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
TextureImage[0]=LoadBMP("Data/NeHe.bmp");
TextureImage[1]=LoadBMP("Data/NeHe3.bmp");
// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if ((TextureImage[0]!=NULL) && (TextureImage[1]!=NULL))
{
Status=TRUE; // Set The Status To TRUE
glGenTextures(2, &texture[0]); // Create The Texture
// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[1]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
free(TextureImage[0]->data); // Free The Texture Image Memory
}
free(TextureImage[0]); // Free The Image Structure
}
if (TextureImage[1]) // If Texture Exists
{
if (TextureImage[1]->data) // If Texture Image Exists
{
free(TextureImage[1]->data); // Free The Texture Image Memory
}
free(TextureImage[1]); // Free The Image Structure
}
return Status; // Return The Status
}
This is compiling alright but when i execute the program it comes up with 'instalization failed'.
any help would be great :)
While my problem may not be concerning multiple textures, I'm still having a problem with Lesson 6. For some reason in Dev-C++, whenever I try to compile it, it throws this error back at me:
expected constructor, destructor, or type conversion before '*' token
That's concerning the AUX_RGBImageRec line. I even tried the one on the site, and still got that error. Anything wrong? I have been able to do all the other tutorials up to date.
expected constructor, destructor, or type conversion before '*' token
That's concerning the AUX_RGBImageRec line. I even tried the one on the site, and still got that error. Anything wrong? I have been able to do all the other tutorials up to date.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement