[SDL] SDL/OpenGL and texture mapping.

Byron Wright bslayerw at mindspring.com
Tue Sep 10 08:58:01 PDT 2002


Hi All,

Ok after saving the file as a jpg (without changing any code) the
texture is now displaying correctly. The only format I can successfully
use as a texture are jpg's. If someone could please explain why that is
I would be very apperiative.

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Byron Wright
Sent: Monday, September 09, 2002 11:27 PM
To: SDL Mailing List
Subject: [SDL] SDL/OpenGL and texture mapping.


Hi All,

Having a weird newbie problem here, attempting to load a texture using
SDL_LoadBMP or IMG_Load and not getting the right results. Basically
what it looks like is that I am loosing the blue channel I think or one
of the channels it not showing up. Here is some code (unoptimized), if
required I can send a screenshot of the image before I map it and after
I map it.:

     //SDL video has already been intialized.

	SDL_Surface *pBitmap = IMG_Load("test.bmp"); 
    if(pBitmap == NULL)  
	{
 
LogManager::getInstance()->getLog("textureManager")->error(" Failed
loading "+getName()+ " : " + (		       SDL_GetError()));
		return ;
	}

    // Generate a texture with the associative texture ID stored in the
array
    glGenTextures(1, &m_textureID);
	std::stringstream os;
	os << "genereated texture with id:" << m_textureID;
	
wright::util::LogManager::getInstance()->getLog("textureManager")->info(
os.str());

    glBindTexture(GL_TEXTURE_2D, m_textureID);
    
    m_width  = pBitmap -> w;
    m_height = pBitmap -> h;   

	os.str("");
	os<< "texture data: \nwidth:"
<<m_width<<"\nheight:"<<m_height<<"\nbit depth:"<< pBitmap -> format ->
BitsPerPixel;
	
wright::util::LogManager::getInstance()->getLog("textureManager")->info(
os.str());
  
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);    
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);   

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_width, m_height, 0, GL_RGB,
GL_UNSIGNED_BYTE, pBitmap -> pixels);
    
    SDL_FreeSurface(pBitmap);                 

Byron Wright


_______________________________________________
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl





More information about the SDL mailing list