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


C++ GLSLProgram::getAttribLocation方法代码示例

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


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

示例1: initializeVertexArrayObject

/*
* Create the Vertex Array Object
* @param _coloProgram is the object that manages the data related to the shaders
*/
void OpenGLBuffers::initializeVertexArrayObject(GLSLProgram & _colorProgram) {	
		// Bind the VAO. All subsequent opengl calls will modify it's state.
	glBindVertexArray(gVAO);

		//Bind the buffer object. YOU MUST BIND the buffer vertex object before binding attributes
	glBindBuffer(GL_ARRAY_BUFFER, gVBO);
	
		//Connect the xyz to the "vertexPosition" attribute of the vertex shader
	glEnableVertexAttribArray(_colorProgram.getAttribLocation("vertexPosition"));
		//Connect the rgba to the "vertexColor" attribute of the vertex shader
	glEnableVertexAttribArray(_colorProgram.getAttribLocation("vertexColor"));

	//Point Opengl to the data in our VBO
	/* The vertexPosition attribute refers to the 3D position
	The first argument is the shader variable that the data should be sent to
	The second argument, 3, says that each vertex has three numbers
	The third argument, GL_FLOAT, says that the three numbers are GLfloats
	The fourth argument, GL_FALSE, says that we do not want the floats to be "normalized." If they were normalized, they would be restricted to having a minimum of zero, and a maximum of one. We don't want that restriction on our points, which is why this argument is false.
	The fifth argument, sizeof(Vertex), says that the information in the buffer vertex object will be composed by elements of the type Vertex
	The sixth argument, (void*)offsetof(Vertex, position), says where starts this kind of information in the vertex buffer object
	*/
	glVertexAttribPointer(_colorProgram.getAttribLocation("vertexPosition"), 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),(void*)offsetof(Vertex, position));
	

	/* The vertexColor attribute refers to the color in RGBA components
	The first argument is the shader variable that the data should be sent to
	The second argument, 4, says that the color contains 4 numbers
	The third argument, GL_UNSIGNED_BYTE, says that the  numbers are GLubyte
	The fourth argument, GL_TRUE, allows to normalize values between 0 and 1
	The fifth argument, sizeof(Vertex), says that the information in the buffer vertex object will be composed by elements of the type Vertex
	The sixth argument, (void*)offsetof(Vertex, color), says where starts this kind of information in the vertex buffer object
	*/
	glVertexAttribPointer(_colorProgram.getAttribLocation("vertexColor"), 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), (void*)offsetof(Vertex, color));

	// unbind the VAO and VBO
	glBindVertexArray(0);
	glBindBuffer(GL_ARRAY_BUFFER,0);
}
开发者ID:efarriol,项目名称:Mecanica,代码行数:42,代码来源:OpenGLBuffers.cpp


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