[SDL] SDL/OpenGL and texture mapping.

Byron Wright bslayerw at mindspring.com
Tue Sep 10 09:06:00 PDT 2002


Ok, this conbined with Matthias's code works beautifully. So my problem
is that my image even though I used SDL_LoadBMP or IMG_Load does not
return a 32-bit image? Therefore I have to set the surface manually and
blit to that surface to create a 32bit image? 

-Byron

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
paul at theV.net
Sent: Tuesday, September 10, 2002 8:28 AM
To: sdl at libsdl.org
Subject: Re: [SDL] SDL/OpenGL and texture mapping.


Maybe you shall try to convert your image to a proper 32-bit RGB 
format first? Just create a RGB surface like this

    SDL_Surface *s;
    Uint32 rmask, gmask, bmask, amask;
    int bits = 32;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
    amask = 0x000000ff;
#else
    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
    amask = 0xff000000;
#endif
    s = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 
            bits, rmask, gmask, bmask, amask);

and then blit your image over, and use the resulting surface
as the source for your GL texture.

Regards,
.paul.

On Mon, Sep 09, 2002 at 11:26:56PM -0700, Byron Wright wrote:
> 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")->inf
> o(
> 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")->inf
> o(
> 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

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





More information about the SDL mailing list