2nd Texture Image
Hello, I am a Progress (Database orientated Business 4GL), and therefore am fairly new to all this. I have used C++ before, but it was Borland, and only in a character enviroment. Anyway, I started working through the tutorials last night, and am loving it. I got up to lesson 6 - Texture mapping.
I have put 3 boxes on-screen, the 2 outside boxes rotate on their X axis and the center one rotates on it's Y axis. So far so good! Anyway, then I bind a texture image to the first box, no problems, but when I try to load a second image into a second texture and apply it to the second box, I keep getting the first texture again (understand all that?).
Added variable texture2[0]; thinking that texture[3] would only give me different version of the same image.
Here is what I have changed in LoadGLTextures:
int LoadGLTextures()
{
int Status=FALSE;
AUX_RGBImageRec *TextureImage[3];
memset(TextureImage,0,sizeof(void *)*1);
/* 1st Image */
if (TextureImage[0]=LoadBMP("Images/W.bmp"))
{
Status=TRUE;
glGenTextures(1, &texture[0]);
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);
}
// 2nd Image
if (TextureImage[1]=LoadBMP("Images/I.bmp"))
{
Status=TRUE;
glGenTextures(1, &texture2[0]);
glBindTexture(GL_TEXTURE_2D, texture2[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->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);
}
if (TextureImage[0]) {
if (TextureImage[0]->data) {
free(TextureImage[0]->data); }
free(TextureImage[0]); }
if (TextureImage[1]) {
if (TextureImage[1]->data) {
free(TextureImage[1]->data); }
free(TextureImage[1]); }
return Status;
}
I then bind this image (texture2[0]) to my second cube, but keep getting the first one, can anyone please help? Thank you very much in advance.
CYA
Just another Corporate slave trying to release himself into the OpenGL void.
Edited by - Wiz74 on 9/24/00 12:40:39 AM
Just another Corporate slave trying to release himself into the OpenGL void.
If you look further ahead in NeHes tuts he loads textures using a loop counter, the example i refer to is in Tutorial 17, where 2 textures are loaded
Hope it helps
Nitro :-)
Hope it helps
Nitro :-)
Thanx mate, will go and check it out now.
CYA
CYA
Just another Corporate slave trying to release himself into the OpenGL void.
Hi, Wiz74 !
Look at your code near lines where you work with 2nd text.:
glBindTexture(GL_TEXTURE_2D, texture2[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB,
GL_UNSIGNED_BYTE, TextureImage[0]->data);
You call glTexImage2D with TextureImage[0]->data again
( TextureImage'' index is ZERO ) !!!
Correct your code.
WBR, Ilya.
Look at your code near lines where you work with 2nd text.:
glBindTexture(GL_TEXTURE_2D, texture2[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[1]->sizeX, TextureImage[1]->sizeY, 0, GL_RGB,
GL_UNSIGNED_BYTE, TextureImage[0]->data);
You call glTexImage2D with TextureImage[0]->data again
( TextureImage'' index is ZERO ) !!!
Correct your code.
WBR, Ilya.
Damnit, these guys beat me to it again...
I should get up earlier. But they''re both correct, it is easier to load multiple textures if you have one array since then you can just use a loop to get every subscript of the array instead of having the same code over and over again... Anyways, if you wanted to have a couple of texture variables defined like you did, then you shouldn''t make them both arrays of 0, there''s no point... You should''ve just defined them as single variables.
And, yes, that annoying thing about copy and pasting code, don''t you hate it? I find I always miss changing one thing if I copy and paste.
Another example of why you should have an array with multiple images... Then you can do this...
That''s so much easier to do once you''ve got lots of textures.
S.
I should get up earlier. But they''re both correct, it is easier to load multiple textures if you have one array since then you can just use a loop to get every subscript of the array instead of having the same code over and over again... Anyways, if you wanted to have a couple of texture variables defined like you did, then you shouldn''t make them both arrays of 0, there''s no point... You should''ve just defined them as single variables.
And, yes, that annoying thing about copy and pasting code, don''t you hate it? I find I always miss changing one thing if I copy and paste.
Another example of why you should have an array with multiple images... Then you can do this...
const int NumOfTextures = 3;unsigned int texture[NumOfTextures];//bool LoadGLTextures(){ bool Status = false; AUX_RGBImageRec *TextureImage[NumOfTextures]; memset(TextureImage, 0, sizeof(void *));// TextureImage[0] = LoadBMP("Images\\W.bmp"); TextureImage[1] = LoadBMP("Images\\I.bmp");// for (int loop = 0; loop < NumOfTextures; loop++) { if (TextureImage[loop]) { Status = true; glGenTextures(1, &texture[loop]); glBindTexture(GL_TEXTURE_2D, texture[loop]); glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); }// if (TextureImage[loop]) { if (TextureImage[loop]->data) { free(TextureImage[loop]->data); }// free(TextureImage[loop]); } }// return Status;}
That''s so much easier to do once you''ve got lots of textures.
S.
Thank you all very much, I looked ahead to chapter 17, as suggested by StephenNitro, And have successfully loaded and applied all three textures. Thanx to everyone who responded, it is very much appreciated. Was thinking, when I finish my little demo, might add the option to run in Glide aswell. Haven''t really looked into it properly yet, but from a quick glance, doesnt look too different.
CYA and once again thank you to all who responded.
Good to see that the sharing of knowledge (which was rife on the C64 and Amiga) hasn''t died.
CYA and once again thank you to all who responded.
Good to see that the sharing of knowledge (which was rife on the C64 and Amiga) hasn''t died.
Just another Corporate slave trying to release himself into the OpenGL void.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement