Archived

This topic is now archived and is closed to further replies.

My first Time With OGL

This topic is 5618 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am working my way throught the tutorials on the site but i have come unstuck on tutorial no.6. I am trying to add different textures to each side but all i get is on texture on one fac and then the other faces are white. What stupid mistake have i made? Thanks

Share this post


Link to post
Share on other sites
Yep all the txtures are there but i am not sure i have got the code right for how to load them and then bind the texture to each face.

I open each face glBegin(GL_QUADS) then give it the co-ords for the face then end it. now set a new texture and repeat for the rest of the faces but it all comes back white

Share this post


Link to post
Share on other sites
Post some code, dude. Off-hand, it may be that you''re trying to bind a texture within a glBegin() section. I don''t think that would work. Maybe I''m wrong, though...

Share this post


Link to post
Share on other sites
Ok Here is the code i am using :

glBindTexture(GL_TEXTURE_2D, texture[0]);

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();

glBindTexture(GL_TEXTURE_2D, texture[1]);
glBegin(GL_QUADS);
// Back Face
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();

glBindTexture(GL_TEXTURE_2D, texture[2]);
glBegin(GL_QUADS);
// Top Face
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();

glBindTexture(GL_TEXTURE_2D, texture[3]);
glBegin(GL_QUADS);
// Bottom Face
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();

glBindTexture(GL_TEXTURE_2D, texture[4]);
glBegin(GL_QUADS);
// Right face
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();

glBindTexture(GL_TEXTURE_2D, texture[5]);
glBegin(GL_QUADS);
// Left 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();



Share this post


Link to post
Share on other sites
Guest Anonymous Poster
that seems okay to me, what about your texture loading code.

Share this post


Link to post
Share on other sites
I am not sure that i ahve got this part right...


int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator

AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
AUX_RGBImageRec *TextureImage[2];
AUX_RGBImageRec *TextureImage[3];
AUX_RGBImageRec *TextureImage[4];
AUX_RGBImageRec *TextureImage[5];


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/Dark.bmp")) (TextureImage[1]=LoadBMP("Data/Louis.bmp"))

{
Status=TRUE; // Set The Status To TRUE

glGenTextures(1, &texture[0]); // Create The Texture
glGenTextures(2, &texture[1]);
glGenTextures(3, &texture[2]);
glGenTextures(4, &texture[3]);
glGenTextures(5, &texture[4]);
glGenTextures(6, &texture[5]);

Share this post


Link to post
Share on other sites
Then i have repeated these line for each 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);

glBindTexture(GL_TEXTURE_2D, texture[1]);
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);

But it then tells me on trying to run that i get the following error

TextureImage'' : redefinition; different subscripts

Am i being stupid here????

Share this post


Link to post
Share on other sites
Your bitmap loading is most definitely funked up. Here''s a totally untested conversion of the LoadTextures thingy from lesson6 for multiple textures (not compiled I''ll stress again):


  const char* filenames[] = { "dir\\one.bmp", "dir\\two.bmp", "dir\\three.bmp", "dir\\four.bmp", "dir\\five.bmp", "dir\\six.bmp" };

int LoadGLTextures()
{
int index;
AUX_RGBImageRec *TextureImage[6];
memset(TextureImage,0,sizeof(void *)*6);

for (index = 0; index < 6; ++index)
{
if (TextureImage[index]=LoadBMP(filenames[index]))
{
glGenTextures(1, &texture[index]);
glBindTexture(GL_TEXTURE_2D, texture[index]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[index]->sizeX, TextureImage[index]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[index]->data);
}
else
return FALSE;
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

if (TextureImage[index])
{
if (TextureImage[index]->data)
free(TextureImage[index]->data);

free(TextureImage[index]);
}
}
return TRUE;
}


If that works it''s a miracle. Note, in particular, some of the changes: the array of RGB_... images is declared in one place (your one was going a little strange with multiple declarations of successively larger arrays). Memset now clears all the elements (that''s what the "*1" bit was - one texture previously, now it''s six. The LoadBMP function takes one of the associated filenames (you weren''t loading in all six before). In general, notice the loop through all the elements and where I''ve put array indices.

Remember to change the filenames as appropriate too. You''ll get white for textures when you''ve not loaded them in correctly.

Share this post


Link to post
Share on other sites
I think Alimonster''s code is essentially correct, but the calls to glTexParameteri() should go inside the loop, as they only affect the currently bound texture.

There''s a thread on exactly this kind of problem in the NeHe forum, called "NeHe''s lesson 6 and multiple textures." (...and that''s the only reason I knew that little detail ).

Share this post


Link to post
Share on other sites
quote:
Original post by nicba
I think Alimonster''s code is essentially correct, but the calls to glTexParameteri() should go inside the loop, as they only affect the currently bound texture.

Heh heh heh... look closely at the code. The call is inside the loop.

Another victory for poor code formatting!



Share this post


Link to post
Share on other sites
There is another problem. Don''t bind the texture using ''textue[#]''. Just use the #. OpenGL binds textures to integer values.

Share this post


Link to post
Share on other sites
I may be completely wrong and/or out of line because I don''t know all that much about OpenGL, but I had a similar problem with that using the NeHe tutorials, with white images showing up instead of the textures I''d hoped. It turned out the bitmaps I was loading weren''t the proper size, I think. Don''t both of the sides have to be of base 2, that is, 2, 4, 6, 8, etc. or something like that?

Neat.

Elijah

Share this post


Link to post
Share on other sites
quote:
Original post by Deyja
There is another problem. Don''t bind the texture using ''textue[#]''. Just use the #. OpenGL binds textures to integer values.


"textures" is a bunch of integers (GLuint array, to be exact). See NeHe''s 6th tutorial, from which the code is converted. You''ve got to say texture[#] as that''s where the texture name is generated. (Although the redundancy is noted, in as much as you could move the multiple gen calls above the loop, replacing them with only one larger gen call.)

Share this post


Link to post
Share on other sites
I agree... The most likely culprit is the texture dimensions. Make sure they are powers of 2.

2, 4, 8, 16, 32, 64, 128, 256, 512, etc. as long as your video card supports it.

Share this post


Link to post
Share on other sites
But it then tells me on trying to run that i get the following error

TextureImage'' : redefinition; different subscripts

Am i being stupid here????






YOU are declaring the pointer TextureImage lot of times
your mistake is here:

AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
AUX_RGBImageRec *TextureImage[2];
AUX_RGBImageRec *TextureImage[3];
AUX_RGBImageRec *TextureImage[4];
AUX_RGBImageRec *TextureImage[5];


delete that and just put one declaration
AUX_RGBImageRec *TextureImage[5];


Share this post


Link to post
Share on other sites
I have go the code running now but all i have at the moment is one texture being displayed, none of the others show. The bmp files and all the same size and in the same place but i cannot see what i have done wrong.

Your Help again please...............

Heres the code........

#include <windows.h> // Header File For Windows
#include <stdio.h> // Header File For Standard Input/Output
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The Glaux Library

HDC hDC=NULL; // Private GDI Device Context
HGLRC hRC=NULL; // Permanent Rendering Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application

bool keys[256]; // Array Used For The Keyboard Routine
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default

GLfloat xrot; // X Rotation ( NEW )
GLfloat yrot; // Y Rotation ( NEW )
GLfloat zrot; // Z Rotation ( NEW )

GLuint texture[6]; // Storage For One Texture ( NEW )

char* filenames[] = {"data\\Dark.bmp","data\\louis.bmp","data\\NeHe.bmp","data\\Dark.bmp","data\\louis.bmp","data\\NeHe.bmp"};


LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc

AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
{
FILE *File=NULL; // File Handle

if (!Filename) // Make Sure A Filename Was Given
{
return NULL; // If Not Return NULL
}

File=fopen(Filename,"r"); // Check To See If The File Exists

if (File) // Does The File Exist?
{
fclose(File); // Close The Handle
return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
}

return NULL; // If Load Failed Return NULL
}

int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
int index; // Status Indicator

AUX_RGBImageRec *TextureImage[6]; // Create Storage Space For The Texture

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

for(index=0; index<6; ++index)
{
if(TextureImage[index]=LoadBMP(filenames[index]))
{
glGenTextures(1,&texture[index]);
glBindTexture(GL_TEXTURE_2D, texture[index]);
glTexImage2D(GL_TEXTURE_2D,0,3, TextureImage[index]->sizeX, TextureImage[index]->sizeY,0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[index]->data);
}
else
return FALSE;
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

if(TextureImage[index])
{
if(TextureImage[index]->data)
free(TextureImage[index]->data);
free(TextureImage[index]);
}
}

return TRUE; // Return The Status
}

GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}

glViewport(0,0,width,height); // Reset The Current Viewport

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix

// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}

int InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
if (!LoadGLTextures()) // Jump To Texture Loading Routine ( NEW )
{
return FALSE; // If Texture Didn''t Load Return FALSE
}

glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
return TRUE; // Initialization Went OK
}

int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
glTranslatef(0.0f,0.0f,-5.0f);

glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,1.0f,0.0f);
glRotatef(zrot,0.0f,0.0f,1.0f);

glBindTexture(GL_TEXTURE_2D, texture[0]);

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();



glBindTexture(GL_TEXTURE_2D, texture[1]);
// Back Face
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();

glBindTexture(GL_TEXTURE_2D, texture[2]);
// Top Face
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();

glBindTexture(GL_TEXTURE_2D, texture[3]);
// Bottom Face
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();

glBindTexture(GL_TEXTURE_2D, texture[4]);
// Right face
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();

glBindTexture(GL_TEXTURE_2D, texture[5]);
// Left 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();

xrot+=0.1f;
yrot+=0.1f;
zrot+=0.1f;
return TRUE;

Share this post


Link to post
Share on other sites
Looks like you''re missing glBegin(GL_QUADS) calls for your last five faces - simple mistake but it took me a while to find too!

Hope that helps

Enigma

Share this post


Link to post
Share on other sites
I'd like to toss in my thanks as well for the advice in this thread. From Dark-Rain for staring it, Alimonster for pointing out the proper loop structure to make the multiple BMP/texture loads and checks, and all those who also had helpful contributions to make.
Dark's last posting of the code allowed me to find the one error that was evading me! In my efforts to fix the error I was able to find additional threads on this subject within these forums, which shows I was not alone in making the multi-faced textue mapping problems.
In the hopes that those in the future forum hunters can also benifit from it, I'd like to toss in my HEAVILY commented coded for modifying NeHe Lesson 6 Texture Mapping ...


    
// In Global variable Definitions

// Before LRESULT CALLBACK

//GLuint texture[1]; // Storage For One Texture ( NEW )

GLuint texture[6]; // Storage For Six Textures ( MODIFIED ) (Global Variable)

char filenames[6][20] = {"Data/OGL-1.bmp", "Data/OGL-2.bmp", "Data/OGL-3.bmp", "Data/OGL-4.bmp",
"Data/OGL-5.bmp", "Data/OGL-6.bmp" };
// *.BMPs : 64x64 px, black background, 6 different colored numbers (1-6) (Global Array)


// Modifications in LoadGLTextures()

int LoadGLTextures() // Load Bitmaps And Convert To Textures

{
int Status=FALSE; // Status Indicator


// AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture

AUX_RGBImageRec *TextureImage[6]; // (MODIFIED) Create Storage Space For The 6 Textures


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

// (MODIFIED) Utilize (void *)*6 to NULL all 6 allocations


// (MODIFIED) Loop to read in 6 BMPs and allocate memory

for (int aBMPTexture=0; aBMPTexture<6; aBMPTexture++)
{ // START Loop Assignment of each BMP to Textures

// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit

// (MODIFIED) Check to insure there is an image to load as a texture

// for each texture/BMP file combination

if (TextureImage[aBMPTexture]=LoadBMP(filenames[aBMPTexture]))
{ // START bind *.bmp to textures

Status=TRUE; // Set The Status To TRUE

// File exists, still has to be mapped to a texture


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

glGenTextures(1, &texture[aBMPTexture]); // (MODIFIED) Create each Texture

// Why de-reference texture[0] and not texture[aBMPTexture]?

// SHOULD!! be aBMPTexture; else won't get ALL textures

// FIXED


// Typical Texture Generation Using Data From The Bitmap

// Function to bind each BMP to its texture

glBindTexture(GL_TEXTURE_2D, texture[aBMPTexture]);

// Assign each BMPs data to its Texture

// Insure to refer to the individual texture counter (aBMPTexture)

//glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY,

//0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

glTexImage2D(GL_TEXTURE_2D, 0, 3,
TextureImage[aBMPTexture]->sizeX,
TextureImage[aBMPTexture]->sizeY,
0, GL_RGB,
GL_UNSIGNED_BYTE,
TextureImage[aBMPTexture]->data);

// Standard Linear mapping. Advanced methods taught in later lessons

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
} // END bind *.bmp to textures

else // File containing BMP wasn't found to be able to map a texture

{
MessageBox(hWnd,filenames[aBMPTexture],"texture not found",MB_OK);
// File not found. Display Error dialog box w/ filename

Status = false; // False Status to indicate load failed

return Status;
}

// Cycle through each texture and de-allocate memory defined

//while still within allocation loop, but before leaving function

if (TextureImage[aBMPTexture]) // If Texture Exists

{ // START Free memory allocation

if (TextureImage[aBMPTexture]->data) // If Texture Image Exists

{
free(TextureImage[aBMPTexture]->data); // Free The Texture Image Memory

}

free(TextureImage[aBMPTexture]); // Free The Image Structure

} // END Free memory allocation

} // END Loop Assignment of each BMP to Textures


return Status; // Return The Status

}

// Modifications in DrawGLScene(GLvoid)

int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing

{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer

glLoadIdentity(); // Reset The View

glTranslatef(0.0f,0.0f,-5.0f);

glRotatef(xrot,1.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,1.0f,0.0f);
glRotatef(zrot,0.0f,0.0f,1.0f);

glBindTexture(GL_TEXTURE_2D, texture[0]);
// Bind Texture [0] with a cube face - OGL-1.bmp

glBegin(GL_QUADS);
// Front Face

// Attempt to change func order to get texture link

// failed

// Order of functions (TexCoord;Vertex) may appear to not matter

//BUT! "the texture coordinates used are the ones from the LAST call to glTexCoord" (neoztar)

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();

// Defined ONE texture/BMP combination. EACH texture has to be mapped

// properly for ALL textures to show up on final project.

// REMEMBER! Advance texture[(number of texture being used)]

// Each texture has to be mapped to each surface individually


//FORMAT:

// glBindTexture(GL_TEXTURE_2D, texture[#]); // Which texture being mapped = #

// glBegin(GL_QUADS); // GL_QUADS = 4-sided polygon

// glTexCoord2f(); glVertex3f(); // Repeat for EACH of 4 corners

// ...

// ...

// ...

// glEnd(); // End of CURRENT texture mapping


glBindTexture(GL_TEXTURE_2D, texture[1]);
// Bind Texture [1] with a cube face - OGL-2.bmp

// Repeat for each texture and face

glBegin(GL_QUADS);
// Rename to GL_QUADS4 == fail:undelclared identifier

// Back Face

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();

glBindTexture(GL_TEXTURE_2D, texture[2]);
// Bind Texture [2] with a cube face - OGL-3.bmp

glBegin(GL_QUADS);
// Top Face

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();

glBindTexture(GL_TEXTURE_2D, texture[3]);
// Bind Texture [3] with a cube face - OGL-4.bmp

glBegin(GL_QUADS);
// Bottom Face

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();

glBindTexture(GL_TEXTURE_2D, texture[4]);
// Bind Texture [4] with a cube face - OGL-5.bmp

glBegin(GL_QUADS);
// Right face

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();

glBindTexture(GL_TEXTURE_2D, texture[5]);
// Bind Texture [5] with a cube face - OGL-6.bmp

glBegin(GL_QUADS);
// Left 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();

xrot+=0.6f;
yrot+=0.7f;
zrot+=0.8f;
return TRUE; // Keep Going

} // END of DrawGLScene(GLvoid)



Pointing out any incorrect commenting or areas that could be commented more clearly for others starting to learn texture mapping would be appreaciated as the LACK of commenting was one of the problems that made the multi-texture mapping difficult to follow the first time through.

Your assistance is appreciated. And thanks again for the help.

[edited by - CyberneticDreams on July 31, 2002 5:39:18 AM]

Share this post


Link to post
Share on other sites
ehm well actually you should overlook the code again

i thought it clearly said you cannot use glbindtexture while you are in the glbegin() glend()........
GReets

Share this post


Link to post
Share on other sites
The order of functions (texcoord, vertex) DOES matter. When you send OpenGL a vertex the texture coordinates used are the ones from the LAST call to glTexCoord. I had this problem once and it was really hard to find.

Share this post


Link to post
Share on other sites