«SDL question»

Discussion in 'Indie Basics' started by kolka, May 2, 2005.

  1. kolka

    Original Member

    Joined:
    Mar 26, 2005
    Messages:
    47
    Likes Received:
    0
    Is there any function in sdl to flip the image vertically?
     
    #1 kolka, May 2, 2005
    Last edited: May 2, 2005
  2. PoV

    PoV
    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    2,132
    Likes Received:
    0
    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.
     
  3. kolka

    Original Member

    Joined:
    Mar 26, 2005
    Messages:
    47
    Likes Received:
    0
    So you write your own code to flip them?
     
  4. ggambett

    Moderator Original Member Indie Author

    Joined:
    Jul 26, 2004
    Messages:
    1,982
    Likes Received:
    6
    Yes. It's quite trivial as image transforms go...

    Code:
    	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!)
     
  5. bentlegen

    Original Member

    Joined:
    Dec 24, 2004
    Messages:
    116
    Likes Received:
    0
    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);
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer