Advertisement
Guest User

engine.hpp

a guest
Mar 19th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. #ifndef ENGINE_HPP
  2. #define ENGINE_HPP
  3.  
  4. #include <glm/glm.hpp>
  5. #include <GL/glew.h>
  6. #include <GLFW/glfw3.h>
  7. #include <GL/gl.h>
  8. #include <GL/glext.h>
  9. #include <thread>
  10.  
  11. #define GLEW_STATIC
  12. #include <GL/glew.h>
  13.  
  14. #include <engine_shaders.hpp>
  15.  
  16. GLFWwindow* InitializeContext(){
  17.     CheckForGLErrors(__func__, __LINE__);
  18.     //Because or else everything else breaks
  19.     glfwInit();
  20.     CheckForGLErrors(__func__, __LINE__);
  21.  
  22.     //Settings for window
  23.     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  24.     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
  25.     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  26.     CheckForGLErrors(__func__, __LINE__);
  27.  
  28.     //Because I don't want to write code to resize
  29.     glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
  30.     CheckForGLErrors(__func__, __LINE__);
  31.  
  32.     //The actual creation of the window
  33.     GLFWwindow* window = glfwCreateWindow(800, 600, "CUBE", nullptr, nullptr); // Windowed
  34.     CheckForGLErrors(__func__, __LINE__);
  35.  
  36.     //Tell glfw to use the window
  37.     glfwMakeContextCurrent(window);
  38.     CheckForGLErrors(__func__, __LINE__);
  39.  
  40.  
  41.     //Use GLEW
  42.     glewExperimental = GL_TRUE;
  43.     GLenum err=glewInit();
  44.     if(err!=GLEW_OK)
  45.     {
  46.         //Problem: glewInit failed, something is seriously wrong.
  47.         std::cout<<"glewInit failed, aborting."<<std::endl;
  48.         exit(-1);
  49.     }
  50.     CheckForGLErrors(__func__, __LINE__);
  51.  
  52.     return window;
  53. }
  54.  
  55. GLuint InitializeElementBuffer(GLuint elements[], size_t size){
  56.     std::cout << "Elements size: " << size << std::endl;
  57.     GLuint ebo;
  58.     glGenBuffers(1, &ebo);
  59.  
  60.     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
  61.     glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, elements, GL_STATIC_DRAW);
  62.  
  63.     return ebo;
  64. }
  65.  
  66. GLuint InitializeVertexBuffer(GLfloat vertices[], size_t size){
  67.     std::cout << "Vertices size: " << size << std::endl;
  68.     GLuint vbo;
  69.     glGenBuffers(1, &vbo);
  70.  
  71.     glBindBuffer(GL_ARRAY_BUFFER, vbo);
  72.     glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_DYNAMIC_DRAW);
  73.  
  74.     return vbo;
  75. }
  76.  
  77. GLuint CreateVertexArray(){
  78.     GLuint vao;
  79.     glGenVertexArrays(1, &vao);
  80.     glBindVertexArray(vao);
  81.  
  82.     return vao;
  83. }
  84.  
  85. void InitializeVertexArray(GLuint ShaderProgram){
  86.     GLint PosAttrib = glGetAttribLocation(ShaderProgram, "position");
  87.     glVertexAttribPointer(PosAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
  88.     glEnableVertexAttribArray(PosAttrib);
  89. }
  90.  
  91.  
  92. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement