Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Rasterizer::LoadScene(string file_name) {
- vector<GLfloat> vertex_data = {};
- vector<Surface *> surfaces;
- vector<Material *> materials;
- LoadOBJ(file_name.c_str(), surfaces, materials, false, {0, 0, 0});
- for (int i = 0; i < surfaces.size(); i++) {
- Surface * surface = surfaces.at(i);
- int no_triangles = surface->no_triangles();
- Triangle * triangles = surface->get_triangles();
- for (int j = 0; j < no_triangles; j++) {
- Triangle triangle = triangles[j];
- for (int k = 0; k < 3; k++) {
- Vertex vertex = triangle.vertex(k);
- // Push position data
- vertex_data.push_back(vertex.position.x);
- vertex_data.push_back(vertex.position.y);
- vertex_data.push_back(vertex.position.z);
- // Push texture coords
- //vertex_data.push_back(vertex.texture_coords->u);
- //vertex_data.push_back(vertex.texture_coords->v);
- }
- }
- }
- GLfloat vertices[vertex_data.size()];
- for (int i = 0; i < vertex_data.size(); i++)
- vertices[i] = vertex_data.at(i);
- printf("Loaded %d verticies & uv`s\n", vertex_data.size() / 3);
- no_of_verticies = vertex_data.size() / 3;
- const int vertex_stride = 0;
- // optional index array
- unsigned int indices[] = {};
- glGenVertexArrays( 1, &vao );
- glBindVertexArray( vao );
- glGenBuffers( 1, &vbo ); // generate vertex buffer object (one of OpenGL objects) and get the unique ID corresponding to that buffer
- glBindBuffer( GL_ARRAY_BUFFER, vbo ); // bind the newly created buffer to the GL_ARRAY_BUFFER target
- glBufferData( GL_ARRAY_BUFFER, sizeof( vertices ), vertices, GL_STATIC_DRAW ); // copies the previously defined vertex data into the buffer's memory
- // vertex position
- glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0 );
- glEnableVertexAttribArray( 0 );
- // vertex texture coordinates
- //glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 0, ( void* )( sizeof( float ) * 3 ) );
- //glEnableVertexAttribArray( 1 );
- //glGenBuffers( 1, &ebo );
- //glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, ebo );
- //glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof( indices ), indices, GL_STATIC_DRAW );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement