Skip to main content
GameDev.net gamedev.net
🔒 Locked

Lesson6 multi textures

Started by Ratalon Mar 21, 2003 at 2:21 AM 5 replies 300+ views
Original Post
Ratalon
Ratalon
I am trying to load 2 different textures on the cube from #6 every [0] in this if... if (TextureImage[1]=LoadBMP("Other.bmp")) I change to a [1] but I get read errors with the glTexImage2D yes I made texture[1] bigger. I am missing something, and im willing to bet it is something simple, at anytime except 3am.
James Trotter
James Trotter
Post all your code around loading and initializing... Then I can help
Ratalon
Ratalon
Ok I basicly have lesson 6 exactly. with a few changes.
--declarations--
GLuint texture[2]; //for 2 textures

--loading--
int LoadGLTextures()
// Load Bitmaps And Convert To Textures
{
int Status=FALSE;
// Status Indicator
AUX_RGBImageRec *TextureImage[2]; // Create Storage Space For The 2 Textures

memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL

// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))
//Loads texture 0
{
Status=TRUE; // Set The Status To TRUE

glGenTextures(1, &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);
}
//Here is texture 1
if (TextureImage[1]=LoadBMP("Data/Other.bmp"))
{
Status=TRUE; // Set The Status To TRUE

glGenTextures(1, &texture[1]); // Create The Texture

// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[0]);

//THE LINE BELOW causes the read error.

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]) replaced 0 with 1

return Status; // Return The Status
}

/*
Then 1/2 way through the GL_QUADS I glEnd(), and glBindTexture(GL_TEXTURE_2D, texture[1]); (Should be the 2nd texture)

The CAPS line is where my debugger says the error is
*/

[edited by - Ratalon on March 21, 2003 1:22:25 PM]
lc_overlord
lc_overlord
change this

// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[0]);

//THE LINE BELOW causes the read error.


to this


// Typical Texture Generation Using Data From The Bitmap
glBindTexture(GL_TEXTURE_2D, texture[1]);

//THE LINE BELOW causes the read error.



However you might want to change the code so that it can load any texture. if you want i could send a good texture loader.


Ratalon
Ratalon
I would like to see a good loader, actually.
falkone
falkone
When you use Memset, you are only clearing enough space for one pointer, not two ( memset(TextureImage,0,sizeof(void *)*2) )
Disclaimer: "I am in no way qualified to present advice n any topic concerning anything and can not be held responsible for any damages that my advice may incurr (due to neither my negligence nor yours)" o
Ratalon
Ratalon
It was a combo of memset and the array..
Thanks Guys

--edit--
why for 5 textures do I need to declare
--
GLuint texture[5];

And load the textures with
--
AUX_RGBImageRec *TextureImage[5];
memset(TextureImage,0,sizeof(void *)*5);

Does the [0] not get used when temping the bmp data or something?


[edited by - Ratalon on March 21, 2003 5:56:47 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.