Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [...]
- GLuint vertexBufferObject /* , colorBufferObject */;
- std::vector<glm::vec3> vertices;
- std::vector<glm::vec2> uvs;
- std::vector<glm::vec3> normals;
- model::loadOBJ("models/cube.obj", vertices, uvs, normals);
- std::cout << "Vertices: " << std::endl;
- for(unsigned int i = 0; i < vertices.size(); i++) {
- std::cout << vertices[i].x << ", " << vertices[i].y << ", " << vertices[i].z << std::endl;
- }
- glGenBuffers(1, &vertexBufferObject);
- glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
- glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- std::cout << "Generated buffer" << std::endl;
- /* glGenBuffers(1, &colorBufferObject);
- glBindBuffer(GL_ARRAY_BUFFER, colorBufferObject);
- glBufferData(GL_ARRAY_BUFFER, sizeof(pyramidColorBufferData), pyramidColorBufferData, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, 0); */
- GLuint progID;
- shaders::genShaders("shaders/test.vs", "shaders/test.fs", &progID);
- ShaderInfo *sInfo = shaders::getShaderInfo(progID);
- printf(sInfo->getVertexShaderPath().c_str());
- printf("\t");
- printf(sInfo->getFragmentShaderPath().c_str());
- printf("\n");
- glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
- glm::mat4 View = glm::lookAt(
- glm::vec3(12.0f, 9.0f, 9.0f), // Camera is at (4,3,3), in World Space
- glm::vec3(0.0f, 0.0f, 0.0f), // and looks at the origin
- glm::vec3(0.0f, 1.0f, 0.0f) // Head is up (set to 0,-1,0 to look upside-down)
- );
- glm::mat4 Model = glm::mat4(1.0f);
- float scaleFactor = 1.0f;
- View = glm::scale(View, glm::vec3(scaleFactor, scaleFactor, scaleFactor));
- glm::mat4 MVP = Projection * View * Model;
- GLuint MatrixID = glGetUniformLocation(progID, "MVP");
- do {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- // Apply matrix
- Model = glm::rotate(Model, yTheta, glm::vec3(0.0f, 0.0f, 1.0f));
- MVP = Projection * View * Model;
- // Send our transformation to the currently bound shader,
- // in the "MVP" uniform
- // For each model you render, since the MVP will be different (at least the M part)
- glUseProgram(progID);
- glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
- glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
- std::cout << "Enabled VertexAttribArray 0" << std::endl;
- glEnableVertexAttribArray(0);
- std::cout << "Enabled VertexAttribArray 1" << std::endl;
- glEnableVertexAttribArray(1);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0);
- std::cout << "Did glVertexAttribPointer stuff" << std::endl;
- // glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (void*) 48); // 48 = 4(size of float) * 4(vec4) * 3(amount vec4's in position data)
- // glBindBuffer(GL_ARRAY_BUFFER, colorBufferObject);
- // glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0);
- glDrawArrays(GL_TRIANGLES, 0, vertices.size());
- std::cout << "Drew stuff" << std::endl;
- glDisableVertexAttribArray(0);
- std::cout << "Disabled VertexAttribArray 0" << std::endl;
- glDisableVertexAttribArray(1);
- std::cout << "Disabled VertexAttribArray 1" << std::endl;
- // gl(offsetX += 0.0005f, y += 0.0005f);
- glfwSwapBuffers();
- std::cout << "Swapped buffers" << std::endl;
- yTheta = timing::getDeltaTime() * 90.0f;
- /** std::cout << "yTheta = " << yTheta << std::endl; */
- if(yTheta > 360)
- yTheta = 0;
- /** std::cout << timing::getDeltaTime() << "\t" << timing::getFPS() << std::endl; */
- // Update time
- timing::update();
- } while(glfwGetKey(GLFW_KEY_ESC) != GLFW_PRESS && glfwGetWindowParam(GLFW_OPENED));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment