我正在尝试使用gldrawelements/arrays函数在OpenGL 4中渲染模型。我目前正在阅读带有顶点数据和多边形索引的文件。我无法在屏幕上显示任何内容,除了IM使用的轴供参考。我已经成功地使用了这种通用方法。我不知道我可能做错了什么,几乎被困了几天。
这是我缓冲我的数据的地方
// get position of "in vec4 vPosition;" from shader program
// displays axes properly
vPosition = glGetAttribLocation( program, "vPosition" );
// create buffers
glGenVertexArrays(2, vao);
glGenBuffers( 3, vbo );
// here I bind vao[0] and vbo[0] then buffer
// a set of XYZ axes which display correctly
// buffer model
glBindVertexArray( vao[1] );
glBindBuffer( GL_ARRAY_BUFFER, vbo[1] );
glBufferData( GL_ARRAY_BUFFER, sizeof(board->verts),
board->verts, GL_STATIC_DRAW );
glEnableVertexAttribArray( vPosition );
glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0,
BUFFER_OFFSET(0));
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER , vbo[2] );
glBufferData(
GL_ELEMENT_ARRAY_BUFFER,
sizeof(board->indices),
board->indices.data(),
GL_STATIC_DRAW);
fyi板是冲浪板的模型,其中读取了gldrawelements的顶点和索引。如果在呼叫Glbufferdata
的呼叫上方,这些顶点和索引正确打印出来。for( int i = 0; i < board->numVerts; i++ ){
std::cerr << i << ": "<<board->verts[i].x << " "<<board->verts[i].y<<" "<<
board->verts[i].z << " " << board->verts[i].w << std::endl;
}
如果放置了类似的打印循环,则索引也是如此。这是我尝试绘制模型的地方:
void draw_model(){
glUniform4fv( color_loc, 1, glm::value_ptr(blue));
glBindVertexArray( vao[1] );
glDrawArrays( GL_LINE_STRIP, 0, 600 );
//glDrawElements(
// GL_LINES,
// board->indices.size(),
// GL_UNSIGNED_INT,
// NULL
//);
}
绘制的调用(已注释)没有显示任何内容。对抽签的呼吁是一项故障排除的努力,以查看我是否只是错误地使用了绘图(我过去只使用了绘制片)。董事会定义为model3d *board
。这是它的班级
class model3d{
public:
glm::vec4 *verts;
std::vector<int> indices;
int numVerts;
int numPolys;
model3d( const char*, const char* );
private:
void load_coords( const char* );
void load_polys( const char* );
};
为什么我的数据似乎没有缓冲?
不使用sizeof(board->verts)
,因为它只会返回指针的大小。