Quicktime and Texture Coordinates

Griggs
Unregistered
 
Post: #1
Hi.
This seems simple enough, but it's been bothering me all day.

I just added textured text, at the moment copied from a NeHe tutorial. I copied the bit that makes the display lists for the letters.

It uses the usual image containing the characters evenly spaced:

[Image: font1.png]

The problem is that because I'm using Quicktime to load the textures the texture coordinates don't work. When I try for " A B C D E F G" I get "…qrstuvw" Opposite from what I want.

Now, my question is how should I modify this code:


Code:
for (int i = 0; i < 256; i++)    
    {
        cx=float(i % 16) / 16.0f;
        cy=float(i / 16) / 16.0f;
        
        glNewList(fontListBase + i,GL_COMPILE);

        glBegin(GL_QUADS);// Use A Quad For Each Character
            
        glTexCoord2f(cx,1-cy-0.0625f);        // Texture Coord (Bottom Left)
        glVertex2i(0,0);            // Vertex Coord (Bottom Left)


        glTexCoord2f(cx+0.0625f,1-cy-0.0625f);    // Texture Coord (Bottom Right)
        glVertex2i(16,0);            // Vertex Coord (Bottom Right)


        glTexCoord2f(cx+0.0625f,1-cy);        // Texture Coord (Top Right)
        glVertex2i(16,16);            // Vertex Coord (Top Right)


        glTexCoord2f(cx,1-cy);            // Texture Coord (Top Left)
        glVertex2i(0,16);            // Vertex Coord (Top Left)


        glEnd();
        
        glTranslated(10,0,0);                        
        glEndList();

        
    }//end for loop
To compensate for the texture coordinate change? I haven't hit on what I need yet, it's really quite frustrating.

Thanks
Quote this message in a reply
henryj
Unregistered
 
Post: #2
OpenGL's origin is bottom left whereas quicktime's origin is top left so you need to flip the image when you load it which is pretty trivial operation with quicktime. You just flip the bounds rect before you load the image.

This is only correct though if you were getting the glyphs upside down as well, which you didn't mention.
Quote this message in a reply
Griggs
Unregistered
 
Post: #3
No, they weren't upside down. The glyphs were exactly as they should look, but I'm getting the wrong ones.
Quote this message in a reply
henryj
Unregistered
 
Post: #4
Quote:
Code:
glTexCoord2f(cx,1-cy-0.0625f)



get rid of the 1-

Code:
glTexCoord2f(cx,cy-0.0625f)
Quote this message in a reply
Nimrod
Unregistered
 
Post: #5
Would this also explain why my PNG textures come out upside down when I load with libpng and display with OpenGL?
Quote this message in a reply
Griggs
Unregistered
 
Post: #6
Maybe so, though oddly enough i my case the image was right side up, only the coordinates were messed up.

Anyway, I have it fixed now, turns out I needed to change the loop a bit and change the display list base.

Thanks for your patience with my newbie questions. OpenGL is really quite new to me, but I think I'm getting things the way I want them. Currently a 640x480x32 full-scrolling tiled environment gets me about 110FPS on my iBook, and about 250 on my G4/400. I think I'm entirely fillrate limited in this case, which is hard to overcome. But 110 (with speed governors off) is good enough for me.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Render video (e.g. QuickTime) to buffer or texture? Ingemar 14 13,255 Jun 8, 2011 04:09 PM
Last Post: mdejong1024
  openal coordinates vs. opengl coordinates gerald 1 6,138 Feb 3, 2011 10:04 PM
Last Post: OneSadCookie
  Flipping a texture loaded using QuickTime.. Craig 3 3,374 Nov 17, 2005 08:52 PM
Last Post: arekkusu
  Integer texture coordinates. Skorche 5 3,871 Apr 28, 2005 10:49 AM
Last Post: Puzzler183
  vertex/texture coordinates screwy reubert 1 2,632 Aug 10, 2004 08:29 AM
Last Post: phydeaux