Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Drawing charcters Matrix Issue

  1. #1
    Intern Contributor
    Join Date
    Feb 2011
    Posts
    50

    Drawing charcters Matrix Issue

    I'm trying to create a library of costume fonts. The issue I'm having is that when text objects are meant to be drawn in a list it refuses to work. Instead, only 1 letter is drawn where I want and the rest are drawn at the origin. I had a feeling this something to do with glLoadIdentity(); so I placed it out side my loop which draws the objects.

    Frustratingly, this didn't work. It also didn't work when I heard glLoadIdentity(); in the loop were it was drawn after every object.

    I have a feelig my issues has something to do with my matrix can you help? I just need to draw objects in a list.

    Code :
    #include "DrawText.h"
    std::vector <CLetter *> qva_Fonts;
    void CFonts::DrawText(char *s, GLfloat gfText_PosX, GLfloat gfText_PosY, GLfloat gfFont_Size, GLfloat gfFont_Spacing)
    {
    	//for loop drawing each letter
    	for (int letter = 0;letter != strlen(s);letter++)
    	{
     
    	//draw font in array
    		qva_Fonts[((int)*s)- 32]-> draw();
    		s++;
     
    	//loadmatrix Position & Scalling
     
    		gfaaSca[0] = gfFont_Size;
    		    gfaaSca[5] = gfFont_Size;
    		        gfaaSca[10] = gfFont_Size;
    		             gfaaSca[15] = gfFont_Size;
     
    		gfText_PosX += gfFont_Spacing;
    	    gfaaPos[12] = gfText_PosX;
    		gfaaPos[13] = gfText_PosY;
     
     
    	//multiply matrix
     
    		glMultMatrixf(gfaaPos);
    		glMultMatrixf(gfaaSca);
     
    	}
    	glLoadIdentity();
    }

  2. #2
    Intern Contributor
    Join Date
    Feb 2011
    Posts
    78

    Re: Drawing charcters Matrix Issue

    this is how i draw text
    i think its also best to render it last
    as you can see i am not even done cleaning this up
    but it works and i dont have the time for such a simple thing


    void DrawText(GLint x, GLint y, char* s, GLfloat r, GLfloat g, GLfloat b) {

    int lines;
    char* p;


    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0.0, glutGet(GLUT_WINDOW_WIDTH), 0.0, glutGet(GLUT_WINDOW_HEIGHT), -1.0, 1.0);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();


    //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();


    glDisable(GL_LIGHTING);
    glDisable(GL_TEXTURE_2D);
    glColor3f(r, g, b);


    glRasterPos2i(x, y);

    for(p = s, lines = 0; *p; p++) {
    if (*p == '\n') {
    lines++;
    glRasterPos2i(x, y-(lines*18));
    }
    glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *p);
    }

    /* */
    glPopMatrix();


    glColor3f(0.0f,0.0f,0.0f);


    glMatrixMode(GL_PROJECTION);
    glPopMatrix();


    glMatrixMode(GL_MODELVIEW);


    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •