当前位置: 首页>>代码示例>>C++>>正文


C++ SurfaceMesh::getIndices方法代码示例

本文整理汇总了C++中SurfaceMesh::getIndices方法的典型用法代码示例。如果您正苦于以下问题:C++ SurfaceMesh::getIndices方法的具体用法?C++ SurfaceMesh::getIndices怎么用?C++ SurfaceMesh::getIndices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SurfaceMesh的用法示例。


在下文中一共展示了SurfaceMesh::getIndices方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: BuildOpenGLSurfaceMesh

OpenGLSurfaceMesh BuildOpenGLSurfaceMesh(const SurfaceMesh<PositionMaterialNormal>& mesh)
{
	//Represents our filled in OpenGL vertex and index buffer objects.
	OpenGLSurfaceMesh result;

	//The source
	result.sourceMesh = &mesh;

	//Convienient access to the vertices and indices
	const vector<PositionMaterialNormal>& vecVertices = mesh.getVertices();
	const vector<uint32_t>& vecIndices = mesh.getIndices();

	//If we have any indices...
	if(!vecIndices.empty())
	{
		//Create an OpenGL index buffer
		glGenBuffers(1, &result.indexBuffer);
		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, result.indexBuffer);

		//Get a pointer to the first index
		GLvoid* pIndices = (GLvoid*)(&(vecIndices[0]));		

		//Fill the OpenGL index buffer with our data. 
		glBufferData(GL_ELEMENT_ARRAY_BUFFER, vecIndices.size() * sizeof(uint32_t), pIndices, GL_STATIC_DRAW);
	}

	result.noOfIndices = vecIndices.size();

	glGenBuffers(1, &result.vertexBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, result.vertexBuffer);
	glBufferData(GL_ARRAY_BUFFER, vecVertices.size() * sizeof(GLfloat) * 9, 0, GL_STATIC_DRAW);
	GLfloat* ptr = (GLfloat*)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);

	for(vector<PositionMaterialNormal>::const_iterator iterVertex = vecVertices.begin(); iterVertex != vecVertices.end(); ++iterVertex)
	{
		const PositionMaterialNormal& vertex = *iterVertex;
		const Vector3DFloat& v3dVertexPos = vertex.getPosition();
		//const Vector3DFloat v3dRegionOffset(uRegionX * g_uRegionSideLength, uRegionY * g_uRegionSideLength, uRegionZ * g_uRegionSideLength);
		const Vector3DFloat v3dFinalVertexPos = v3dVertexPos + static_cast<Vector3DFloat>(mesh.m_Region.getLowerCorner());

		*ptr = v3dFinalVertexPos.getX();
		ptr++;
		*ptr = v3dFinalVertexPos.getY();
		ptr++;
		*ptr = v3dFinalVertexPos.getZ();
		ptr++;

		*ptr = vertex.getNormal().getX();
		ptr++;
		*ptr = vertex.getNormal().getY();
		ptr++;
		*ptr = vertex.getNormal().getZ();
		ptr++;

		uint8_t material = vertex.getMaterial() + 0.5;

		OpenGLColour colour = convertMaterialIDToColour(material);

		*ptr = colour.red;
		ptr++;
		*ptr = colour.green;
		ptr++;
		*ptr = colour.blue;
		ptr++;
	}

	glUnmapBuffer(GL_ARRAY_BUFFER);

	return result;
}
开发者ID:alexis-,项目名称:iwe,代码行数:70,代码来源:OpenGLVertexBufferObjectSupport.cpp


注:本文中的SurfaceMesh::getIndices方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。