opengl:将原点更改为左上角 [英] opengl: Change the origin to upper left corner

查看:452
本文介绍了opengl:将原点更改为左上角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将openGL原点设置到视图的左上角时遇到麻烦。因此,在我的窗口调整大小处理程序中,我做以下事情:

I am having trouble setting the openGL origin to the upper left corner of the view. So, in my window resize handler, I do something as;

// ox and oy are some offsets and width and height are the 
// required viewport width and height
glViewport(ox, oy, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

这会将原点保留在左下角,我可以将纹理渲染为:

This keeps the origin at bottom left and I can render my texture as:

glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(0, 0); 
glTexCoord2f(1, 0); glVertex2f(width, 0);                            
glTexCoord2f(1, 1); glVertex2f(width, height);                      
glTexCoord2f(0, 1); glVertex2f(0, height);                 
glEnd();

据我在这里阅读的页面所知,翻转原点我只需要替换一下glOrtho调用

As far as I can tell from reading the pages here, to flip the origin I simply need to replace the glOrtho call with

glOrtho(0, width, height, 0, -1, 1);

但是,执行此操作并使用上面的渲染代码不再渲染我的纹理,我只看到一个

However, doing this and using the render code above does not render my texture anymore and I just see a blank screen.

推荐答案

通过在y轴上翻转,您可以翻转世界空间的手性。这意味着您的脸部弯曲会有所不同。 CCW变为CW,反之亦然。很可能您启用了脸部剔除,因此要考虑手性翻转,您必须将CCW换成CW脸部剔除。

By flipping around the y-axis you flipped the chirality of the world space. Which means that the winding of your faces comes out differently. CCW becomes CW and vice versa. Most likely you have face culling enabled, so to account for the chirality flip you have to swap CCW for CW face culling.

这篇关于opengl:将原点更改为左上角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆