typedef cml::matrix44f_c Matrix;
struct SourceData {
GLenum type;
unsigned int size;
unsigned int stride;
void* data;
};
struct IndexData {
unsigned short* data;
int count;
};
struct MyGeometry {
std::string id;
SourceData vertices;
SourceData normals;
SourceData texcoords;
IndexData vert_indices;
IndexData norm_indices;
IndexData tex_indices;
GLenum primitive;
Matrix model_matrix;
};
[B]
HERE IS MY SETUP CODE:[/B]
[CODE]void LoadColladaFile(void)
{
std::string file_name;
std::cout << "Enter .dae file name: ";
std::cin >> file_name;
std::cout << "\n\nREADING FILE...\n";
ColladaInterface::readFile(&geometries, file_name.data());
std::cout << "\nREAD FILE!!!\n";
geometry_count = geometries.size();
/* Uniforms are used to pass data into the shaders */
/* First we need to get the uniform locations here */
std::cout << "\nGetting uniform locations\n";
ModelMatrixUniformLocation = glGetUniformLocation(program_ids[0], "ModelMatrix");
ViewMatrixUniformLocation = glGetUniformLocation(program_ids[0], "ViewMatrix");
ProjectionMatrixUniformLocation = glGetUniformLocation(program_ids[0], "ProjectionMatrix");
ExitOnGLError("ERROR: Could not get shader uniform locations");
/* Generate vertex array objects */
std::cout << "Generating vaos : " << geometry_count << std::endl;
vaos = new GLuint[geometry_count];
glGenVertexArrays(geometry_count, vaos);
ExitOnGLError("ERROR: Could not generate the VAO");
/* Allocate vbos */
vbos = new GLuint[geometry_count];
/* Generate buffer to hold vertex data */
glGenBuffers(geometry_count, vbos);
ExitOnGLError("ERROR: Could not generate the buffer objects");
/* Allocate ibos */
ibos = new GLuint[geometry_count];
/* Generate buffer to hold index data */
glGenBuffers(geometry_count, ibos);
ExitOnGLError("ERROR: Could not generate the buffer objects");
/* Loop through the geometries */
std::cout << "\nLinking OpenGL to geometries\n";
int i = 0;
for(it=geometries.begin() ; it != geometries.end(); it++)
{
MyGeometry * current_geometry = &(*it).second;
std::cout << "Linking " << current_geometry->id << std::endl;
/* Bind new vao for this geometry */
glBindVertexArray(vaos[i]);
std::cout << "Using vao: " << i;
ExitOnGLError("ERROR: Could not bind the VAO");
/* Bind vertex buffer object and give it data from geometry*/
vertices = (float*) current_geometry->vertices.data;
std::cout << "number of elements: " << current_geometry->vertices.size << std::endl;
std::cout << "type of elements: " << current_geometry->vertices.type << std::endl;
std::cout << "stride of vertices: " << current_geometry->vertices.stride << std::endl;
std::cout << "vertices: " << std::endl;
for(int j = 0; j < (current_geometry->vertices.size); j++)
{
std::cout << vertices[j] << std::endl;
}
glBindBuffer(GL_ARRAY_BUFFER, vbos[i]);
std::cout << "Using vdo: " << i;
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
ExitOnGLError("ERROR: Could not bind the VBO to the VAO");
/* Bind index buffer and give it the index data */
std::cout << "number of position indices: " << current_geometry->vert_indices.count << std::endl;
indices = current_geometry->vert_indices.data;
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibos[i]);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
ExitOnGLError("ERROR: Could not bind the IBO to the VAO");
/* Enable vertex attributes */
glEnableVertexAttribArray(0);
ExitOnGLError("ERROR: Could not enable vertex attributes");
/* Set up vertex attribute pointers so that the shaders know what their input is */
glVertexAttribPointer(
0,
current_geometry->vertices.stride,
current_geometry->vertices.type,
GL_FALSE,
0,
0);
ExitOnGLError("ERROR: Could not set VAO attributes");
std::cout << "Press enter to link next geometry...";
getchar();
i++;
}
std::cout << "\nDone linking geometries.\n";
}