mad1231999

Untitled

Jan 20th, 2013
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.32 KB | None | 0 0
  1. std::vector<glm::vec3> vertices;
  2.     std::vector<glm::vec2> uvs;
  3.     std::vector<glm::vec3> normals;
  4.  
  5.     model::loadOBJ("models/cube.obj", vertices, uvs, normals);
  6.  
  7.     glGenBuffers(1, &vertexBufferObject);
  8.     glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
  9.     glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW);
  10.     glBindBuffer(GL_ARRAY_BUFFER, 0);
  11.  
  12.     /* glGenBuffers(1, &colorBufferObject);
  13.     glBindBuffer(GL_ARRAY_BUFFER, colorBufferObject);
  14.     glBufferData(GL_ARRAY_BUFFER, sizeof(pyramidColorBufferData), pyramidColorBufferData, GL_STATIC_DRAW);
  15.     glBindBuffer(GL_ARRAY_BUFFER, 0); */
  16.  
  17.     GLuint progID;
  18.     shaders::genShaders("shaders/test.vs", "shaders/test.fs", &progID);
  19.  
  20.     ShaderInfo *sInfo = shaders::getShaderInfo(progID);
  21.  
  22.     printf(sInfo->getVertexShaderPath().c_str());
  23.     printf("\t");
  24.     printf(sInfo->getFragmentShaderPath().c_str());
  25.     printf("\n");
  26.  
  27.     // Compute matrix
  28.     // Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
  29.     glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
  30.     // Camera matrix
  31.     glm::mat4 View       = glm::lookAt(
  32.         glm::vec3(4.0f, 4.0f, 4.0f), // Camera is at (4,3,3), in World Space
  33.         glm::vec3(0.0f, 0.0f, 0.0f), // and looks at the origin
  34.         glm::vec3(0.0f, 1.0f, 0.0f)  // Head is up (set to 0,-1,0 to look upside-down)
  35.     );
  36.     // Model matrix : an identity matrix (model will be at the origin)
  37.     glm::mat4 Model      = glm::mat4(1.0f);  // Changes for each model !
  38.  
  39.     float scaleFactor = 0.4f;
  40.     View = glm::scale(View, glm::vec3(scaleFactor, scaleFactor, scaleFactor));
  41.  
  42.     // Our ModelViewProjection : multiplication of our 3 matrices
  43.     glm::mat4 MVP        = Projection * View * Model; // Remember, matrix multiplication is the other way around
  44.  
  45.     // Get a handle for our "MVP" uniform.
  46.     // Only at initialisation time.
  47.     GLuint MatrixID = glGetUniformLocation(progID, "MVP");
  48.  
  49.     do {
  50.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  51.  
  52.         // Apply matrix
  53.  
  54.         Model = glm::rotate(Model, yTheta, glm::vec3(0.0f, 0.0f, 1.0f));
  55.  
  56.         MVP = Projection * View * Model;
  57.  
  58.         // Send our transformation to the currently bound shader,
  59.         // in the "MVP" uniform
  60.         // For each model you render, since the MVP will be different (at least the M part)
  61.         MVP = MVP;
  62.         glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
  63.  
  64.         glUseProgram(progID);
  65.  
  66.         glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject);
  67.  
  68.         // std::cout << "Enabled VertexAttribArray 0" << std::endl;
  69.         glEnableVertexAttribArray(0);
  70.         // std::cout << "Enabled VertexAttribArray 1" << std::endl;
  71.         glEnableVertexAttribArray(1);
  72.         // glEnableVertexAttribArray(1);
  73.  
  74.         glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0);
  75.         // glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (void*) 48); // 48 = 4(size of float) * 4(vec4) * 3(amount vec4's in position data)
  76.         // glBindBuffer(GL_ARRAY_BUFFER, colorBufferObject);
  77.         // glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0);
  78.  
  79.         glDrawArrays(GL_TRIANGLES, 0, vertices.size());
  80.  
  81.         glDisableVertexAttribArray(0);
  82.         glDisableVertexAttribArray(1);
Advertisement
Add Comment
Please, Sign In to add comment