glutBitmapCharacter()不';我什么也没展示?
我正在尝试使用OpenGL制作一个简单的文本输出,FreeGlut使用glutBitmapCharacter()不';我什么也没展示?,c,opengl,glut,freeglut,C,Opengl,Glut,Freeglut,我正在尝试使用OpenGL制作一个简单的文本输出,FreeGlut使用glutBitmapCharacter()。我的问题是,我没有显示任何文本。这个三角形很好用。我想问题不在于displayText()函数本身,但我可能在错误的位置调用它,或者重新绘制/清除文本?我使用gcc main.c-lGL-lglut-o文件名编译 #include <stdio.h> #include <string.h> #include <GL/freeglut.h> in
glutBitmapCharacter()
。我的问题是,我没有显示任何文本。这个三角形很好用。我想问题不在于displayText()
函数本身,但我可能在错误的位置调用它,或者重新绘制/清除文本?我使用gcc main.c-lGL-lglut-o文件名编译
#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;
}
#包括
#包括
#包括
内窗高度=500;
int窗宽=500;
void displayText(浮点x、浮点y、整数r、整数g、整数b、常量字符*字符串){
int j=strlen(字符串);
gl3f(r,g,b);
glRasterPos2f(x,y);
对于(int i=0;i
glRasterPos2f()
考虑当前矩阵堆栈,或者切换到glWindowPos()
(直接在窗口坐标中工作,绕过矩阵堆栈和视口变换),或者更改模型视图/投影矩阵以进行变换,其中(200,200)
未脱离屏幕。找到了解决方案。编译语句gcc main.c-lGL-lglut-lGLU-o exfilename中缺少参数(-lGLU)