2D_Game_Engine
Loading...
Searching...
No Matches
glfw.cpp
Go to the documentation of this file.
1#include <pch.hpp>
2#include <glfw.hpp>
3#include <window.hpp>
4
5int InitGlfwWindow(const char *window_name){
6 glfwInit();
7 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,4);
8 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,6);
9 glfwWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE);
10 #ifdef __APPLE__
11 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT,GL_TRUE);
12 #endif
13 glfwWindowHint(GLFW_RESIZABLE,false);
14
15 Window::Window=glfwCreateWindow(Window::Width,Window::Height,window_name,nullptr,nullptr);
16 if(Window::Window==NULL){
17 perror("Failed to create GLFW WINDOW\n");
18 glfwTerminate();
19 return -1;
20 }
21
22 glfwMakeContextCurrent(Window::Window);
23 glfwSwapInterval(1); //v-sync
24
25 if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)){
26 perror("Failed to initialize GLAD\n");
27 return -1;
28 }
29
30 glfwSetFramebufferSizeCallback(Window::Window,FramebufferSizeCallback);
31
32 printf("%s\n%s\n",(char *)glGetString(GL_VERSION),(char *)glGetString(GL_RENDERER));
33
34 glViewport(0,0,Window::Width,Window::Height);
35
36 return 0;
37}
38
39void GLAPIENTRY MessageCallback(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar* message,const void* userParam){
40 if(type==GL_DEBUG_TYPE_ERROR)
41 fprintf(stderr,"[[GL ERROR]] Type: 0x%x Severity: 0x%x Message: %s\n",type,severity,message);
42}
43
44void GLAPIENTRY FramebufferSizeCallback(GLFWwindow *WINDOW,int width,int height){
45 glViewport(0,0,width,height);
46}
void GLAPIENTRY FramebufferSizeCallback(GLFWwindow *WINDOW, int width, int height)
Definition glfw.cpp:44
void GLAPIENTRY MessageCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)
Definition glfw.cpp:39
int InitGlfwWindow(const char *window_name)
Definition glfw.cpp:5
GLFWwindow * Window
Definition window.cpp:225
float Height
Definition window.hpp:43
float Width
Definition window.cpp:227