mad1231999

Untitled

Jan 30th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.95 KB | None | 0 0
  1. [...]
  2.  
  3. GLuint vertexBufferObject /* , colorBufferObject */;
  4.  
  5.     std::vector<glm::vec3> vertices;
  6.     std::vector<glm::vec2> uvs;
  7.     std::vector<glm::vec3> normals;
  8.  
  9.     model::loadOBJ("models/cube.obj", vertices, uvs, normals);
  10.  
  11.     std::cout << "Vertices: " << std::endl;
  12.     for(unsigned int i = 0; i < vertices.size(); i++) {
  13.         std::cout << vertices[i].x << ", " << vertices[i].y << ", " << vertices[i].z << std::endl;
  14.     }
  15.  
  16.     glGenBuffers(1, &vertexBufferObject);
  17.     glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
  18.     glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW);
  19.     glBindBuffer(GL_ARRAY_BUFFER, 0);
  20.  
  21.     std::cout << "Generated buffer" << std::endl;
  22.  
  23.     /* glGenBuffers(1, &colorBufferObject);
  24.     glBindBuffer(GL_ARRAY_BUFFER, colorBufferObject);
  25.     glBufferData(GL_ARRAY_BUFFER, sizeof(pyramidColorBufferData), pyramidColorBufferData, GL_STATIC_DRAW);
  26.     glBindBuffer(GL_ARRAY_BUFFER, 0); */
  27.  
  28.     GLuint progID;
  29.     shaders::genShaders("shaders/test.vs", "shaders/test.fs", &progID);
  30.  
  31.     ShaderInfo *sInfo = shaders::getShaderInfo(progID);
  32.  
  33.     printf(sInfo->getVertexShaderPath().c_str());
  34.     printf("\t");
  35.     printf(sInfo->getFragmentShaderPath().c_str());
  36.     printf("\n");
  37.  
  38.     glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
  39.  
  40.     glm::mat4 View       = glm::lookAt(
  41.         glm::vec3(12.0f, 9.0f, 9.0f), // Camera is at (4,3,3), in World Space
  42.         glm::vec3(0.0f, 0.0f, 0.0f), // and looks at the origin
  43.         glm::vec3(0.0f, 1.0f, 0.0f)  // Head is up (set to 0,-1,0 to look upside-down)
  44.     );
  45.  
  46.     glm::mat4 Model      = glm::mat4(1.0f);
  47.  
  48.     float scaleFactor = 1.0f;
  49.     View = glm::scale(View, glm::vec3(scaleFactor, scaleFactor, scaleFactor));
  50.  
  51.     glm::mat4 MVP        = Projection * View * Model;
  52.  
  53.     GLuint MatrixID = glGetUniformLocation(progID, "MVP");
  54.  
  55.     do {
  56.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  57.  
  58.         // Apply matrix
  59.  
  60.         Model = glm::rotate(Model, yTheta, glm::vec3(0.0f, 0.0f, 1.0f));
  61.  
  62.         MVP = Projection * View * Model;
  63.  
  64.         // Send our transformation to the currently bound shader,
  65.         // in the "MVP" uniform
  66.         // For each model you render, since the MVP will be different (at least the M part)
  67.  
  68.         glUseProgram(progID);
  69.         glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
  70.  
  71.         glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
  72.  
  73.         std::cout << "Enabled VertexAttribArray 0" << std::endl;
  74.         glEnableVertexAttribArray(0);
  75.         std::cout << "Enabled VertexAttribArray 1" << std::endl;
  76.         glEnableVertexAttribArray(1);
  77.  
  78.         glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0);
  79.         std::cout << "Did glVertexAttribPointer stuff" << std::endl;
  80.         // glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (void*) 48); // 48 = 4(size of float) * 4(vec4) * 3(amount vec4's in position data)
  81.         // glBindBuffer(GL_ARRAY_BUFFER, colorBufferObject);
  82.         // glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0);
  83.  
  84.         glDrawArrays(GL_TRIANGLES, 0, vertices.size());
  85.         std::cout << "Drew stuff" << std::endl;
  86.  
  87.         glDisableVertexAttribArray(0);
  88.         std::cout << "Disabled VertexAttribArray 0" << std::endl;
  89.         glDisableVertexAttribArray(1);
  90.         std::cout << "Disabled VertexAttribArray 1" << std::endl;
  91.  
  92.         // gl(offsetX += 0.0005f, y += 0.0005f);
  93.  
  94.         glfwSwapBuffers();
  95.         std::cout << "Swapped buffers" << std::endl;
  96.  
  97.         yTheta = timing::getDeltaTime() * 90.0f;
  98.  
  99.         /** std::cout << "yTheta = " << yTheta << std::endl; */
  100.  
  101.         if(yTheta > 360)
  102.             yTheta = 0;
  103.  
  104.         /** std::cout << timing::getDeltaTime() << "\t" << timing::getFPS() << std::endl; */
  105.  
  106.         // Update time
  107.         timing::update();
  108.     } while(glfwGetKey(GLFW_KEY_ESC) != GLFW_PRESS && glfwGetWindowParam(GLFW_OPENED));
  109.  
  110.     return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment