如何完全像在OpenGL中使用glRotatef()那样旋转顶点? [英] How to rotate vertices exactly like with glRotatef() in OpenGL?

查看:99
本文介绍了如何完全像在OpenGL中使用glRotatef()那样旋转顶点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要优化渲染代码,目前我正在使用glPushMatrix()和glTranslatef()和glRotatef().但是,这比在单个顶点数组调用中呈现所有对象的成本更高.

I need to optimize my rendering code, currently I'm using glPushMatrix() with glTranslatef() and glRotatef(). But this costs more than rendering all objects in a single vertex array call.

OpenGL中是否有一些 fast 内置函数可以像glRotatef()那样完全旋转我的顶点数据?如果没有,您建议使用哪种库或方法?我知道的唯一方法是使用sin/cos函数旋转顶点,但是我不确定这是最快的方法,还是会导致相同的结果.

Is there some fast built in function in OpenGL to rotate my vertices data exactly like glRotatef() would do? If not, what library or method would you recommend using? The only method I know is to use sin/cos functions to rotate the vertices, but I'm not sure if that is the fastest way to do it, or will it even result in the same outcome.

每个对象(2D渲染)只需要绕一个轴旋转一次,因此它不需要太复杂,也不需要完全支持glPushMatrix()系统.

I only need to rotate along one axis once per object (2D rendering), so it doesn't need to be super complicated or support that glPushMatrix() system in its full potential.

编辑:我不想为此使用着色器.

I don't want to use shaders for this.

Edit2 :我仅渲染沿零点旋转的单个四边形(在2D模式下),因此每个顶点的值从-10变为10.我当前的代码:(quad.vert[i].x*cosval)-(quad.vert[i].y*sinval)(也是y的两倍).

I am only rendering individual quads (in 2D mode) which are rotated along the zero point, so each vertex would go from -10 to 10 values for example. My current code: (quad.vert[i].x*cosval)-(quad.vert[i].y*sinval) (twice, for y too).

推荐答案

我假设您使用的是旧版本的OpenGL,因为您使用的是glRotate,而您使用的是真正的古老/奇怪的硬件,因为您使用的是glRotate不想使用着色器.

I'm assuming you're using an old version of OpenGL, since you're using glRotate, and truly ancient/strange hardware since you don't want to use shaders.

您可以将glRotate*()调用放在显示列表中,或者自己计算旋转矩阵. OpenGL红皮书的第3章

You can put the glRotate*() calls in a display list, or compute the rotation matrices yourself. Chapter 3 of the OpenGL Red Book together with appendix F has the information you need to construct the matrices yourself. Look at chapter 7 for more information about display lists.

这篇关于如何完全像在OpenGL中使用glRotatef()那样旋转顶点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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