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

查看:35
本文介绍了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天全站免登陆