27#include "gl_helper.hpp"
29#include "engine_logger.hpp"
35using namespace Brenta;
36using namespace Brenta::Utils;
42 if (!gladLoadGLLoader(loadproc))
44 ERROR(
"Failed to initialize GLAD");
51 glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
52 glEnable(GL_DEPTH_TEST);
53 INFO(
"Enabled GL_DEPTH_TEST");
59 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
60 INFO(
"Enabled GL_BLEND (transparency)");
67 glEnable(GL_CULL_FACE);
68 INFO(
"Enabled GL_CULL_FACE (draw only visible triangles)");
75 glEnable(GL_MULTISAMPLE);
76 INFO(
"Enabled GL_MULTISAMPLE");
79 GLenum errcode = GL::glCheckError();
81 INFO(
"OpenGl loaded");
88 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
89 INFO(
"Enabled GL_POLYGON_MODE (wireframe)");
93 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
94 INFO(
"Disabled GL_POLYGON_MODE (fill)");
100 glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT);
101 INFO(
"Set viewport: y = ", SCR_WIDTH,
"x = ", SCR_HEIGHT);
106 glClearColor(r, g, b, a);
111 glDrawArrays(mode, first, count);
116 glDrawElements(mode, count, type, indices);
122 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
127 glBindVertexArray(n);
133 while ((errorCode = glGetError()) != GL_NO_ERROR)
138 case GL_INVALID_ENUM:
139 error =
"INVALID_ENUM";
141 case GL_INVALID_VALUE:
142 error =
"INVALID_VALUE";
144 case GL_INVALID_OPERATION:
145 error =
"INVALID_OPERATION";
147 case GL_STACK_OVERFLOW:
148 error =
"STACK_OVERFLOW";
150 case GL_STACK_UNDERFLOW:
151 error =
"STACK_UNDERFLOW";
153 case GL_OUT_OF_MEMORY:
154 error =
"OUT_OF_MEMORY";
156 case GL_INVALID_FRAMEBUFFER_OPERATION:
157 error =
"INVALID_FRAMEBUFFER_OPERATION";
161 error +=
" | " + std::string(file) +
" (" + std::to_string(line) +
")";
static void LoadOpenGL(bool gl_blending=true, bool gl_cull_face=true, bool gl_multisample=true, bool gl_depth_test=true)
Load OpenGL.
static void DrawElements(GLenum mode, int count, GLenum type, const void *indices)
Draw Elements.
static GLenum glCheckError_(const char *file, int line)
Check OpenGL error.
static void DrawArrays(GLenum mode, int first, int count)
Draw Arrays.
static void SetColor(float r, float g, float b, float a)
Set Clear Color.
static void Clear()
Clear.
static void BindVertexArray(unsigned int n)
Enable Depth Test.
static void SetViewport(int x, int y, int SCR_WIDTH, int SCR_HEIGHT)
Set Viewport.
static void SetPoligonMode(GLboolean enable)
Set Poligon Mode.
static int GetHeight()
Get the height of the window.
static GLFWglproc GetProcAddress()
Get the OpenGL function pointer.
static int GetWidth()
Get the width of the window.