Dealing with inverted textures in OpenGL

Member
Posts: 65
Joined: 2009.01
Post: #1
Is there a "best" way to deal with the fact that 2D Textures in OpenGL are inverted?
I have a simple 2D game that uses images mapped onto quads to create the sprites. I use the Texture2D sample code to load the textures, but they are upside down.
I could say something like

glRotatef(180, 0, 0, 1);

on every render cycle, but that seems like a waste.
Should I map them onto the quad upside down?
I can't figure out how they do it in the Crash Landing sample code, which has a _rotation variable, but that just seems to be used to orient the ship.
Any ideas?
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #2
Use an upside down image Wacko

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 65
Joined: 2009.01
Post: #3
Inverting the image is not ideal, particularly if you are working with other people that will keep trying to "correct" the picture.
As a matter of fact, the images in the Crash Landing sample code are not inverted.
Quote this message in a reply
Member
Posts: 269
Joined: 2005.04
Post: #4
Use a negative y coordinate for your texture coordinates. Or you can flip the image on load.

Part of the code modified from Texture2D:

Code:
CGAffineTransform    transform;

if (flipImage)
{
    transform = CGAffineTransformTranslate(transform, 0, height);
    transform = CGAffineTransformScale(transform, 1.0, -1.0);
}
        
imageData = (GLubyte *)calloc(1, (width * height * 4));
spriteContext = CGBitmapContextCreate(imageData, width, height, 8, width * 4, CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);
            
CGContextConcatCTM(spriteContext, transform);

CGContextDrawImage(spriteContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), spriteImage);
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #5
You can flip the images when you save them, flip the images on load, flip the texture matrix, flip the geometry for every object, or flip each object. All will work just fine.

Personally, I just flip the images at load time and be done with it. It's pretty easy to do, and isn't going to be a performance problem really.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #6
I'm with the "flip it on load" crowd.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #7
Skorche Wrote:You can flip the images when you save them, flip the images on load, flip the texture matrix, flip the geometry for every object, or flip each object. All will work just fine.

Not "all", Any 3 will work though.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #8
unknown Wrote:Not "all", Any 3 will work though.

Um... Or any 1 or 5 of them. Rasp

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Is Dealing with Opengl ES 2 worth the trouble? Mattonaise 9 8,053 Aug 23, 2011 08:56 PM
Last Post: Mattonaise
  [SOLVED]OpenGL edges of textures mk12 2 4,399 Sep 2, 2010 08:07 PM
Last Post: mk12
  OpenGL Image Textures mikey 52 24,603 Jun 30, 2009 10:42 AM
Last Post: AnotherJake
  Using textures OpenGL switches to software renderer bruno 2 3,563 Oct 12, 2008 03:06 AM
Last Post: bruno
  Dealing with GLUT and OpenGL... RingoEST 10 5,734 Aug 16, 2008 12:24 AM
Last Post: RingoEST