I have made a rotating cube and I got some performance drops while using two glRotatef calls. So basically this code is giving me 80FPS:
//code 1 GLrotate_x += 0.4f; GLrotate_y += 0.4f; glPushMatrix(); glRotatef( GLrotate_y, 0.0f, 1.0f, 0.0f ); glRotatef( GLrotate_x, 1.0f, 0.0f, 0.0f ); glTranslatef(multiplxGL+0.5f+spaceGL/2, -multiplyGL-0.5f-spaceGL/2, multiplzGL+0.5f+spaceGL/2); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, BUFFER_OFFSET(0)); glPopMatrix(); While this one is giving me 100FPS
//code 2 GLrotate_y += 0.4f; glPushMatrix(); glRotatef( GLrotate_y, 1.0f, 1.0f, 0.0f ); glTranslatef(multiplxGL+0.5f+spaceGL/2, -multiplyGL-0.5f-spaceGL/2, multiplzGL+0.5f+spaceGL/2); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, BUFFER_OFFSET(0)); glPopMatrix(); The rotate results from the rotation code 1 and code 2 are not the same (cube rotates different).I know that the code 1 is the most proper way here for the rotation but why the performance drops? Any chance of updating my code 1 to the performance of code 2?
On the other side in DirectX I use:
D3DXMatrixRotationYawPitchRoll(&matDXRotate, D3DXToRadian(DXrotate_y), D3DXToRadian(DXrotate_x), D3DXToRadian(0.0f)); and then
matDXStack->Push(); D3DXMatrixTranslation(&matDXmove, multiplxDX + 0.5f + spaceDX / 2, multiplyDX + 0.5f + spaceDX / 2, multiplzDX + 0.5f + spaceDX / 2); matDXStack->LoadMatrix(&(matDXmove*matDXRotate)); d3ddev->SetTransform(D3DTS_WORLD, matDXStack->GetTop()); d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 36, 0, 12); matDXStack->Pop(); Which gives me 100 FPS and rotate results same as code 1.
glRotatefwill cause performance drops, period. It’s been superseded by better mechanisms for 10 years and deprecated for 6 years now. You should learn yourself some modern OpenGL instead. \$\endgroup\$glRotatef (...)does not violate hardware T&L or anything like that (in fact, long before D3D invented the term "hardware T&L", GL was able to implement transforms on the server-side). The matrix stack and its associated transformations can be implemented completely on the GPU (server). In fact, creating a transformation matrix from a sequence ofglLoadIdentity (...),glTranslatef (...),glRotatef (...), etc. calls is sometimes quicker than transferring 16 floats usingglLoadMatrixf (...)orglUniformMatrix4fv (...). \$\endgroup\$