Advertisement

VBO and Quake3 bsp rendering

Started by February 28, 2005 07:13 AM
7 comments, last by b3rs3rk 19 years, 11 months ago
i've wrote a simple quake3 map renderer using vertex arrays but now i would like to use VBOs. I build VBO with this function (i call it during the LoadMap):

void CQuake3BSP::BuildVBOs()
{
	CVector3 *T_Verts = new CVector3[m_numOfVerts];
	CVector3 *T_Norms = new CVector3[m_numOfVerts];
	CVector2 *T_TextCoords = new CVector2[m_numOfVerts];

	for(int i=0;i<m_numOfVerts;i++){
		T_Verts = m_pVerts.vPosition;
		T_Norms = m_pVerts.vNormal;
		T_TextCoords = m_pVerts.vTextureCoord;
	}
	
	glGenBuffersARB( 1, &m_nVBOVertices );					
	glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOVertices );		
	glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_numOfVerts*sizeof(CVector3), T_Verts, GL_STATIC_DRAW_ARB );

	glGenBuffersARB( 1, &m_nVBONormals );					
	glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBONormals );		
	glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_numOfVerts*sizeof(CVector3), T_Norms, GL_STATIC_DRAW_ARB );

	glGenBuffersARB( 1, &m_nVBOTexCoords );					
	glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTexCoords );		
	glBufferDataARB( GL_ARRAY_BUFFER_ARB, m_numOfVerts*sizeof(CVector2), T_TextCoords, GL_STATIC_DRAW_ARB );
	
	glGenBuffersARB(1, &m_nVBOIndices);
	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_nVBOIndices);
	glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_numOfIndices*sizeof(int), m_pIndices, GL_STATIC_DRAW_ARB); 

	glBindBufferARB( GL_ARRAY_BUFFER_ARB, NULL );
    glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, NULL );

	delete [] T_Verts; T_Verts = NULL;
	delete [] T_TextCoords; T_TextCoords = NULL;

}

and i THINK it works (i get no error..). The problem is that when i render the map, i have on screen ONLY a single wall! I use this function for rendering:

void CQuake3BSP::RenderLevel()
{

		glEnable(GL_VERTEX_ARRAY);
		glEnable(GL_TEXTURE_COORD_ARRAY);
		glEnable(GL_NORMAL_ARRAY);
		glEnable(GL_INDEX_ARRAY );	

		glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTexCoords );
		glTexCoordPointer(2,GL_FLOAT,0, 0);
		glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBONormals );
		glNormalPointer( GL_FLOAT, 0, 0 );
		glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOVertices );
		glVertexPointer( 3, GL_FLOAT, 0, 0 );
		glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, m_nVBOIndices );

		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D,  decal);

		glDrawElements(GL_TRIANGLES, m_numOfIndices, GL_UNSIGNED_INT, 0 );
		
                glBindBufferARB( GL_ARRAY_BUFFER_ARB, NULL );
                glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, NULL );

		glDisable(GL_VERTEX_ARRAY);
		glDisable(GL_NORMAL_ARRAY);
		glDisable(GL_TEXTURE_COORD_ARRAY);
		glDisable(GL_TEXTURE_2D);
}

where is the error? any help is really welcome! [Edited by - b3rs3rk on February 28, 2005 7:42:12 AM]
m_numOfIndices to numVerts?
Game Core
Advertisement
@BGCJR: changes nothing :\
Hmmm dunno if that has to do with your problem but your enabling the "glEnable(GL_INDEX_ARRAY );" Index buffer. The index buffer does not have anything to do with indexed vertices. ( See here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc03_36lu.asp ) Ive never actually seen it used anywhere, so I guess you should disable it.
again, nothing :\
and disable normals?
Game Core
Advertisement
still nothing -_____-' i think that maybe it's better if i return to use vertex arrays...
A short notice- Array Enabling/Disabling is done through
glEnableClientState/glDisableClientState, not the usual glEnable/glDisable

Relative Games - My apps

changed my code to:
        tBSPFace *pFace = &m_pFaces[faceIndex];	glEnableClientState(GL_VERTEX_ARRAY);	glEnableClientState(GL_TEXTURE_COORD_ARRAY);	glEnableClientState(GL_NORMAL_ARRAY);	glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOTexCoords );	glTexCoordPointer(2,GL_FLOAT,0, 0);	glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBONormals );	glNormalPointer( GL_FLOAT, 0, 0 );	glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOVertices );	glVertexPointer( 3, GL_FLOAT, 0, 0 );	glEnableClientState(GL_VERTEX_ARRAY);	glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, m_nVBOIndices );	glEnable(GL_TEXTURE_2D);	glBindTexture(GL_TEXTURE_2D,  decal);	glDrawElements(GL_TRIANGLES, m_numOfIndices, GL_UNSIGNED_INT, 0 );		        glBindBufferARB( GL_ARRAY_BUFFER_ARB, NULL );        glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, NULL );	glDisableClientState(GL_VERTEX_ARRAY);	glDisableClientState(GL_NORMAL_ARRAY);	glDisableClientState(GL_TEXTURE_COORD_ARRAY);	glDisable(GL_TEXTURE_2D);


but now it hangs up on glDrawElements o_O I tryed also to use only the vertex array without the normal and the textures ones, but it still crashed..

This topic is closed to new replies.

Advertisement