OpenGL深度缓冲区问题
在我最近的几个项目中,我一直在使用一些在查看一些演示时发现的实用程序文件 在这里。
即一个名为 opengl.h 的文件 - 主要用于管理着色器,有点像 glew 和另一个文件 gl_font。
gl_font 是他们用来使用顶点缓冲区对象在屏幕上渲染字体的类。
但是,当我使用它来渲染游戏中的帧速率时,它会正确绘制除天空盒之外的所有内容。由于某种原因,天空盒呈现白色,如此处所示,如果我不渲染它看起来的字体就像这个。
以下是我认为最重要的 gl_font 类的一些部分:
void GLFont::begin()
{
HWND hWnd = GetForegroundWindow();
RECT rcClient;
GetClientRect(hWnd, &rcClient);
int w = rcClient.right - rcClient.left;
int h = rcClient.bottom - rcClient.top;
glPushAttrib(GL_CURRENT_BIT | GL_LIGHTING_BIT);
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_fontTexture);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0f, w, h, 0.0f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
drawTextBegin();
}
我尝试将 glPushAttrib(GL_CURRENT_BIT | GL_LIGHTING_BIT);
更改为 glPushAttrib(GL_CURRENT_BIT | GL_LIGHTING_BIT | GL_TEXTURE_BIT);背景纹理返回,但字体未渲染。
void GLFont::end()
{
drawTextEnd();
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPopAttrib();
}
这是渲染字体时深度缓冲区的图像,这就是实际情况的样子。
有人能解释一下这个问题吗?
任何帮助将不胜感激!
谢谢。
For my last few projects I have been using some of the utility files that I found whilst looking at a few demos here.
Namely a file called opengl.h - mainly used to manage shaders a bit like glew and another file gl_font.
gl_font is a class they use to render fonts on screen using vertex buffer objects.
However, when I use this to render the framerate in my game it draws everything but the skybox correctly. For some reason the skybox is rendered white as seen here, if I do not render the font it looks like this.
Here are some parts of the gl_font class that I think are most important:
void GLFont::begin()
{
HWND hWnd = GetForegroundWindow();
RECT rcClient;
GetClientRect(hWnd, &rcClient);
int w = rcClient.right - rcClient.left;
int h = rcClient.bottom - rcClient.top;
glPushAttrib(GL_CURRENT_BIT | GL_LIGHTING_BIT);
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_fontTexture);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0f, w, h, 0.0f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffer);
drawTextBegin();
}
I have trie changing glPushAttrib(GL_CURRENT_BIT | GL_LIGHTING_BIT);
to glPushAttrib(GL_CURRENT_BIT | GL_LIGHTING_BIT | GL_TEXTURE_BIT); and the background texture returns, but the font isn't rendered.
void GLFont::end()
{
drawTextEnd();
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPopAttrib();
}
This is an image of the depth buffer when the font is rendered and this is what is looks like when it is not.
Could anyone shed some light on this problem please?
Any help would be much appreciated!
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来
begin()
在glMatrixMode(GL_MODELVIEW)
之后缺少glPushMatrix()
。当某些文本也被渲染时,这可能会导致场景渲染不正确。glGetError()
不是报告了GL_STACK_UNDERFLOW
错误吗?Looks like
begin()
lacks aglPushMatrix()
afterglMatrixMode(GL_MODELVIEW)
. This might cause the scene to be rendered incorrectly when some text is also rendered.Didn't
glGetError()
report aGL_STACK_UNDERFLOW
error?