alternate rendering loop

This is a discussion on alternate rendering loop within the Game Programming forums, part of the General Programming Boards category; I have a loop that runs through polygons and verticies to render a model (the basic routine). It works fine, ...

  1. #1
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070

    Arrow alternate rendering loop

    I have a loop that runs through polygons and verticies to render a model (the basic routine). It works fine, except I need it to loop differently, to work with a collision library.

    Code:
    		glBegin( GL_TRIANGLES );
    		{
    			for ( int j = 0; j < objectP->m_pMeshes[i].m_numTriangles; j++ )
    			{
    				int triangleIndex = objectP->m_pMeshes[i].m_pTriangleIndices[j];
    				const Triangle *pTri = &objectP->m_pTriangles[triangleIndex];
    				
    				for ( int k = 0; k < 3; k++ )
    				{
    					int index = pTri->m_vertexIndices[k];
    					
    					glNormal3fv( pTri->m_vertexNormals[k] );
    					glTexCoord2f( pTri->m_s[k], pTri->m_t[k] );
    					glVertex3fv( objectP->m_pVertices[index].m_location );
    				}
    			}
    		}
    		glEnd();
    The bolded code is the main problem. For each triangle, it then loops through 3 verticies. I want it to do 3 verticies at once....
    Code:
    for(blah blah...<numtris..blah)
    {
        glVertex3f(...);
        glVertex3f(...);
        glVertex3f(...);
    }
    ...but i'm not sure how to go about it. Iv'e tried different things, but I just end up with severe poly scattering. I'm not sure if i'm making sense, but if I am, please help!

    thanx
    -psychopath
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    this should work unless i am missing something?

    Code:
    glBegin( GL_TRIANGLES );
    {
    	for ( int j = 0; j < objectP->m_pMeshes[i].m_numTriangles; j++ )
    	{
    		int triangleIndex = objectP->m_pMeshes[i].m_pTriangleIndices[j];
    		const Triangle *pTri = &objectP->m_pTriangles[triangleIndex];
    				
    		int index = pTri->m_vertexIndices[0];
    					
    		glNormal3fv( pTri->m_vertexNormals[0] );
    		glTexCoord2f( pTri->m_s[0], pTri->m_t[0] );
    		glVertex3fv( objectP->m_pVertices[index].m_location );
    
    		int index = pTri->m_vertexIndices[1];
    					
    		glNormal3fv( pTri->m_vertexNormals[1] );
    		glTexCoord2f( pTri->m_s[1], pTri->m_t[1] );
    		glVertex3fv( objectP->m_pVertices[index].m_location );
    
    		int index = pTri->m_vertexIndices[2];
    					
    		glNormal3fv( pTri->m_vertexNormals[2] );
    		glTexCoord2f( pTri->m_s[2], pTri->m_t[2] );
    		glVertex3fv( objectP->m_pVertices[index].m_location );
    	}
    }
    glEnd();
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    Naturally, the one thing I didn't try would be the solution :P.
    Thanx, It works perfectly. Now all I have to do is work out the bugs in the collision system. *cringes*

    -psychopath
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 10:44 AM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  3. scene graph rendering techniques
    By ichijoji in forum Game Programming
    Replies: 7
    Last Post: 03-18-2006, 11:17 PM
  4. while loop help
    By bliznags in forum C Programming
    Replies: 5
    Last Post: 03-19-2005, 11:30 PM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 08:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21