glOrtho 不工作?
/* OpenGL animation code goes here */
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f,512.0f,0.0f,512.0f,0.0f,1.0f);
glMatrixMode(GL_MODELVIEW_MATRIX);
glPushMatrix ();
glLoadIdentity();
glTranslatef(x,y,0.0f);
//glRotatef (theta, 0.0f, 0.0f, 1.0f);
glBegin (GL_TRIANGLES);
glColor3f (1.0f, 0.0f, 0.0f); glVertex2f (0.0f, 1.0f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.8f, -0.5f);
glColor3f (0.0f, 0.0f, 1.0f); glVertex2f (-0.8f, -0.5f);
glEnd ();
glPopMatrix ();
SwapBuffers (hDC);
//theta += 0.1f;
Sleep(1);
}
这是主要的简单 opengl 循环。
最近,我回来学习Opengl(离开它两年了)。问题是,我尝试使用 glOrtho 创建 2D 环境,但它不起作用。我的意思是,该程序似乎忽略了 glOrtho 调用(没有错误,没有警告,没有投影,什么都没有)。这会导致 GL_TRIANGLE 的顶点 (0,1) 碰到窗口顶部,并且任何超过 1.0f 的东西都会飞离视口(我认为它仍然是单位矩阵?)。我尝试更改参数,但视口中没有发生任何变化。我不知道我是否遗漏了某些东西(可能缺少一些初始化步骤或一些我不知道的弃用)。
/* OpenGL animation code goes here */
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f,512.0f,0.0f,512.0f,0.0f,1.0f);
glMatrixMode(GL_MODELVIEW_MATRIX);
glPushMatrix ();
glLoadIdentity();
glTranslatef(x,y,0.0f);
//glRotatef (theta, 0.0f, 0.0f, 1.0f);
glBegin (GL_TRIANGLES);
glColor3f (1.0f, 0.0f, 0.0f); glVertex2f (0.0f, 1.0f);
glColor3f (0.0f, 1.0f, 0.0f); glVertex2f (0.8f, -0.5f);
glColor3f (0.0f, 0.0f, 1.0f); glVertex2f (-0.8f, -0.5f);
glEnd ();
glPopMatrix ();
SwapBuffers (hDC);
//theta += 0.1f;
Sleep(1);
}
This is the main simple opengl loop.
Recently, I come back to study Opengl (after leaving it for like 2 yrs). The problem is, I tried to use glOrtho to create 2D environment, but It is not working. I mean, the program seems to ignore glOrtho call (no errors, no warnings, no projection, nothing). This causes the vertex (0,1) of GL_TRIANGLE to hit the top of windows, and anything more than 1.0f will fly off the viewport (it is still an identity matrix I think?). I tried changing the parameters but no changes occur in the vieewport. I don't know if I am missing something (maybe missing some initialization step or some deprecation that I am not aware of).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该投影有效地选择宽度为 512、高度为 512、深度为 1 单位的框作为可见世界空间。然而,您指定的顶点将全部位于框的一个非常小的子集内,即在一个单位内。
我认为您只是混淆了 glOrtho 和 glViewport 的使用。
This projection effectively selects the box of width 512, height 512 and depth 1 units to be the visible world space. However the vertices you specify will all be within a very small subset of the box, i.e. within one unit.
I think you just confused the use of glOrtho with glViewport.