Skip to main content
gamedev.net
🔒 Locked

Problems with textures

Started by MaxxJag Oct 25, 2002 at 4:55 PM 7 replies 850+ views
Original Post
MaxxJag
MaxxJag
I''m having a lot of fun trying to get textures to show up. First one shows up and all, but any concecutive textures I try and bind don''t work, white is all that shows. I know this is general, but I want to see some possible solutions before I show my train wreck of coding.
MaxxJag
MaxxJag
Just BMP format, I''ve adapted the Lesson 6 Tutorial to my needs.

  
void CreateTexture ( void )
{
char filename[MAX_PATH];
AUX_RGBImageRec *Image;
int i;

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


for (i=0; i<2; i++)
{
if (i == 0)
strcpy (filename,"bg.bmp");
if (i == 1)
strcpy (filename,"install.bmp");

Image = auxDIBImageLoad(filename);

glBindTexture(GL_TEXTURE_2D, Texture[i]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, Image->sizeX, Image->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, Image->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}

if (Image)
{
if (Image->data)
free(Image->data);

free(Image);
}
}

int InitGL(GLvoid) // All Setup For OpenGL Goes Here

{
CreateTexture ();

glShadeModel(GL_SMOOTH); // Enable Smooth Shading

glClearColor(0.0f, 0.0f, 0.5f, 0.5f); // Black Background

glClearDepth(1.0f); // Depth Buffer Setup

glEnable(GL_DEPTH_TEST); // Enables Depth Testing

glEnable(GL_TEXTURE_2D);
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 Screen And Depth Buffer

glLoadIdentity(); // Reset The Current Modelview Matrix


glTranslatef (0.0f, 0.0f, -57.0f);
glBindTexture (GL_TEXTURE_2D, Texture[0]);

glBegin (GL_QUADS);
glTexCoord2f(0,1);glVertex2f (-32.0f, 24.0f);
glTexCoord2f(1,1);glVertex2f ( 32.0f, 24.0f);
glTexCoord2f(1,0);glVertex2f ( 32.0f,-24.0f);
glTexCoord2f(0,0);glVertex2f (-32.0f,-24.0f);
glEnd();

glLoadIdentity();

glTranslatef (0.0f, 0.0f, -5.0f);
glRotatef (rot, 0.0f, 1.0f, 0.0f);
glBindTexture (GL_TEXTURE_2D, Texture[1]);

glBegin (GL_QUADS);
glTexCoord2f(0,1);glVertex2f (-1.0f, 0.5f);
glTexCoord2f(1,1);glVertex2f ( 1.0f, 0.5f);
glTexCoord2f(1,0);glVertex2f ( 1.0f,-0.5f);
glTexCoord2f(0,0);glVertex2f (-1.0f,-0.5f);
glEnd();

rot += 2;

return TRUE;
}

Now I know I''ll be told my way of loading my textures using IF isn''t effective, it''s because I''m testing and will be adding some level loading stuff in the near future. I''ve had this problem before so that''s why I''m trying different ways of loading textures.

Raduprv
Raduprv
Are the textures power of 2?
Are they the proper format?
I don''t use auxDIBImageLoad(filename), instead, I use my custom made function, but, I think, I did try to use it once for an 8 bpp BMP,and it didn''t work.
Try changing the color depth of your BMP, to 24bpp. Also, make sure they are powers of 2.
MaxxJag
MaxxJag
That might be it since I''m trying to make a button texture, which I didn''t check the size, thanks, let''s hope it works.
MaxxJag
MaxxJag
No go, I did check the size, fixed it and still nothing. Next thing I did was try the Targa format from tutorial 2x, after some trial I got it working in my code, still same problem.
The background shows up, but the button thing doesn''t. hopefully it''s something stupid.
Wavarian
Wavarian
"glGenTextures(2, &Texture[0]);"

erm, maybe you should put the above line into your loop code modified as:

glGenTextures(1,&Texture);
Wavarian
Wavarian
-_-

glGenTextures(1,&Texture(i)); // where ( = [ etc
MaxxJag
MaxxJag
same problem, second texture doesn''t seem to be generated for some reason.

Topic Locked

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

Sign in to reply to this topic.