0
    GLfloat vertices4[]={-0.9,0.6, -0.9,0.2, -0.6,0.2, -0.6,0.6,
                         -0.4,0.6, -0.4,0.2,  0.1,0.2,  0.1,0.6,
                          0.3,0.6,  0.3,0.2,  0.6,0.2,  0.6,0.6  };

     GLushort indices[]={0,1,2,3, 120, 4,5,6,7, 120, 8,9,10,11};
     GLenum *value=GL_STREAM_DRAW;  
     GLfloat temp_err;

     glEnable(GL_PRIMITIVE_RESTART);
     nResult =GL_ERROR_CHECK((GL_NO_ERROR,"glEnable(GL_PRIMITIVE_RESTART)"));

     glPrimitiveRestartIndex(120);
     nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glPrimitiveRestartIndex(120);"));

     glGenBuffers(1,&bufferid1);
     nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glGenBuffers(1,&bufferid1)"));

     glGenBuffers(1,bufferid);

     glBindBuffer(GL_TEXTURE_BUFFER,bufferid);      
     glBufferData(GL_TEXTURE_BUFFER,sizeof(vertices4),vertices4,*value);

     temp_err=(GLfloat*)glMapBufferRange(GL_TEXTURE_BUFFER,0,8*sizeof(GLfloat),GL_MAP_READ_BIT);


     glBindBuffer(GL_ARRAY_BUFFER,bufferid1);
     nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glBindBuffer(GL_ARRAY_BUFFER,bufferid1);")); 

     glBufferData(GL_ARRAY_BUFFER,8*sizeof(GLfloat),temp_err,*value);


     *attr_vertex = glGetAttribLocation(shader_data.psId, "a_position"); 
     nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glGetAttribLocation(shader_data.psId, \"a_position\");"));

     glVertexAttribPointer(*attr_vertex, 2 , GL_FLOAT, GL_FALSE ,0, 0);
     nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glVertexAttribPointer(attr_vertex, 2 , GL_FLOAT, GL_FALSE ,0, 0);"));

     glEnableVertexAttribArray(*attr_vertex);
     nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glEnableVertexAttribArray(attr_vertex);"));

     glUniform1f(glGetUniformLocation(shader_data.psId,"offset_x"),x);                      
     glUniform1f(glGetUniformLocation(shader_data.psId,"offset_y"),y);                      
     glDrawElements(GL_TRIANGLE_FAN, 14,GL_UNSIGNED_SHORT,indices);

我期望它会渲染 1 个四边形,因为我正在为“bufferid1”中的第一个四边形传递顶点数据,但它会渲染 vertices4 中的所有 3 个四边形。请指出我在这里出错的地方。

4

1 回答 1

2

在这里,我期望它会渲染 1 个四边形

你怎么能期待呢?您的渲染调用明确表示要渲染 14 个顶点:

glDrawElements(GL_TRIANGLE_FAN, 14,GL_UNSIGNED_SHORT,indices);

OpenGL 没有理由神奇地知道您这次只指四个。

于 2013-01-21T18:24:58.157 回答