C Board  

Go Back   C Board > General Programming Boards > Game Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-16-2005, 09:50 AM   #1
The Right Honourable
 
psychopath's Avatar
 
Join Date: Mar 2004
Location: Where circles begin.
Posts: 1,068
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.
psychopath is offline   Reply With Quote
Old 07-16-2005, 11:20 AM   #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.
no-one is offline   Reply With Quote
Old 07-16-2005, 12:30 PM   #3
The Right Honourable
 
psychopath's Avatar
 
Join Date: Mar 2004
Location: Where circles begin.
Posts: 1,068
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.
psychopath is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
My loop within loop won't work Ayreon C Programming 3 03-18-2009 10:44 AM
Personal Program that is making me go wtf? Submeg C Programming 20 06-27-2006 12:13 AM
scene graph rendering techniques ichijoji Game Programming 7 03-19-2006 12:17 AM
while loop help bliznags C Programming 5 03-20-2005 12:30 AM
loop issues kristy C Programming 3 03-05-2005 09:14 AM


All times are GMT -6. The time now is 09:31 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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