Advertisement

Texturing a cube

Started by April 03, 2005 06:41 PM
15 comments, last by bearS 19 years, 7 months ago
Hello, i'm following lession 6 , and i did it correctly , but i wonder how possible to add new image (different image) in every face of the cube ?
You will need to bind another texture before drawing each face of the cube then.
Advertisement
Or use one texture and the correct texture coordinates.
Thanks, but any example for this ?

i'm just new for the opengl programming and i'm trying to understand it all in steps .

regards
create how ever many texture you want. then before each face put bindtexture that you wan't on that face.
i just wish to have the full script foir this if possible .. i'm new my programming imagination stioll poor ..

Thanks
Advertisement
see below:
make sure to make room for 6 textures.
do this at the top with the rest.
oh and make int loop for the loop
GLuint	texture[6];			// Storage For six Texturesint loop;

then make the textures
int LoadGLTextures()									// Load Bitmaps And Convert To Textures{	int Status=FALSE;									// Status Indicator	AUX_RGBImageRec *TextureImage[6];	//Create Storage Space For The six texture images				memset(TextureImage,0,sizeof(void *)*6); //note the *6          		// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit	if ((TextureImage[0]=LoadBMP("image1.bmp")) &&  (TextureImage[1]=LoadBMP("Data/image2.bmp")) &&   (TextureImage[2]=LoadBMP("Data/image3.bmp")) && // load all your files   (TextureImage[3]=LoadBMP("Data/image4.bmp")) &&    (TextureImage[4]=LoadBMP("Data/image5.bmp")) &&    (TextureImage[5]=LoadBMP("Data/image6.bmp")))	{		Status=TRUE;		// Set The Status To TRUE  		glGenTextures(6, &texture[0]);		//we want 6 textures so create them.    	for (loop=0; loop<6; loop++)					// Loop Through All 6 Textures		{			glBindTexture(GL_TEXTURE_2D, texture[loop]);//loop replaces the normal [0] to make 6			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);			glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[loop]->sizeX, TextureImage[loop]->sizeY,				0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[loop]->data);		}		for (loop=0; loop<6; loop++)						// Loop Through All 6 Textures freeing the data	{		if (TextureImage[loop])						// If Texture Exists		{			if (TextureImage[loop]->data)				// If Texture Image Exists			{				free(TextureImage[loop]->data);			// Free The Texture Image Memory			}			free(TextureImage[loop]);				// Free The Image Structure		}	}}	return Status;										// Return The Status}


last bind a separate texture for each face in your scene
        glBindTexture(GL_TEXTURE_2D, texture[0]);//first texture	glBegin(GL_QUADS);		// Front Face				glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);		glEnd();		// Back Face        glBindTexture(GL_TEXTURE_2D, texture[1]);//second texture		glBegin(GL_QUADS);				glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);		glEnd();		// Top Face		glBindTexture(GL_TEXTURE_2D, texture[2]);//third		glBegin(GL_QUADS);		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);		glEnd();		// Bottom Face		glBindTexture(GL_TEXTURE_2D, texture[3]);//etc.		glBegin(GL_QUADS);		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);		glEnd();		// Right face		glBindTexture(GL_TEXTURE_2D, texture[4]);		glBegin(GL_QUADS);		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);		glEnd();		// Left Face		glBindTexture(GL_TEXTURE_2D, texture[0]);		glBegin(GL_QUADS);		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	glEnd();


i'm a beginner too so if i messed anything up i'm sorry.

[Edited by - badbrad29 on April 4, 2005 11:08:40 PM]
Hi all
I am at lesson 6 too and i'am stuck!
My problem is the glAUX (glaux.h)
my DEVcpp package does not include that header.
I then searched for it on the net and found one.
This header alow the lesson to compile correctly, but if i try to run the program i get a more ugly error
"missing glaux.dll" -?!
is glaux depending on a dll?

I also looked at the code NeHe uploaded as an alternative to the glaux.h, but that code..
I would love to se the lesson 6 implemented with the replacement code (especially because glaux is obsolete/deprecated)
I have 3 questions:
1. does you (who can run the lesson6 with glaux.h) ALSO have a glaux.dll??
2. Can anyone use the "replacement code":


link

(there seams to be something missing??)
3. is it posible to write an email to NeHe eg Jeff Molofee, I have looked everywhere, but not found any email addres (fully understandable actually..)
Any reply is apreciated

regards.
------
edited to try to get the link to replacement code working..

[Edited by - bearS on April 5, 2005 8:45:45 AM]
regards a.
I've stuck glaux.h and glaux.dll in a zip on my webspace. Grab it here.

You do links using standard HTML: [a href="www.blah.com"]blah[/a] (obviously replace square brackets with less than and greater than).
--
Cheers,
Darren Clark
Quote: Original post by eSCHEn
I've stuck glaux.h and glaux.dll in a zip on my webspace. Grab it here.

You do links using standard HTML: [a href="www.blah.com"]blah[/a] (obviously replace square brackets with less than and greater than).


&lta href="www.blah.com"&gtblah</a> ;-)
Killers don't end up in jailThey end up on a high-score!

This topic is closed to new replies.

Advertisement