c++屏幕上未显示文本
c++ Text not showing on screen
我正试图使用此代码将文本打印到屏幕上。
int main(int argc, char* argv[]) {
glutInit(&argc, argv);
glutInitWindowSize(640, 480);
int WindowHandle = glutCreateWindow("Maze");
if (WindowHandle < 1) {
fprintf(stderr, "ERROR: Could not create a new rendering window.n");
exit(EXIT_FAILURE);
}
//Initialize OpenGL
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//Initialize the viewport
glViewport(0, 0, 640, 480);
//Initialize OpenGL projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, 640.0f, 480.0f, 0.0f, -2.0f, 2.0f);
//Clear back buffer
glClear(GL_COLOR_BUFFER_BIT);
//Create font
GLuint textureName;
glGenTextures(1, &textureName);
PixelPerfectGLFont font;
try {
font.Create("fonts\quad20.glf", textureName);
}
catch(GLFontError::InvalidFile) {
cerr << "Cannot load fontn";
abort();
}
//Draw some stuff
glMatrixMode(GL_MODELVIEW);
glLoadIdentity( );
glEnable(GL_TEXTURE_2D);
glColor3f(1.0f, 0.0f, 0.0f);
try {
font.Begin();
font.TextOut("hello world", 50, 50, 0);
}
catch(GLFontError::InvalidFont) {
cerr << "Trying to draw with an uninitialized fontn";
abort();
}
glDisable(GL_TEXTURE_2D);
glLoadIdentity();
glutMainLoop();
return 0;
}
把这个代码放在一个main.cpp文件中,它就会运行(假设你有正确的链接器)
在代码的顶部,我有
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glew.h>
#include <GL/glut.h>
#endif
#include "glfont.h"
要使用glfont.h,您可以在顶部添加using namespace std;
(否则会引发编译错误)
所以。。。当我运行应用程序时,它只显示一个白色屏幕,没有显示文本。
有人能告诉我我做错了什么吗?
p.s.glfont可以在这里找到http://students.cs.byu.edu/~bfish/glfontdl.php
有人能告诉我我做错了什么吗?
一切。
这根本不是使用GLUT渲染的方式。您应该注册当GLUT准备好显示内容时将被调用的回调。你从不交换缓冲区或任何东西,所以你不会看到东西。等等。
看看你能找到的任何GLUT例子,你会发现它看起来不是这样的。
在开始玩文本渲染之前,您应该首先了解常规渲染。
相关文章:
- 尝试使用 WinBGI 显示文本时出现编译器错误
- 动态填充的组合框不显示文本,列表未定义
- QTreeWidgetItem 突出显示文本问题
- 如何通过单击按钮在QTextEdit中显示文本?
- 在C Windows程序中显示文本文件内容
- findChild 从不显示文本浏览器
- C 在同一行中左右显示文本
- 使用 C++ 中的向量在新行上显示文本文件中的列
- 如何使用 Opengl 库显示文本文件中的 3D 点
- Qt. 方法显示文本() 如果我在 QStyledItemDelegate 中定义了 paint() 方法不起作用
- 如何在C 中的OpenGL中通过矩形显示文本
- 如何使用键盘输入和sf ::文本在SFML中添加一种文本框以显示文本字符串
- QMessageBox:无法在框中显示文本(使用 c++)
- 延迟窗口在 MFC 上显示文本
- Visual Studio代码集成的终端未显示文本
- SFML-不显示文本
- qprogressdialog未显示文本标签
- C++程序无法正确显示文本文件中的内容
- 如何在不显示文本的情况下分配Win32编辑控件的窗口名称
- SDL2 OpenGL SDL2_TTF:显示文本