您的位置:首页 > 运维架构

关于CCTexure2D使用opengl实现绘制的原理分析

2013-08-18 19:55 579 查看
CCTexure2D中在指定的位置中绘制图元的如下示例代码:

cocos2D-x中CCNode的画图函数
void CCTexture2D::drawAtPoint(const CCPoint& point)
  {
  GLfloat coordinates[] = {
  0.0f, m_fMaxT,
  m_fMaxS,m_fMaxT,
  0.0f, 0.0f,
  m_fMaxS,0.0f };
GLfloat width = (GLfloat)m_uPixelsWide * m_fMaxS,
  height = (GLfloat)m_uPixelsHigh * m_fMaxT;
GLfloat vertices[] = {
  point.x, point.y,
  width + point.x, point.y,
  point.x, height + point.y,
  width + point.x, height + point.y };
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position | kCCVertexAttribFlag_TexCoords );
  m_pShaderProgram->use();
  m_pShaderProgram->setUniformsForBuiltins();
ccGLBindTexture2D( m_uName );

  glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
  glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, coordinates);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  }


OpenGL函数。

void glVertexAttribPointer( GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride,const GLvoid * pointer);

参数:

pointer

指定一个指针,指向数组中第一个顶点属性的第一个组件。初始值为0。

stride

指定连续顶点属性之间的偏移量。如果为0,那么顶点属性会被理解为:它们是紧密排列在一起的。初始值为0。

normalized

指定当被访问时,固定点数据值是否应该被归一化(GL_TRUE)或者直接转换为固定点值(GL_FALSE)。

type

指定数组中每个组件的数据类型。可用的符号常量有GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT,GL_UNSIGNED_SHORT, GL_FIXED, 和 GL_FLOAT,初始值为GL_FLOAT。

size

指定每个顶点属性的组件数量。必须为1、2、3或者4。初始值为4。(梦维:如position是由3个(x,y,z)组成,而颜色是4个(r,g,b,a))

index

指定要修改的顶点属性的索引值
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐