Text in OpenGL



  • Hallo,

    ich versuche in einem Raum, den ich glOrtho(...) eingestellt habe, Text anzuzeigen. Die Klasse für die Schrift sieht folgendermaßen aus:

    GLubyte space[] = 	
    	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    
    GLubyte letters[][13] = {
    	{0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18}, 
    	{0x00, 0x00, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe}, 
    	{0x00, 0x00, 0x7e, 0xe7, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e}, 
    	{0x00, 0x00, 0xfc, 0xce, 0xc7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc7, 0xce, 0xfc}, 
    	{0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xff}, 
    	{0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xff}, 
    	{0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xcf, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e}, 
    	{0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3}, 
    	{0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e}, 
    	{0x00, 0x00, 0x7c, 0xee, 0xc6, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06}, 
    	{0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8, 0xf0, 0xe0, 0xf0, 0xd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0x3c, 0x66, 0x66, 0xc3}, 
    	{0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3}, 
    	{0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x7e, 0x0c, 0x06, 0x03, 0x03, 0xff}
    };
    
    Font::Font()
    {
    	GLuint i, j;
    	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    
    	fontOffset = glGenLists(128);
    
    	for (i=0,j='A'; i<26; i++,j++) 
    	{
    		glNewList(fontOffset + j, GL_COMPILE);
    		glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, letters[i]);
    		glEndList();
    	}
    
    	glNewList(fontOffset + ' ', GL_COMPILE);
    	glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, space);
    	glEndList();
    }
    
    void Font::printString(char *s, Vertex *v)
    {
    	glColor3f(0.8, 0.8, 0.8);
    	glRasterPos3d(-0.7, 0.2, -0.7);
    	glPushAttrib(GL_LIST_BIT);
    	glListBase(fontOffset);
    	glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *) s);
    	glPopAttrib();
    }
    

    Jedoch wenn ich dann eine Instanz erstelle und printString(...) aufrufe kommt kein Text zum Vorschein:

    Font font;
    font.printString("HELLO", NULL);
    

    Kann mir jemand Helfen. 🙂



  • Zeig mal den RenderCode und wie du glOrtho eingestellt hast.



  • Gerendert wird das doch letztlich mit

    glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, letters[i]);
    

    siehe oben. 🙂

    Vorher mache ich im init-code

    int side = qMin(width, height);
    
    	glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
    
    	glOrtho(-2, 2, -2, 2, 5.0, 60.0);
    
        glViewport((width - side) / 2, (height - side) / 2, side, side);
    
    	glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    

    Wenn ich ein Objekt zeichne, sehe ich das auch....nur die schrift nicht



  • Ich weiss dass glBitmap der RenderCall ist in dem Fall, aber du musst doch eine Render-Loop haben oder nicht?
    Davon abgesehen hast du als zNear 5.0f.
    Ist die Kamera auch nah genug am Text dran, dass er erscheint?



  • In meiner Render-loop rufe ich immer wieder nur

    font.printString("HELLO", NULL);
    

    auf.

    Wenn ich in der Render-loop stattdessen ein Objekt zeichne, sehe ich das auch....



  • Hmm, sorry. Keine Idee woran es liegen könnte.
    Mal durch den gDebugger gejagt?

    Dass Display Listen nicht das gelbe vom Ei sind und glBitmap eigentlich nicht mehr verwendet wird, sollte ja bekannt sein :).

    Trotzdem solte es natürlich funktionieren, solange nicht der Treiber was dagegen hat.



  • Wie Scorcher schon sagte, hast du dein viewing-volume von z = 5.0 bis z = 60.0.
    Damit wird die RasterPosition ungültig und das glBitmap somit ignoriert.

    siehe glRasterPos
    und glBitmap

    Grüsse



  • Ich sehe auch keinen Text, wenn ich die nearClippingPlane auf -5.0 setze.



  • Dann sitzt der Text ja auch 5 Einheiten hinter der Kamera.....
    http://www.abload.de/img/camznpj.jpg

    Meine Ubar Paint Skills 😛



  • Ich schiebe vorher alles mit

    glTranslated(0.0, 0.0, -40.0);
    

    nach vorn.

    Außerdem ist sogar

    GL_CURRENT_RASTER_POSITION_VALID
    

    TRUE 😮



  • Es funktioniert. Ich hatte den Konstruktor von Font aufgerufen, bevor der Rendercontext da war...


Anmelden zum Antworten