Archived

This topic is now archived and is closed to further replies.

TheSyan

"OGL Camera's" and then "Renderin' Speed"

Recommended Posts

TheSyan    122
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???

Share this post


Link to post
Share on other sites
Penance    190
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
LoadIdentity();
rotate_translate_world();

glPushMatrix();
rotate_translate_object();
draw_object();
glPopMatrix();

glPushMatrix();
...
glPopMatrix();

glPush..
..
glPop..

..

2. Display lists, glDrawElements(), GL_TRIANGLE_STRIP, VAR, VAO

Share this post


Link to post
Share on other sites
TheSyan    122
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! ).


// 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[i].m_numTriangles; j++ )
{
int triangleIndex = m_pMeshes[i].m_pTriangleIndices[j];
const Triangle* pTri = &m_pTriangles[triangleIndex];

for ( int k=0; k < 3; k++ )
{
int index = pTri->m_vertexIndices[k];

see=false;

// CHECK IF COMPONENT OF NORMAL IN DIR OF CAMERA...
// 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 );
// if ( angle == 0 ) // Backface culling...
{
tv.x = m_pVertices[index].m_location[0];
tv.y = m_pVertices[index].m_location[1];
tv.z = m_pVertices[index].m_location[2];

Scalevector( tv, s );
Addvectors( tv, o );

glNormal3fv( pTri->m_vertexNormals[k] );
glTexCoord2f( pTri->m_s[k], pTri->m_t[k] );
glVertex3f( m_pVertices[index].m_location[0] * s,m_pVertices[index].m_location[1] * s,m_pVertices[index].m_location[2] * s );
}
}
}
}
glEnd();

if ( texEnabled )
glEnable( GL_TEXTURE_2D );
else
glDisable( GL_TEXTURE_2D );

if ( ligEnabled )
glEnable( GL_LIGHTING );
else
glDisable( GL_LIGHTING );

}
}

Also Don''t know anything about Quaternions but they sound excellent so Ill have a look!

Share this post


Link to post
Share on other sites
TheSyan    122
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!!

Share this post


Link to post
Share on other sites
George2    187
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.

Share this post


Link to post
Share on other sites