0

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.

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.

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.

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. My current code: (quad.vert[i].x*cosval)-(quad.vert[i].y*sinval) (twice, for y too).

Rookie
  • 4,064
  • 6
  • 54
  • 86
  • OpenGL doesn't even support glRotate. Use GLM. – Pubby Apr 29 '12 at 17:20
  • 1
    You need to describe what you are rendering. Also you need to state whether shaders are an option, as well as your target level of hardware/OpenGL version. – Nicol Bolas Apr 29 '12 at 17:22
  • @NicolBolas, shaders arent an option here. – Rookie Apr 29 '12 at 17:30
  • @Pubby, what do you mean? every time my "camera" rotates, its actually rebuilding all the vertices everywhere and sending them to GPU? i find that hard to believe since the FPS is quite fast on my other project that uses glRotatef() on a 3d scene with million vertices or more. – Rookie Apr 29 '12 at 17:33
  • 2
    @Rookie: "shaders arent an option here" And the rest of the questions? What you're rendering, target level of hardware, etc? You know, sufficient information needed to answer the question. – Nicol Bolas Apr 29 '12 at 17:50
  • Use a matrix and transform the points by multiplying it with the vertices. Otherwise look into 'instancing', but this will likely require shaders/extensions. – Pete Apr 29 '12 at 18:05
  • @NicolBolas, im rendering simple quads that rotate from the zero point, so my vertices would go from -10 to 10 for example. target level of hardware, as old as possible, the game will be super simple and i dont want to hear people whining "doesnt work on my crappy computer" etc, for a simple game like this. i probably do the rendering without opengl too later, so people with really bad computers can play it without having 1fps or so. at the moment im using this code: `(quad.vert[i].x*cosval)-(quad.vert[i].y*sinval)` (twice, for y too). when browsing the internets, i think that is fastest. – Rookie Apr 29 '12 at 18:37
  • @Pubby: It does. Although functions are "deprecated", they're still here. – SigTerm Apr 29 '12 at 19:05
  • @Rookie: "As old as possible" is unrealistic. I'm fairly certain your game will not work on Hercules/EGA/CGA display, no matter what you do. Pick some fairly new hardware for minimum requirements. OpenGL 2.0 has shaders, and it is supported by many cards today. – SigTerm Apr 29 '12 at 19:09
  • @SigTerm AFAIK it's been gone since 3.1 – Pubby Apr 29 '12 at 19:16
  • 1
    @Pubby: "compatibility profile". glRotatef is available in compatibility profile even in OpenGL 4.2. – SigTerm Apr 29 '12 at 19:47

1 Answers1

4

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.

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.

Edvard Pedersen
  • 723
  • 3
  • 12
  • But can you put glPushMatrix() in a display list? anyways, wouldnt vertex arrays be faster to render? – Rookie Apr 29 '12 at 18:33
  • @Rookie: Not in the way that you want to. But then again, you didn't exactly explain that you were rendering individual quads that each have their own separate transformation matrix until well after he posted the answer. All he did was take a reasonable guess, as most people don't render a bunch of individual quads; his advice would be good for someone rendering actual 3D meshes. – Nicol Bolas Apr 29 '12 at 18:49