"OGL Camera's" and then "Renderin' Speed"
O.k. this questions probably been asked a 1000 times, but here goes. What is the best method for coding a camera in ogl. I''ve written a camera class using the gluLookAt() command, but its a bit messy and im sure there are advantages to using some crazy combination of glTranslates and glRotates... I thought u might be able to render/rotate/translate each object, and then translate the whole world to implement the camera view, but when I tried it, every subsequent object I rendered, ended up screwing up the position of the others. Any advice?
Second part. I''ve written several classes for rendering models/objects in an OGL world, but in every one, the fps is tiny when the model has over 200 polys. I know there must be some tricks to getting this moving quicker... Again and advice would help???
For the camera: Quaternions.
What kind of machine are you running your program on?
It would be hard to point out what''s wrong unless you posted some code snippets because it''s probably just an efficiency issue.
What kind of machine are you running your program on?
It would be hard to point out what''s wrong unless you posted some code snippets because it''s probably just an efficiency issue.
LoadIdentity();
rotate_translate_world();
glPushMatrix();
rotate_translate_object();
draw_object();
glPopMatrix();
glPushMatrix();
...
glPopMatrix();
glPush..
..
glPop..
..
2. Display lists, glDrawElements(), GL_TRIANGLE_STRIP, VAR, VAO
rotate_translate_world();
glPushMatrix();
rotate_translate_object();
draw_object();
glPopMatrix();
glPushMatrix();
...
glPopMatrix();
glPush..
..
glPop..
..
2. Display lists, glDrawElements(), GL_TRIANGLE_STRIP, VAR, VAO
My Systems quite hight spec so I would n''t think its that...
As for code... Here''s the code for rendering a .MS3D file im using. It has some primitive face culling stuff in there as well, which I wrote before I found out u could turn it on in OGL. (forgoten the prefix for entering code, so the formattings probably whack! ).
As for code... Here''s the code for rendering a .MS3D file im using. It has some primitive face culling stuff in there as well, which I wrote before I found out u could turn it on in OGL. (forgoten the prefix for entering code, so the formattings probably whack! ).
// Draw by group for ( int i=0;i< m_numMeshes; i++) { int materialIndex = m_pMeshes.m_materialIndex; if (materialIndex >= 0 ) { glMaterialfv( GL_FRONT, GL_AMBIENT, m_pMaterials[materialIndex].m_ambient ); glMaterialfv( GL_FRONT, GL_DIFFUSE, m_pMaterials[materialIndex].m_diffuse ); glMaterialfv( GL_FRONT, GL_SPECULAR, m_pMaterials[materialIndex].m_specular); glMaterialfv( GL_FRONT, GL_EMISSION, m_pMaterials[materialIndex].m_emissive ); glMaterialf( GL_FRONT, GL_SHININESS, m_pMaterials[materialIndex].m_shininess ); if ( m_pMaterials[materialIndex].m_texture > 0 ) { glBindTexture( GL_TEXTURE_2D, m_pMaterials[materialIndex].m_texture ); glEnable( GL_TEXTURE_2D ); glEnable( GL_LIGHTING ); } else glDisable( GL_TEXTURE_2D ); glEnable( GL_LIGHTING ); } else { glDisable( GL_TEXTURE_2D ); glEnable( GL_LIGHTING ); } glBegin( GL_TRIANGLES ); { for( int j=0; j < m_pMeshes.m_numTriangles; j++ )<br> {<br> int triangleIndex = m_pMeshes.m_pTriangleIndices[j];<br> const Triangle* pTri = &m_pTriangles[triangleIndex];<br><br> for ( int k=0; k < 3; k++ )<br> {<br> int index = pTri->m_vertexIndices[k];<br> <br> see=false;<br> <br> // CHECK IF COMPONENT OF NORMAL IN DIR OF CAMERA…<br>// angle = ( pTri->m_vertexNormals[k][0] * OGL->Camera.N.x ) + (pTri->m_vertexNormals[k][1] * OGL->Camera.N.y ) + ( pTri->m_vertexNormals[k][2] * OGL->Camera.N.z );<br>// if ( angle == 0 ) // Backface culling…<br> {<br> tv.x = m_pVertices[index].m_location[0];<br> tv.y = m_pVertices[index].m_location[1];<br> tv.z = m_pVertices[index].m_location[2];<br><br> Scalevector( tv, s );<br> Addvectors( tv, o );<br><br> glNormal3fv( pTri->m_vertexNormals[k] );<br> glTexCoord2f( pTri->m_s[k], pTri->m_t[k] );<br> glVertex3f( m_pVertices[index].m_location[0] * s,m_pVertices[index].m_location[1] * s,m_pVertices[index].m_location[2] * s );<br> }<br> }<br> }<br> }<br> glEnd();<br><br> if ( texEnabled )<br> glEnable( GL_TEXTURE_2D );<br> else<br> glDisable( GL_TEXTURE_2D );<br><br> if ( ligEnabled )<br> glEnable( GL_LIGHTING );<br> else<br> glDisable( GL_LIGHTING );<br><br> }<br>}<br><br>Also Don''t know anything about Quaternions but they sound excellent so Ill have a look! </i> </pre>
Oh, forgot about the other post, er VAR??, VAO?? But thanks for the correct method with the matricies! That''l fit nicley in with my code!!
quote:Original post by TheSyan
Oh, forgot about the other post, er VAR??, VAO?? But thanks for the correct method with the matricies! That''l fit nicley in with my code!!
VAR (Vertex array range) is an nvidia specific extension to speed up rendering with vertex array''s, check the nvidia docs for more info on it. VAO (Vertex array object) is about the same but for ATI cards.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement