简体   繁体   English

glOrtho无法正常工作?

[英]glOrtho is not working?

 /* 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. 这是主要的简单opengl循环。

Recently, I come back to study Opengl (after leaving it for like 2 yrs). 最近,我回去学习Opengl(离开了2年之后)。 The problem is, I tried to use glOrtho to create 2D environment, but It is not working. 问题是,我试图使用glOrtho创建2D环境,但是它不起作用。 I mean, the program seems to ignore glOrtho call (no errors, no warnings, no projection, nothing). 我的意思是,该程序似乎忽略了glOrtho调用(没有错误,没有警告,没有投影,什么也没有)。 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?). 这将导致GL_TRIANGLE的顶点(0,1)到达窗口顶部,并且大于1.0f的任何东西都会从视口飞出(我认为这仍然是一个单位矩阵吗?)。 I tried changing the parameters but no changes occur in the vieewport. 我尝试更改参数,但在vieewport中未发生任何更改。 I don't know if I am missing something (maybe missing some initialization step or some deprecation that I am not aware of). 我不知道我是否缺少某些内容(也许缺少一些我不知道的初始化步骤或某些弃用)。

glOrtho(0.0f,512.0f,0.0f,512.0f,0.0f,1.0f);

This projection effectively selects the box of width 512, height 512 and depth 1 units to be the visible world space. 该投影有效地选择了宽度512,高度512和深度1单位的框作为可见世界空间。 However the vertices you specify will all be within a very small subset of the box, ie within one unit. 但是,您指定的顶点将全部位于该框的一个很小的子集中,即一个单位内。

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();

I think you just confused the use of glOrtho with glViewport. 我认为您只是将glOrtho与glViewport混淆了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM