bool DrawImage(string name, CRectangle rect, float zDepth) { glEnable( GL_TEXTURE_2D ); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); GLuint texture; // Texture object handle SDL_Surface *surface; // Gives us the information to make the texture SDL_Surface* loadedImage = NULL; if ( (loadedImage = IMG_Load(name.c_str())) ) { //If the image loaded if( loadedImage != NULL ) { //Create an optimized surface surface = SDL_DisplayFormatAlpha( loadedImage ); //Free the old surface SDL_FreeSurface( loadedImage ); } // Have OpenGL generate a texture object handle for us glGenTextures( 1, &texture ); // Bind the texture object glBindTexture( GL_TEXTURE_2D, texture ); // 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, 4, surface->w, surface->h, 0, GL_BGRA, GL_UNSIGNED_BYTE, surface->pixels ); } else { printf("SDL could not load %s: %s/n", name.c_str(), SDL_GetError()); SDL_Quit(); return false; } // Free the SDL_Surface only if it was successfully created if ( surface ) { SDL_FreeSurface( surface ); } //glScalef(1.0f, 1.0f, 1.0f); glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Bind the texture to which subsequent calls refer to glBindTexture( GL_TEXTURE_2D, texture ); glBegin( GL_QUADS ); // Top-left vertex (corner) glTexCoord2i( 0, 0 ); glVertex3f( rect.left, rect.top, zDepth ); // Bottom-left vertex (corner) glTexCoord2i( 1, 0 ); glVertex3f( rect.right, rect.top, zDepth ); // Bottom-right vertex (corner) glTexCoord2i( 1, 1 ); glVertex3f( rect.right, rect.bottom, zDepth ); // Top-right vertex (corner) glTexCoord2i( 0, 1 ); glVertex3f( rect.left, rect.bottom, zDepth ); glEnd(); return true; }