added basic glfw stuff
This commit is contained in:
94
TSE_GlfwOpenGlImpl/src/OpenGLRenderingBackend.cpp
Normal file
94
TSE_GlfwOpenGlImpl/src/OpenGLRenderingBackend.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
#include "OpenGLRenderingBackend.hpp"
|
||||
#include "GL/gl3w.h"
|
||||
#include "GLFW/glfw3.h"
|
||||
#include "GL/gl.h"
|
||||
#include "WindowGlfw.hpp"
|
||||
#include "Debug.hpp"
|
||||
|
||||
TSE::GLFW::OpenGLRenderingBackend::OpenGLRenderingBackend(Color _backgroundColor, bool _vsync)
|
||||
: OpenGLRenderingBackend(_backgroundColor, _vsync, 0, false){ }
|
||||
|
||||
TSE::GLFW::OpenGLRenderingBackend::OpenGLRenderingBackend(Color _backgroundColor, bool _vsync, int _samples, bool _useseImGui)
|
||||
{
|
||||
backgroundColor = _backgroundColor;
|
||||
vsync = _vsync;
|
||||
samples = _samples;
|
||||
useseImGui = _useseImGui;
|
||||
}
|
||||
|
||||
void TSE::GLFW::OpenGLRenderingBackend::InitPreWindow()
|
||||
{
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, TSE_OPENGL_VERSION_MAJOR);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, TSE_OPENGL_VERSION_MINOR);
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, 1);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_SAMPLES, samples);
|
||||
}
|
||||
|
||||
bool TSE::GLFW::OpenGLRenderingBackend::InitPostWindow()
|
||||
{
|
||||
WindowGlfw* wnd = static_cast<WindowGlfw*>(window);
|
||||
glfwMakeContextCurrent(wnd->window);
|
||||
if(gl3wInit())
|
||||
{
|
||||
Debug::Log("Failed to initialize gl3w.");
|
||||
return false;
|
||||
}
|
||||
if(!gl3wIsSupported(TSE_OPENGL_VERSION_MAJOR, TSE_OPENGL_VERSION_MINOR))
|
||||
{
|
||||
Debug::Log("gl3w dose not support the selected version of OpenGL.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(vsync) glfwSwapInterval(1);
|
||||
else glfwSwapInterval(0);
|
||||
|
||||
Debug::Log("OpenGL:" + std::string((const char*)glGetString(GL_VERSION)));
|
||||
Debug::Log("GLSL:" + std::string((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION)));
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glClearDepth(0.0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_GEQUAL);
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_FRONT);
|
||||
glFrontFace(GL_CW);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glClearColor(backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a);
|
||||
glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TSE::GLFW::OpenGLRenderingBackend::onResize(int width, int height)
|
||||
{
|
||||
glViewport(0,0,width, height);
|
||||
}
|
||||
|
||||
void TSE::GLFW::OpenGLRenderingBackend::onUpdate() const
|
||||
{
|
||||
int error = glGetError();
|
||||
if(error != GL_NO_ERROR)
|
||||
{
|
||||
Debug::Log("OpenGL Error: " + std::to_string(error));
|
||||
}
|
||||
|
||||
WindowGlfw* wnd = static_cast<WindowGlfw*>(window);
|
||||
glfwSwapBuffers(wnd->window);
|
||||
}
|
||||
|
||||
void TSE::GLFW::OpenGLRenderingBackend::onClear() const
|
||||
{
|
||||
//cameras
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void TSE::GLFW::OpenGLRenderingBackend::onClearDepthBuffer() const
|
||||
{
|
||||
//cameras
|
||||
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
Reference in New Issue
Block a user