View Full Version : «SDL question»
kolka
05-02-2005, 01:13 AM
Is there any function in sdl to flip the image vertically?
No. With OpenGL however you can play with the texture co-ordinates or the vertices to achieve that.
Not sure how appropriate this question is for this forum.
kolka
05-02-2005, 07:39 AM
So you write your own code to flip them?
ggambett
05-02-2005, 08:17 AM
So you write your own code to flip them?
Yes. It's quite trivial as image transforms go...
SDL_LockSurface(m_pSurface);
int nHH = m_pSurface->h / 2;
int nPitch = m_pSurface->pitch;
byte* pBuf = new byte[nPitch];
byte* pSrc = (byte*) m_pSurface->pixels;
byte* pDst = (byte*) m_pSurface->pixels + nPitch*(m_pSurface->h - 1);
while (nHH--)
{
memcpy(pBuf, pSrc, nPitch);
memcpy(pSrc, pDst, nPitch);
memcpy(pDst, pBuf, nPitch);
pSrc += nPitch;
pDst -= nPitch;
}
delete[] pBuf;
SDL_UnlockSurface(m_pSurface);
(Yeah, yeah, it could be optimized in assembler with SSE and MMX, unrolled, and written in Haskell, but you shouldn't be doing flips too often in realtime, nor optimizing prematurely!)
bentlegen
05-02-2005, 07:45 PM
No. With OpenGL however you can play with the texture co-ordinates or the vertices to achieve that.
On a slightly related note, I thought I'd mention the following easy (but not always obvious) trick:
glScalef(1.0f, -1.0f, 1.0f);
vBulletin v3.6.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.