Facebook
From Sploky, 2 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 96
  1. #include <glad/glad.h>
  2. #include <GLFW/glfw3.h>
  3. #include <iostream>
  4. #include "resources/shader.h"
  5. #include "resources/texture.h"
  6. #include "entities/camera.h"
  7. #define STB_IMAGE_IMPLEMENTATION
  8. #include <stb_image.h>
  9. #include <glm/glm.hpp>
  10. #include <glm/gtc/matrix_transform.hpp>
  11. #include <glm/gtc/type_ptr.hpp>
  12. #include <glm/gtx/quaternion.hpp>
  13. #include <utility>
  14. #include <vector>
  15. #include "screen.h"
  16. #include "entities/Alive/player.h"
  17. #include "resources/model.h"
  18.  
  19. using namespace glg;
  20.  
  21.  
  22.  
  23. Camera camera(glm::vec3(0, 0, 3), glm::vec3(0, 0, 0), 70, (float)SCREEN_WIDTH / (float)SCREEN_HEIGHT);
  24.  
  25. void loadOpenGlFunctions();
  26.  
  27. int main() {
  28.         // initialize and configure
  29.         glfwInit();
  30.         glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  31.         glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
  32.         glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  33.  
  34. #ifdef __APPLE__
  35.         glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  36. #endif // __APPLE__
  37.         // window creation
  38.         GLFWwindow* window = createWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Test");
  39.         lockCursor(window, true);
  40.         // load all OpenGl function pointers
  41.         loadOpenGlFunctions();
  42.  
  43.         Shader shader("Assets/VertexShader.vert", "Assets/FragmentShader.frag");
  44.         // creates a vertex array object
  45.  
  46.         shader.use();
  47.  
  48.  
  49.         Player player(camera.getPosition(), camera.getRotation(), camera);
  50.  
  51.  
  52.         glEnable(GL_DEPTH_TEST);
  53.         shader.use();
  54.         Model model("assets/backpack/backpack.obj");
  55.         Model model2(model);
  56.  
  57.         // render loop
  58.         while (!glfwWindowShouldClose(window))
  59.         {
  60.                 calculateDeltaTime();
  61.                 loopThroughEntitys();
  62.  
  63.                 glClearColor(.3f, 0, .2f, 1);
  64.                 glClear(GL_COLOR_BUFFER_BIT);
  65.                 glClearColor(0, 0, 0, 0);
  66.                 glClear(GL_DEPTH_BUFFER_BIT);
  67.                 //shader.use();
  68.                 //texture1.activate();
  69.                 //texture2.activate();
  70.                 glm::mat4 modeli = glm::mat4(1);
  71.                 shader.setMat4("model", modeli);
  72.                 //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  73.                 camera.aspectRatio = (float)SCREEN_WIDTH / (float)SCREEN_HEIGHT;
  74.                 glm::mat4 view = player.camera.getViewMatrix();
  75.                 shader.setMat4("view", view);
  76.                 shader.setMat4("projection", player.camera.getProjectionMatrix());
  77.                 model.draw(shader);
  78.  
  79.                 modeli = glm::translate(modeli, glm::vec3(0, 5, 0));
  80.                 shader.setMat4("model", modeli);
  81.                 model2.draw(shader);
  82.                 //view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
  83.  
  84.                
  85.                 glBindVertexArray(0);
  86.  
  87.                 glfwSwapBuffers(window);
  88.                 glfwPollEvents();
  89.         }
  90.  
  91.         glfwTerminate();
  92.         return 0;
  93. }
  94.  
  95. void loadOpenGlFunctions() {
  96.         if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
  97.                 throw std::runtime_error("No glad just sad");
  98.         }
  99. }
captcha