简体   繁体   English

如何在OpenGL中完全像glRotatef()那样旋转顶点?

[英]How to rotate vertices exactly like with glRotatef() in OpenGL?

I need to optimize my rendering code, currently I'm using glPushMatrix() with glTranslatef() and glRotatef(). 我需要优化渲染代码,目前我正在使用glPushMatrix()和glTranslatef()和glRotatef()。 But this costs more than rendering all objects in a single vertex array call. 但是,这比在单个顶点数组调用中呈现所有对象的成本更高。

Is there some fast built in function in OpenGL to rotate my vertices data exactly like glRotatef() would do? OpenGL中是否有一些快速内置函数来像glRotatef()那样旋转我的顶点数据? 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. 我知道的唯一方法是使用sin / cos函数旋转顶点,但是我不确定这是最快的方法,还是会导致相同的结果。

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. 我只需要每个对象沿一个轴旋转一次(2D渲染),因此它不需要太复杂,也不需要完全支持glPushMatrix()系统。

Edit: I don't want to use shaders for this. 编辑:我不想为此使用着色器。

Edit2: 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. Edit2:我仅渲染沿零点旋转的单个四边形(在2D模式下),因此每个顶点的值从-10到10。 My current code: (quad.vert[i].x*cosval)-(quad.vert[i].y*sinval) (twice, for y too). 我当前的代码: (quad.vert[i].x*cosval)-(quad.vert[i].y*sinval) (也是y的两倍)。

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. 我假设您使用的是OpenGL的旧版本,因为您使用的是glRotate ,并且由于您不想使用着色器而确实是古老的/奇怪的硬件。

You can put the glRotate*() calls in a display list, or compute the rotation matrices yourself. 您可以将glRotate*()调用放在显示列表中,或者自己计算旋转矩阵。 Chapter 3 of the OpenGL Red Book together with appendix F has the information you need to construct the matrices yourself. OpenGL红皮书的第3章以及附录F提供了您自己构建矩阵所需的信息。 Look at chapter 7 for more information about display lists. 有关显示列表的更多信息,请参见第7章。

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

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