Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef ENGINE_HPP
- #define ENGINE_HPP
- #include <glm/glm.hpp>
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- #include <GL/gl.h>
- #include <GL/glext.h>
- #include <thread>
- #define GLEW_STATIC
- #include <GL/glew.h>
- #include <engine_shaders.hpp>
- GLFWwindow* InitializeContext(){
- CheckForGLErrors(__func__, __LINE__);
- //Because or else everything else breaks
- glfwInit();
- CheckForGLErrors(__func__, __LINE__);
- //Settings for window
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- CheckForGLErrors(__func__, __LINE__);
- //Because I don't want to write code to resize
- glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
- CheckForGLErrors(__func__, __LINE__);
- //The actual creation of the window
- GLFWwindow* window = glfwCreateWindow(800, 600, "CUBE", nullptr, nullptr); // Windowed
- CheckForGLErrors(__func__, __LINE__);
- //Tell glfw to use the window
- glfwMakeContextCurrent(window);
- CheckForGLErrors(__func__, __LINE__);
- //Use GLEW
- glewExperimental = GL_TRUE;
- GLenum err=glewInit();
- if(err!=GLEW_OK)
- {
- //Problem: glewInit failed, something is seriously wrong.
- std::cout<<"glewInit failed, aborting."<<std::endl;
- exit(-1);
- }
- CheckForGLErrors(__func__, __LINE__);
- return window;
- }
- GLuint InitializeElementBuffer(GLuint elements[], size_t size){
- std::cout << "Elements size: " << size << std::endl;
- GLuint ebo;
- glGenBuffers(1, &ebo);
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, elements, GL_STATIC_DRAW);
- return ebo;
- }
- GLuint InitializeVertexBuffer(GLfloat vertices[], size_t size){
- std::cout << "Vertices size: " << size << std::endl;
- GLuint vbo;
- glGenBuffers(1, &vbo);
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_DYNAMIC_DRAW);
- return vbo;
- }
- GLuint CreateVertexArray(){
- GLuint vao;
- glGenVertexArrays(1, &vao);
- glBindVertexArray(vao);
- return vao;
- }
- void InitializeVertexArray(GLuint ShaderProgram){
- GLint PosAttrib = glGetAttribLocation(ShaderProgram, "position");
- glVertexAttribPointer(PosAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
- glEnableVertexAttribArray(PosAttrib);
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement