I have tried that yes, and it doesn’t seem to work… Here’s the code
init images
GLuint gn;
SDL_Surface* surface;
GLenum texture_format;
GLint nOfColors;
if ( (surface = IMG_Load("zeldatest.png")) ) {
// Check that the image's width is a power of 2
if ( (surface->w & (surface->w - 1)) != 0 ) {
printf("warning: image width is not a power of 2
");
}
// Also check if the height is a power of 2
if ( (surface->h & (surface->h - 1)) != 0 ) {
printf("warning: image height is not a power of 2
");
}
// get the number of channels in the SDL surface
nOfColors = surface->format->BytesPerPixel;
if (nOfColors == 4) // contains an alpha channel
{
if (surface->format->Rmask == 0x000000ff)
texture_format = GL_RGBA;
else
texture_format = GL_BGRA;
} else if (nOfColors == 3) // no alpha channel
{
if (surface->format->Rmask == 0x000000ff)
texture_format = GL_RGB;
else
texture_format = GL_BGR;
} else {
printf("warning: the image is not truecolor.. this will probably break
");
// this error should not go unhandled
}
// Have OpenGL generate a texture object handle for us
glGenTextures( 1, &gn );
// Bind the texture object
glBindTexture( GL_TEXTURE_2D, gn );
// Set the texture's stretching properties
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// Edit the texture object's image data using the information SDL_Surface gives us
glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0,
texture_format, GL_UNSIGNED_BYTE, surface->pixels );
}
else {
printf("SDL could not load image %s
", SDL_GetError());
SDL_Quit();
}
// Free the SDL_Surface only if it was successfully created
if ( surface ) {
SDL_FreeSurface( surface );
}
draw a quad
void Square::Draw(GLuint texture){
glBindTexture( GL_TEXTURE_2D, texture );
glBegin(GL_QUADS);
glTexCoord2f( 0.0f, 0.0f ); glVertex3f(0, 0, 0);
glTexCoord2f( 0.5f, 0.0f ); glVertex3f(20, 0, 0);
glTexCoord2f( 0.5f, 0.5f ); glVertex3f(20, 25, 0);
glTexCoord2f( 0.0f, 0.5f ); glVertex3f(0, 25, 0);
glEnd();
}
(admittedly not exactly like your saying, i had a “sprite” class that was working until i had this problem, so i’ve been cutting out code to try to rule it out…) basically, in the main game init function i run the load function, which saves the GLuint to gn (a private class variable)… in the render function you run the draw(GLuint texture) to draw the quad and add the texture, (i send the texture and call the glBindTexture inside the function… is that my problem?) i’m going to attempt to start over when i get home and staple down what’s going on… thanks for the help everyone… i’m quite new to C++, SDL and OpenGL…