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


C++ Array::GetElements方法代码示例

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


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

示例1: LoadMesh

	bool Graphics::LoadMesh(Mesh * aMesh, GLuint & aVBO, GLuint & aIBO)
	{
		//TODO: Load the mesh data into OpenGL
		if (aMesh == nullptr)
		{
			return false;
		}

		if (aMesh->IsUploaded())
		{
			Debug::Error("Graphics", "Cannot upload the mesh. It's already uploaded. Release the resources before attempting to upload.");
			return false;
		}

		Array<Vector3> positions = aMesh->GetPositions();
		Array<Vector3> normals = aMesh->GetNormals();
		Array<Vector2> texCoords = aMesh->GetTexCoords();
		Array<Color> colors = aMesh->GetColors();
		Array<UInt16> indices = aMesh->GetIndicies();

		UInt32 count = positions.GetCount();
		if (count != normals.GetCount() ||
			count != texCoords.GetCount() ||
			count != colors.GetCount()
			)
		{
			Debug::ErrorFormat("Graphics", nullptr, "There is a different number of attributes in this mesh %s", aMesh->GetName().c_str());
			return false;
		}

		Array<VertexAttribute> attributes;
		attributes.Allocate(count);

		for (unsigned int i = 0; i < count; i++)
		{
			//Position
			attributes[i].position[0] = positions[i].x;
			attributes[i].position[1] = positions[i].y;
			attributes[i].position[2] = positions[i].z;

			//Normals
			attributes[i].normal[0] = normals[i].x;
			attributes[i].normal[1] = normals[i].y;
			attributes[i].normal[2] = normals[i].z;

			//Tex Coords
			attributes[i].texCoord[0] = texCoords[i].x;
			attributes[i].texCoord[1] = texCoords[i].y;

			//Colors
			attributes[i].color[0] = colors[i].r;
			attributes[i].color[1] = colors[i].g;
			attributes[i].color[2] = colors[i].b;
			attributes[i].color[3] = colors[i].a;
		}

		//Send to OpenGL
		glGenBuffers(1, &aVBO);
		glBindBuffer((GLenum)BufferTarget::Array, aVBO);
		glBufferData((GLenum)BufferTarget::Array, sizeof(VertexAttribute)* count, attributes.GetElements(), (GLenum)BufferMode::StaticDraw);
		glBindBuffer((GLenum)BufferTarget::Array, 0);

		glGenBuffers(1, &aIBO);
		glBindBuffer((GLenum)BufferTarget::ElementArray, aIBO);
		glBufferData((GLenum)BufferTarget::ElementArray, sizeof(GLshort)* indices.GetCount(), indices.GetElements(), (GLenum)BufferMode::StaticDraw);
		glBindBuffer((GLenum)BufferTarget::ElementArray, 0);

		return true;
	}
开发者ID:NathanSaidas,项目名称:Gem,代码行数:69,代码来源:Graphics.cpp


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