2017-09-06 5 views
0

J'essaie de faire une sortie de texte simple avec OpenGL, FreeGlut en utilisant glutBitmapCharacter(). Mon problème est que je ne reçois aucun texte. Le triangle fonctionne bien. Je suppose que le problème n'est pas la fonction displayText() lui-même, mais peut-être que je l'appelle au mauvais endroit ou redessiner/effacer le texte? Je compile avec gcc main.c -lGL -lglut -o filenameglutBitmapCharacter() n'affiche rien?

#include <stdio.h> 
#include <string.h> 
#include <GL/freeglut.h> 


int WindowHeight = 500; 
int WindowWidth = 500; 

void displayText(float x, float y, int r, int g, int b, const char *string) { 

    int j = strlen(string); 
    glColor3f(r, g, b); 
    glRasterPos2f(x, y); 
    for (int i = 0; i < j; i++) { 
     glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, string[i]); 
    } 
    printf("Lange: %i - Raster: %f %f", j, x, y); 

} 

void keyboard(unsigned char key, int x, int y) { 
    if (key == 27) 
     exit(0); 
    else 
     printf("Sie haben %c gedruckt.\n", key); 
} 

void display(void) { 


    glClearColor(1.0, 1.0, 1.0, 0); 
    glClear(GL_COLOR_BUFFER_BIT); 

    glLoadIdentity(); 

    glBegin(GL_LINE_LOOP); 
    glVertex3f(-0.3, -0.3, 0); 
    glVertex3f(0, 0.3, 0); 
    glVertex3f(0.3, -0.3, 0); 
    glEnd(); 

    displayText(200, 200, 0, 0, 255, "test"); 

    glFlush(); 
} 

int main(int argc, char **argv) { 


    glutInit(&argc, argv); 
    glutInitWindowSize(WindowWidth, WindowHeight); 
    glutInitWindowPosition(0, 0); 
    glutCreateWindow("Test"); 

    glutDisplayFunc(display); 
    glutKeyboardFunc(keyboard); 

    glutMainLoop(); 
    return 0; 
} 
+0

trouvé la solution. Un paramètre (-lGLU) était manquant dans l'instruction de compilation gcc main.c -lGL -lglut -lGLU -o exfilename –

Répondre

0

glRasterPos2f() prend la pile de matrice courante en compte, soit interrupteur à glWindowPos() (qui fonctionne directement en coordonnées fenêtre, en contournant la pile de matrices et de visualisation de transformation) ou modifier tes modelview/matrices de projection pour faire un transformer où (200, 200) n'est pas hors de l'écran.