Jump to content
  • Advertisement

Archived

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

Dark-Rain

My first Time With OGL

This topic is 5922 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
Advertisement
Have you checked that all required textures exist, that you''ve loaded them all in, and that you''ve enabled GL_TEXTURE_2D?

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
Guest Anonymous Poster
show us your code!

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!