void CreateVBO(void)
{
Vertex_t House_Tri[36]; /* vertices for cube triangles (3*triangles = 3*6*2) */
Vertex_t Roof_Tri[12]; /* vertices for roof triangles (3*triangles = 3*2*2) */
Vertex_t Plane_Tri[6]; /* 2 triangles */
int i,j, ind;
GLuint loc_tex;
Image *Teximage;
float v1[2], v2[2], v3[2], w1[2], w2[2], n1[2], n2[2], n3[2];
/* House (Cube) triangles */
ind = 0;
for (i=0; i<12; i++) { /* 12: number of triangles on a cube surface*/
for (j=0; j<3; j++) { /* three vertices in each triangle */
House_Tri[ind] = Cube_Ver[Cube_Ind[i*3+j]];
ind = ind + 1;
}
}
/* Roof triangles */
ind = 0;
for (i=0; i<4; i++) {
for (j=0; j<3; j++) {
Roof_Tri[ind] = Roof_Ver[Roof_Ind[i*3+j]];
ind = ind + 1;
}
}
/* triangles for the plane (colors and normals given in the data initialization) */
ind = 0;
for (i=0; i<2; i++) {
for (j=0; j<3; j++) {
Plane_Tri[ind] = Plane_Ver[Plane_Ind[i*3+j]];
ind = ind + 1;
}
}
/* texture coordinates for the plane (x,y,z) <-> (s,t) (always consists of two triangles) */
/* s t */
tex_coord[0][0] = 0.0; tex_coord[0][1] = 0.0; /* (s,t) (0,1) *********** (1,1) */
tex_coord[1][0] = 1.0; tex_coord[1][1] = 0.0; /* * * * */
tex_coord[2][0] = 1.0; tex_coord[2][1] = 1.0; /* * * * */
tex_coord[3][0] = 0.0; tex_coord[3][1] = 0.0; /* * * * */
tex_coord[4][0] = 1.0; tex_coord[4][1] = 1.0; /* * * * */
tex_coord[5][0] = 0.0; tex_coord[5][1] = 1.0; /* (0,0) *********** (1,0) */
for (ind=0;ind<6;ind++) {
Plane_Tri[ind].St[0] = tex_coord[ind][0]; Plane_Tri[ind].St[1] = tex_coord[ind][1];
}
glGenTextures(3, textures);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, checker1);
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textures[1]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, checker2);
glGenerateMipmap(GL_TEXTURE_2D);
Teximage = (Image *) malloc(sizeof(Image));
ImageLoad("crate.bmp", Teximage);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, textures[2]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Teximage->sizeX, Teximage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE,Teximage->data);
glGenerateMipmap(GL_TEXTURE_2D);
for (ind=0;ind<6;ind++) {
Roof_Tri[ind].St[0] = tex_coord[ind][0]; Roof_Tri[ind].St[1] = tex_coord[ind][1];
Roof_Tri[6+ind].St[0] = tex_coord[ind][0]; Roof_Tri[6+ind].St[1] = tex_coord[ind][1];
}
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glGenVertexArrays(4, &VAOIds[0]);
glBindVertexArray(VAOIds[0]);
glGenBuffers(3, &VBOIds[0]);
glBindBuffer(GL_ARRAY_BUFFER, VBOIds[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(House_Tri), House_Tri, GL_STATIC_DRAW);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4*14, 0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 4*14, (GLvoid*)16);
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 4*14, (GLvoid*)32);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glBindVertexArray(VAOIds[1]);
glGenBuffers(4, &VBOIds[0]);
glBindBuffer(GL_ARRAY_BUFFER, VBOIds[1]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Roof_Tri), Roof_Tri, GL_STATIC_DRAW);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4*14, 0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 4*14, (GLvoid*)16);
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 4*14, (GLvoid*)32);
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 4*14, (GLvoid*)48);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2); glEnableVertexAttribArray(3);
glBindVertexArray(VAOIds[2]);
glGenBuffers(4, &VBOIds[0]);
glBindBuffer(GL_ARRAY_BUFFER, VBOIds[2]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Plane_Tri), Plane_Tri, GL_STATIC_DRAW);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4*14, 0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 4*14, (GLvoid*)16);
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 4*14, (GLvoid*)32);
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 4*14, (GLvoid*)48);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2); glEnableVertexAttribArray(3);
glBindVertexArray(VAOIds[3]);
glGenBuffers(3, &VBOIds[0]);
glBindBuffer(GL_ARRAY_BUFFER, VBOIds[3]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Axes), Axes, GL_STATIC_DRAW);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4*14, 0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 4*14, (GLvoid*)16);
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 4*14, (GLvoid*)32);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glBindVertexArray(0);
}