Code: Select all
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_Surface* screen = SDL_SetVideoMode( width, height, 32, SDL_OPENGL );
glEnable( GL_TEXTURE_2D );
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(0.0f, width*1.5, height*1.5, 0.0f, -100.0f, 100.0f);
glMatrixMode( GL_MODELVIEW );
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glClearDepth(1.0f);
glColor4f(1.0f,1.0f,1.0f,1.0f);
glAlphaFunc( GL_GREATER, 0.1f );
glEnable( GL_ALPHA_TEST );
Code: Select all
//The image that's loaded
SDL_Surface* loadedImage = NULL;
//The optimized image that will be used
SDL_Surface* optimizedImage = NULL;
//Load the image using SDL_image
loadedImage = IMG_Load( filename.c_str() );
//If the image loaded
if( loadedImage != NULL )
{
//Create an optimized image
optimizedImage = SDL_DisplayFormat( loadedImage );
//Free the old image
SDL_FreeSurface( loadedImage );
//Return the optimized image
texture_image[current_image] = optimizedImage;
// Have OpenGL generate a texture object handle for us
glGenTextures( 1, &texture[current_image] );
// Bind the texture object
glBindTexture( GL_TEXTURE_2D, texture[current_image] );
// 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, GL_RGBA, optimizedImage->w, optimizedImage->h, 0, GL_BGRA, GL_UNSIGNED_BYTE, optimizedImage->pixels );