🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Multiple textures

Started by
5 comments, last by lc_overlord 17 years, 7 months ago
Hi, im having a problem to figure how to make multiple textures, I have the base as NeHe tutorial lesson 6, Dev-Cpp version. Added my own requirements to it (3d cubes, 4boxes high, 4 boxes wide and 4 boxes deep), Im trying to get a patern in there using multiple textures, I had it working with different colors, thats the easy part. I tryed to use something like this: http://rafb.net/paste/results/u1Yh9a47.html If anyone could help, I would apreciate it [Edited by - Gurnarok on December 3, 2006 5:33:38 AM]
Advertisement
so what, specifically, is your problem? also are you talking about having multiple textures and applying htem to different sides of a cube, or using multiple textures on the same face (and blending them)?

have you started to try to program this and came to a problem or are you just concerned from a pre-programming point?
I have the code done, im just trying to figure out how to get different texture on the different sides of the cube. Ie. blue in the front and back, red on top and bottom, green in left and right. Something like that. But when I try to bind other textures, they get over-ride with the last texture or the whole thing crashes. Im going to post the source in a external site tomorrow when I get back from work.
Ok, the source is in here: http://grimmi.one09.net/source.php
You cant bind a texture within a glBegin() and glEnd() pair, if you do, it will be ignored.

In this case you have to do it like this for each new texture
glBindTexture(GL_TEXTURE_2D, texture[0]);glBegin(GL_QUADS);          // Etuosa     glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); // Top right corner     glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); // Top left  corner     glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom left  corner     glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom right corner...... glEnd();
What about using multiple textures (texture[0], texture[1], texture[n]) ? How should I do that?
Rewrite the texture loading function to input the filename and return the texture id to a variable, like this.
Then just use the variable when binding the texture.

unsigned int LoadGLTexture(char fileneame[120])									// Load Bitmaps And Convert To Textures{	unsigned int texture;	AUX_RGBImageRec *TextureImage[1];					// Create Storage Space For The Texture	memset(TextureImage,0,sizeof(void *)*1);           	// Set The Pointer To NULL	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit	TextureImage[0] = LoadBMP(fileneame);		if (TextureImage[0])	{			glGenTextures(1, &texture[0]);					// Create The Texture		// Typical Texture Generation Using Data From The Bitmap		glBindTexture(GL_TEXTURE_2D, texture);		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);	}	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	}	return texture;									// Return The Status}


It's not that hard.

This topic is closed to new replies.

Advertisement