void CreateTexture(UINT texture[], LPSTR strFileName, int textureID) {
AUX_RGBImageRec* pBitmap = NULL;
if(!strFileName)
return;
pBitmap = auxDIBImageLoad(strFileName);
if(pBitmap == NULL)
exit(0);
glGenTextures(0, &texture[textureID]);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
if(pBitmap) {
if(pBitmap->data)
free(pBitmap->data);
free(pBitmap);
}
}
Problem loading textures... UPD8 -> Prob solved! Thanks Grambo & Raduprv
Hello... I'm trying to load multiple textures, I'm just not sure how to add more than one...
This is how I create a texture:
CreateTexture(texture, "blkblue.bmp", 0);
I want to create more than one.
Here is my function to create a texture.
I'm not sure how to create more than one. I can't do the same thing twice because the data will be overwritten by the new texture:
CreateTexture(texture, "blkblue.bmp", 0);
CreateTexture(texture, "blkgren.bmp", 1);
That of course will be overwritten... So how do I get to the next element of the array?
Do I do CreateTexture(texture + sizeof(something), "blkblue.bmp", 0); ?
I can't do:
CreateTexture(texture[0], "blkblue.bmp", 0);
or I get this error: error C2664: 'CreateTexture' : cannot convert parameter 1 from 'unsigned int' to 'unsigned int []'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Just curious as to how to move forward.
Any help is greatly appreciated!
Thanks...
-Dennis
[edited by - anachronism on December 21, 2002 9:57:55 PM]
[edited by - anachronism on December 21, 2002 9:58:28 PM]
It is longer than one element! I set it up for 3! ... That's not really my problem... My problem is getting to the next array element when i set the texture...
-Dennis
[edited by - anachronism on December 21, 2002 8:26:08 PM]
-Dennis
[edited by - anachronism on December 21, 2002 8:26:08 PM]
Hmm... do you bind the other texture properly, when you try to use it? Can we see the code where you bind it?
Height Map Editor | Eternal lands
Height Map Editor | Eternal lands
Sure...
It displayes the texture like it should.... no matter whether i use texture[0] or texture[1] its the same texture...
Like when i load the second texture it overwrites the first... dunno though im confused...
thanks
glPushMatrix(); glTranslatef(xPos, yPos, zPos); glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); glTexCoord2f(0.0f,0.0f); glVertex3f( 0.0f, 0.0f, 0.0f ); // front glTexCoord2f(1.0f,0.0f); glVertex3f(-1.0f, 0.0f, 0.0f ); glTexCoord2f(1.0f,1.0f); glVertex3f(-1.0f, -1.0f, 0.0f ); glTexCoord2f(0.0f,1.0f); glVertex3f( 0.0f, -1.0f, 0.0f ); glEnd(); glPopMatrix();
It displayes the texture like it should.... no matter whether i use texture[0] or texture[1] its the same texture...
Like when i load the second texture it overwrites the first... dunno though im confused...
thanks
this would be the correct way to do it:
but even with that the code probably wont work correctly as you are not generating any opengl texture names (number of textures parameter of glGenTextures is 0) and you are not binding the textures so the first texture will be overwritten by the second.
I think this should solve the problem:
Hope that helps
[edited by - Grambo on December 21, 2002 8:44:15 PM]
CreateTexture(&texture[0], "blkblue.bmp", 0);
but even with that the code probably wont work correctly as you are not generating any opengl texture names (number of textures parameter of glGenTextures is 0) and you are not binding the textures so the first texture will be overwritten by the second.
I think this should solve the problem:
glGenTextures(1, &texture[textureID]);glBindTexture(GL_TEXTURE_2D,texture[textureID]);gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);glBindTexture(GL_TEXTURE_2D, 0);
Hope that helps
[edited by - Grambo on December 21, 2002 8:44:15 PM]
Change from
glBindTexture(GL_TEXTURE_2D, texture[0]);
to
glBindTexture(GL_TEXTURE_2D, texture[textureID]);
where texture ID is the textureid used to load the new texture.
Height Map Editor | Eternal lands
glBindTexture(GL_TEXTURE_2D, texture[0]);
to
glBindTexture(GL_TEXTURE_2D, texture[textureID]);
where texture ID is the textureid used to load the new texture.
Height Map Editor | Eternal lands
I think you misunderstood the code he posted Raduprv because that code looks suspiciously like it is the drawing code not the code used when loading the texture. Correct me if im wrong but i dont think he has any glBindTexture calls in his loading code which is why i suggested that he add them in my other post
His loading code looks OK, however, his drawing coe, which contains the bind does NOT look OK. That''s why I suggested him to make that change.
Height Map Editor | Eternal lands
Height Map Editor | Eternal lands
Thanks to the both of you...
Well... I made changes both of you suggested and it apparently worked for a second...
Now, EVERY time I run the program it performs an illegal operation and shuts down before it even shows anything. Has something to do with how somethings displayed...
Here is my current code:
I create these two textures:
CreateTexture(&texture[0], "blkblue.bmp", 0);
CreateTexture(&texture[1], "blkgren.bmp", 1);
Here is the new CreateTexture function:
and this is how I draw them...
One of the tweaks actually made both textures show up when I ran the program. But now it crashes before its displayed everytime. I commented out this code and it no longer crashes... the code must be near right since both textures apparently load, but something is causing everything to crash...
Thanks
-Dennis
Well... I made changes both of you suggested and it apparently worked for a second...
Now, EVERY time I run the program it performs an illegal operation and shuts down before it even shows anything. Has something to do with how somethings displayed...
Here is my current code:
I create these two textures:
CreateTexture(&texture[0], "blkblue.bmp", 0);
CreateTexture(&texture[1], "blkgren.bmp", 1);
Here is the new CreateTexture function:
void CreateTexture(UINT texture[], LPSTR strFileName, int textureID) { AUX_RGBImageRec* pBitmap = NULL; if(!strFileName) return; pBitmap = auxDIBImageLoad(strFileName); if(pBitmap == NULL) exit(0); glGenTextures(textureID, &texture[textureID]); glBindTexture(GL_TEXTURE_2D,texture[textureID]); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); glBindTexture(GL_TEXTURE_2D, textureID); if(pBitmap) { if(pBitmap->data) free(pBitmap->data); free(pBitmap); }}
and this is how I draw them...
glPushMatrix(); glTranslatef(xPos, yPos, zPos); glBindTexture(GL_TEXTURE_2D, 0); glBegin(GL_QUADS); glTexCoord2f(0.0f,0.0f); glVertex3f( 0.0f, 0.0f, 0.0f ); // front glTexCoord2f(1.0f,0.0f); glVertex3f(-1.0f, 0.0f, 0.0f ); glTexCoord2f(1.0f,1.0f); glVertex3f(-1.0f, -1.0f, 0.0f ); glTexCoord2f(0.0f,1.0f); glVertex3f( 0.0f, -1.0f, 0.0f ); glEnd(); glPopMatrix(); glPushMatrix(); glTranslatef(xPos, yPos, zPos); glBindTexture(GL_TEXTURE_2D, 1); glBegin(GL_QUADS); glTexCoord2f(0.0f,0.0f); glVertex3f( 0.0f, 0.0f, 0.0f ); // front glTexCoord2f(1.0f,0.0f); glVertex3f(-1.0f, 0.0f, 0.0f ); glTexCoord2f(1.0f,1.0f); glVertex3f(-1.0f, -1.0f, 0.0f ); glTexCoord2f(0.0f,1.0f); glVertex3f( 0.0f, -1.0f, 0.0f ); glEnd(); glPopMatrix();
One of the tweaks actually made both textures show up when I ran the program. But now it crashes before its displayed everytime. I commented out this code and it no longer crashes... the code must be near right since both textures apparently load, but something is causing everything to crash...
Thanks
-Dennis
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement