Jump to content
  • Advertisement
Sign in to follow this  
jack872

OpenGL [SDL/OpenGL] resize problem

This topic is 2842 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

Hello,
I'm a newbie here so please be kind. I'm trying to make a little 2d videogame using SDL and OpenGL, but I'm having some problems on drawing the textures.
I'm using the rotozoom fuction from SDL_gfx to resize the image, but some images, after resizing, are messed up.

Here's my code:
bool Texture::LoadTexture( string strFile, GLuint new_Width, GLuint new_Height )
{
SDL_Surface *surface;
GLenum texture_format;
GLint nOfColors;
if ( (surface = IMG_Load(strFile.c_str())) ) {
if ( (surface->w & (surface->w - 1)) != 0 ) {
printf( "warning: image's width is not a power of 2\n" );
}

if ( (surface->h & (surface->h - 1)) != 0 ) {
printf( "warning: image's height is not a power of 2\n" );
}
nOfColors = surface->format->BytesPerPixel;
if( nOfColors == 4 )
{
if( surface->format->Rmask == 0x000000ff )
texture_format = GL_RGBA;
else
texture_format = GL_BGRA;
} else if( nOfColors == 3 )
{
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\n" );
return false;
}


surface = rotozoomSurfaceXY( surface, 0, 1, 1, 1 );
glGenTextures( 1, &texture );
glBindTexture( GL_TEXTURE_2D, texture );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels );

width = (GLfloat)surface->w;
height = (GLfloat)surface->h;
SDL_FreeSurface( surface );
return true;
}

printf( "SDL could not load image: %s\n", SDL_GetError() );
return false;
}





Drawing:
void Texture::DrawTexture( GLfloat x, GLfloat y )
{
if( !texture )
return;

glTranslatef( (GLfloat)x, (GLfloat)y, 0 );
glBindTexture( GL_TEXTURE_2D, texture );
glBegin( GL_QUADS );
glTexCoord2d( 0, 0 ); glVertex2d( 0, 0 );
glTexCoord2d( 1, 0 ); glVertex2d( width, 0 );
glTexCoord2d( 1, 1 ); glVertex2d( width, height );
glTexCoord2d( 0, 1 ); glVertex2d( 0, height );
glEnd();
glLoadIdentity();
}








this is a screen of what I get:
http://yfrog.com/jpscreen1q0j

I can't understand why! without the rotozoom istruction the drawing works fine.

Can someone help me?

SOLVED:
I've just found the problem... it was the rotozoom function wich changes the format so I put this istruction before I get the texture_format. :}



[Edited by - jack872 on December 10, 2010 12:20:23 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • 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!