我将Mac OSX 10.8中GLFW3.0.4中的“Simple example”示例修改为XCode 4.6项目(未更改时运行正常)。我正在使用外部库(通过着色器绘制)绘制(2D)矩形。我可以看到矩形但是如果我在它之前绘制样本三角形(立即绘制),则在第一个启动(框架)中看到三角形然后它就会丢失。如果我尝试绘制之后,就不会看到三角形。我只能看到矩形,我不知道库正在改变什么设置/状态!
我尝试使用OpenGL Profiler检查应用程序。在CGLFlushDrawable
之前停止,并且无法在任何缓冲区(正面,背面,深度,模板)中找到三角形。
我做某事(显着)错了吗?分析器仅允许gl函数断点。如何调试(更有效)并找到问题。
以下是(代码的大部分更改部分)代码:
void glfw2DViewport(GLFWwindow * window) {
float ratio;
int width, height;
glfwGetFramebufferSize(window, &width, &height);
ratio = width / (float) height;
glViewport(0, 0, width, height);
glClearColor(0.8, 0.8, 0.8, 1.0); // Lets see if something black is drawn!!
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// eye is at 0,0,0 looking to positive Z, -1(behind) to 1 are clipping planes:
// https://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml
glOrtho(ratio, -ratio, -1.f, 1.f, 1.0f, -1.f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// ----- 2D settings -----
glfwSwapInterval(1);
glEnable(GL_SMOOTH);
glDisable(GL_DEPTH_TEST);
//glDisable(GL_STENCIL_TEST); // Disabling changed nothing!!
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glLineWidth(5.0f);
glEnable(GL_LINE_SMOOTH);
glPointSize(5.0f);
glEnable(GL_POINT_SMOOTH);
}
int main(void) {
GLFWwindow* window;
glfwSetErrorCallback(error_callback);
if (!glfwInit())
exit(EXIT_FAILURE);
window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
if (!window) {
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
glfw2DViewport(window);
//...
while (!glfwWindowShouldClose(window)) {
glMatrixMode(GL_MODELVIEW_MATRIX);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);
//drawUnitTriangle(); // can be seen just in the first frame!
glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); // A vain attempt?
glPushAttrib(GL_ALL_ATTRIB_BITS); // Another vain attempt??
external_library_identity_matrix();
external_library_rectangle(POS,RED);
external_library_flush();
glPopAttrib();
glPopClientAttrib();
// Other vain attempts:
glfwMakeContextCurrent(window);
glMatrixMode(GL_MODELVIEW_MATRIX);
glLoadIdentity();
drawUnitTriangle(); // Nothing is Drawn!!
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
exit(EXIT_SUCCESS);
}
答案 0 :(得分:0)
您确定发布的代码正是您正在构建的代码吗?如果这是真的,请检查glMatrixMode()
的参数应该是GL_MODELVIEW
,而不是GL_MODELVIEW_MATRIX
。有两个地方可以像这样设置它。
由于您已经有glfw2DViewport()
,为什么不将它放在while
循环中并删除其他模型视图设置代码?