gpt4 book ai didi

c - glutBitmapCharacter() 不显示任何内容?

转载 作者:太空宇宙 更新时间:2023-11-04 03:21:10 27 4
gpt4 key购买 nike

我正在尝试使用 OpenGL、FreeGlut 使用 glutBitmapCharacter() 进行简单的文本输出。我的问题是,我没有显示任何文字。三角形工作正常。我想问题不是 displayText() 函数本身,而是我在错误的地方调用它或重绘/清除文本?我用 gcc main.c -lGL -lglut -o filename

编译
#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;
}

最佳答案

glRasterPos2f() 将当前矩阵堆栈考虑在内,或者切换到 glWindowPos()(直接在窗口坐标中工作,绕过矩阵堆栈和视口(viewport)变换)或者更改您的模型 View /投影矩阵以在 (200, 200) 不在屏幕外的地方进行转换。

关于c - glutBitmapCharacter() 不显示任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46084716/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com