2017-09-06 21 views
0

OpenGL、FreeGlutで単純なテキスト出力をglutBitmapCharacter()を使って作成しようとしています。私の問題は、テキストが表示されないことです。三角形はうまく動作します。私は問題がdisplayText()関数自体ではないと思いますが、間違った場所で呼び出すか、テキストを再描画/クリアすることができますか?私はgcc main.c -lGL -lglut -o filenameglutBitmapCharacter()に何も表示されませんか?

#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

が見つかりました。コンパイル文にパラメータ(-lGLU)がありません gcc main.c -lGL -lglut -lGLU -o exfilename –

答えて

0

glRasterPos2f()でコンパイルするには、アカウントに(変換行列スタックとビューポートをバイパスして、ウィンドウ座標で直接動作します)glWindowPos()にスイッチまたは作るためにあなたのモデルビュー/投影行列を変更するのいずれかを現在の行列スタックを取ります(200, 200)はオフスクリーンではありません。

関連する問題