3D text rotation not working right.

Started by zezioen, December 22, 2010, 12:11:01

Previous topic - Next topic

zezioen

Hey everyone,

I am currently trying to render text in a 3D environment but it is not working the right way.
When I try to rotate the text it just takes a pixel line away until it is gone.

Here is the code that I use to build the font and render it to the screen.

And yes I've copied it from a tutorial on http://nehe.gamedev.net

private void buildFont() 
	{                                  // Build Our Font Display List
        float   cx;                                             // Holds Our X Character Coord
        float   cy;                                             // Holds Our Y Character Coord

        base = glGenLists(256);                            // Creating 256 Display Lists
        glBindTexture(GL_TEXTURE_2D, textureNames[0]);     // Select Our Font Texture
        for (int i=0;i<256;i++)
        {                               // Loop Through All 256 Lists
            cx = ((float)(i % 16)) / 16.0f;                     // X Position Of Current Character
            cy = ((float)(i / 16)) / 16.0f;                     // Y Position Of Current Character

            glNewList(base + i, GL_COMPILE);          // Start Building A List
            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();                                       // Done Building Our Quad (Character)
            glTranslatef(10.0f, 0.0f, 0.0f);               // Move To The Right Of The Character
            glEndList();                                   // Done Building The Display List
        }                                                       // Loop Until All 256 Are Built
    }

private void glPrint(int x, int y, String msg, int set)
    {
        if (set>1) 
        {
            set=1;
        }
        glBindTexture(GL_TEXTURE_2D, textureNames[0]);           // Select Our Font Texture
        glMatrixMode(GL_PROJECTION);                        // Select The Projection Matrix
        glPushMatrix();                                     // Store The Projection Matrix
        glLoadIdentity();                                   // Reset The Projection Matrix
        glOrtho(0, mode.getWidth(), 0, mode.getHeight(), -1, 1);                          // Set Up An Ortho Screen
        glMatrixMode(GL_MODELVIEW);                         // Select The Modelview Matrix
        glPushMatrix();                                     // Store The Modelview Matrix
        glLoadIdentity();   								// Reset The Modelview Matrix

        glRotatef(angle/100, 1.0f,0.0f,0.0f);  //here's the problem!

        glTranslatef(x, y, 0);                                // Position The Text (0,0 - Bottom Left)
        int baseOffset = base - 32 + (128 * set);                // Choose The Font Set (0 or 1)
        for(int i=0;i<msg.length();i++) 
        {
            glCallList(baseOffset + msg.charAt(i));
            glTranslatef(1.0f, 0.0f, 0.0f);
            
        }
        glMatrixMode(GL_PROJECTION);                        // Select The Projection Matrix
        glPopMatrix();                                      // Restore The Old Projection Matrix
        glMatrixMode(GL_MODELVIEW);                         // Select The Modelview Matrix
        glPopMatrix();                                      // Restore The Old Projection Matrix
    }


All I do to draw a string to the screen is:
glPrint(50,50,"hello world", 0);


But when the angle is supposed to rotate the text the piece of text that should be rotated just disappears.

My only GL initialization holds glEnable(GL_TEXTURE_2D) and loads the textures.
My guess is that I need to enable GL_DEPTH but it hasn't been working for me. Either what I described above happens or I just get a black screen.

Thanks in advance.

Fool Running

Although you say you're looking to render text in a 3D environment, you're using an ortho screen setup, so I assume you mean you want to add text on top of a 3D environment. The rotate you are using is rotating around the x-axis. This would cause the characters to attempt to rotate towards the monitor (depth). I assume this is not what you are wanting to do.
Try rotating around one of the other axes (probably the z-axis is what you want).
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D