I'm having a bit of trouble grasping the concept of drawing things with buffer objects, and a lot of trouble getting anything to be displayed on screen with one. Up until now I have been using gl_begin/gl_end for drawing.
So I basically have everything set up more or less how I want it, only I need to know what function calls to make and in what order. Here's what I've tried:
//Initialization
trimesh_rendering* t = get_world_trias(); glGenBuffers(1, &vboId); glBindBuffer(GL_ARRAY_BUFFER, vboId); glBufferData(GL_ARRAY_BUFFER, sizeof(t->vertices)+sizeof(t->normals)+sizeof(t->colors), 0, GL_STREAM_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(t->vertices), t->vertices); // copy vertices starting from 0 offest glBufferSubData(GL_ARRAY_BUFFER, sizeof(t->vertices), sizeof(t->normals), t->normals); // copy normals after vertices glBufferSubData(GL_ARRAY_BUFFER, sizeof(t->vertices)+sizeof(t->normals), sizeof(t->colors), t->colors); // copy colours after normals glBindBuffer(GL_ARRAY_BUFFER, 0); delete_world_trias(t);
//get_world_trias()
trimesh_rendering* TriMeshRenderer::get_world_trias() {
trimesh_rendering* t = new trimesh_rendering;
int num = 0;
node *q;
int col, row;
//Count num trias
for( int r=0; r<world->get_rows()+world->get_cols()-1; r++ ) {
for( int c=maximum(0, r-world->get_rows()+1); c<=r && c<world->get_cols(); c++ ) {
col = c;
row = r-c;
for( q = world->get(col,row,0); q != 0; q = q->next ) {
TriMesh *mesh = q->shape;
if(mesh!=0) {
num += mesh->get_numTrias()*9;
}
}
}
}
triasize = num/9;
worldsize = num*3;
t->len = num;
t->vertices = new GLfloat[t->len];
t->normals = new GLfloat[t->len];
t->colors = new GLfloat[t->len];
int m = 0;
for( int r=0; r<world->get_rows()+world->get_cols()-1; r++ ) {
for( int c=maximum(0, r-world->get_rows()+1); c<=r && c<world->get_cols(); c++ ) {
col = c;
row = r-c;
for( q = world->get(col,row,0); q != 0; q = q->next ) {
TriMesh *mesh = q->shape;
if(mesh!=0) {
int n = mesh->get_numTrias();
for( int i=0; i<n; i++ ) {
Triangle3D tria = mesh->get_tria(i);
t->vertices[m+0] = tria.p1.x;
t->vertices[m+1] = tria.p1.y-tria.p1.z;
t->vertices[m+2] = 0;
t->vertices[m+3] = tria.p2.x;
t->vertices[m+4] = tria.p2.y-tria.p2.z;
t->vertices[m+5] = 0;
t->vertices[m+6] = tria.p3.x;
t->vertices[m+7] = tria.p3.y-tria.p3.z;
t->vertices[m+8] = 0;
t->normals[m+0] = tria.normal.x;
t->normals[m+1] = tria.normal.y;
t->normals[m+2] = tria.normal.z;
t->normals[m+3] = tria.normal.x;
t->normals[m+4] = tria.normal.y;
t->normals[m+5] = tria.normal.z;
t->normals[m+6] = tria.normal.x;
t->normals[m+7] = tria.normal.y;
t->normals[m+8] = tria.normal.z;
t->colors[m+0] = 1.0;
t->colors[m+1] = 1.0;
t->colors[m+2] = 1.0;
t->colors[m+3] = 1.0;
t->colors[m+4] = 1.0;
t->colors[m+5] = 1.0;
t->colors[m+6] = 1.0;
t->colors[m+7] = 1.0;
t->colors[m+8] = 1.0;
m+=9;
}
}
}
}
}
return t;
}
//Update and draw
glBindBuffer(GL_ARRAY_BUFFER, vboId); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, 0); trimesh_rendering* t = get_world_trias(); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(t->vertices), t->vertices); // copy vertices starting from 0 offest glBufferSubData(GL_ARRAY_BUFFER, sizeof(t->vertices), sizeof(t->normals), t->normals); // copy normals after vertices glBufferSubData(GL_ARRAY_BUFFER, sizeof(t->vertices)+sizeof(t->normals), sizeof(t->colors), t->colors); // copy colours after normals delete_world_trias(t); glDrawArrays(GL_TRIANGLES, 0, triasize); glDisableClientState(GL_VERTEX_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0); glUseProgram(0);
My goal is to use a vertex shader to transform primitives from a square to an isometric view.






