[SDL] Blitting OpenGL texture.
Ryan Williams
libsdl.org-mailinglist at shitsoftware.com
Thu Jul 7 15:59:44 PDT 2005
Hi, I'm using SDL and OpenGL to make a 2D game. I have my sprites as 1
long PNG file with all the frames of animation, what I want to do is
blit the frame I want into an opengl texture. This is the code I'm using:
SDL_Surface* m_gSprites(IMG_Load("sprites.png"));
glGenTextures(1, &m_nTextureID);
glBindTexture(GL_TEXTURE_2D, m_nTextureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
SDL_Rect tSrcRect;
SDL_Rect tDesRect;
tSrcRect.x = 0;
tSrcRect.y = m_iSize*m_iFrame;
tSrcRect.w = m_iSize;
tSrcRect.h = m_iSize;
tDesRect.x = 0;
tDesRect.y = 0;
SDL_Surface* tSurface(SDL_CreateRGBSurface(SDL_SWSURFACE, m_iSize,
m_iSize, 32, rmask, gmask, bmask, amask));
SDL_BlitSurface(m_gSprites, &tSrcRect, tSurface, &tDesRect);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_iSize, m_iSize, 0, GL_RGBA,
GL_UNSIGNED_BYTE, tSurface->pixels);
This results in a totally empty texture, but if i add this before blitting:
SDL_FillRect(tSurface, NULL, 0x55ffffff);
I can see it's copied the texture fine but is semi-transparent like the
rectangle I filled it with, it seems to be using the alpha from the
destination surface. Am I missing something I need to apply to the
destination surface before blitting?
Thanks
--
Ryan Williams
http://ryanwilliams.org
More information about the SDL
mailing list