OpenGL的坐标匹配屏幕坐标? [英] OpenGL coordinates to match screen coordinates?

查看:425
本文介绍了OpenGL的坐标匹配屏幕坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安卓的OpenGL ES视图的问题。因此,在OpenGL中,相机和视图的默认位置是0,0。你如何设置视图和摄像头,这样它的行为基本上是相同的,与0,0电脑屏幕坐标顶部。我叫gl.glOrthof(-screenWidth / 2,屏幕宽度/ 2,-ScreenHeight / 2,ScreenHeight / 2)。但我认为这是不对的。我还需要将相机设置为整个视野。我不知道如何使用gl.glFrustumf来完成这项任务。

Android opengl-es view question. So in openGL, the default position of the camera and view is at 0,0. How do you set the view and camera so that it acts basically the same as computer screen coordinates with 0,0 at the top. I've called gl.glOrthof(-screenWidth/2, ScreenWidth/2, -ScreenHeight/2, ScreenHeight/2). But I think this is wrong. I also need to set the camera to view the entire field. I'm not sure how to use gl.glFrustumf to accomplish this task.

推荐答案

要使用你的顶点坐标为屏幕坐标,只需使用 glOrtho(0,宽度,高度,0,-1,1)上的投影矩阵,并保持你的模型视图矩阵的身份(这是默认值)。请注意,我翻转底部和顶部,如GL(0,0)在左下角和你在顶部希望它(但请记住,这也翻转每个对象,因此三角形排序)。你也忘了设置近及远的飞机(一切与AZ走出这个区间将不会被显示出来)。但是,当你现在画以Z所有对象= 0(这是默认值,仅绘制2D顶点的时候),都应该罚款。

To use your vertex coordinates as screen coordinates, just use glOrtho(0, width, height, 0, -1, 1) on the projection matrix and keep your modelview matrix identity (which is the default). Note that I flipped bottom and top, as in GL (0,0) is at the lower left and you want it at the top (but keep in mind that this also flips every object and therefore the triangle ordering). You also forgot to set the near and far planes (everything with a z out of this interval won't get displayed). But when you now draw all your objects with z=0 (which is the default, when drawing only 2d vertices), all should be fine.

glFrustum 只是一个替代品 glOrtho 。其中, glOrtho constrcuts正交(并行)认为, glFrustum 构造的立体图。所以,你不需要 glFrustum

glFrustum is just an alternative to glOrtho. Where glOrtho constrcuts an orthographic (parallel) view, glFrustum constructs a perspective view. So you don't need glFrustum.

这篇关于OpenGL的坐标匹配屏幕坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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