【发布时间】:2015-07-19 11:37:28
【问题描述】:
我正在尝试获取 OpenGL 纹理以在屏幕上以 2D 形式呈现。我知道这看起来很简单,但我是 OpenGL 新手,这给我带来了一些麻烦。
无论我尝试什么,它都显示为白色。
我已经看到了像OpenGL renders texture all white 这样的其他问题,并检查了清单上的所有内容,但我似乎无法弄清楚来源,我非常感谢任何帮助。
我很确定我只是在某个地方犯了一些愚蠢的错误,并尝试废弃我的代码并重写了几次。
这是与从 main 方法运行的窗口相关的代码。
//Window is a custom wrapper for GLFWwindow
Window thirdwindow(window_width, window_height, "Three");
thirdwindow.show();
thirdwindow.setPosition(300, 300);
ThirdLoop(thirdwindow);
这里是第三循环:
static void ThirdLoop(Window& win)
{
GLuint tex = loadBMP("cat.bmp");
auto size = win.getWindowSize();
win.beginDraw();
while (running)
{
if (win.isClosing())
running = false;
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the color buffer (background)
DrawImage(size, tex);
win.render();
Update();
}
}
还有 DrawImage(对于这里奇怪的缩进表示歉意,复制粘贴的东西)
void DrawImage(const Size<int>& size, GLuint texture) {
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, size.width, 0.0, size.height, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
// Draw a textured quad
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(0, 1); glVertex3f(0, 100, 0);
glTexCoord2f(1, 1); glVertex3f(100, 100, 0);
glTexCoord2f(1, 0); glVertex3f(100, 0, 0);
glEnd();
glDisable(GL_TEXTURE_2D);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
loadBMP 取自 http://www.opengl-tutorial.org/beginners-tutorials/tutorial-5-a-textured-cube/。
【问题讨论】:
-
您是否尝试过通过 GPU 调试器运行它?如果您使用的是 AMD 卡,则类似于 GPU Perf Studio;我认为 NVIDIA 也有类似的东西。
标签: c++ opengl graphics 2d textures