1
0
Fork 0
spectre/source/Graphics/OpenGL.cpp
Henrik Hautakoski 2a111a237d
Move OpenGL headers from API to implementation.
We don't want to expose any OpenGL functions to client code. Because if we do, there is a chance we break client code if we switch implementation (Direct3D).
2020-01-03 20:30:08 +01:00

93 lines
1.6 KiB
C++

#include <Spectre/Graphics.h>
#include <Graphics/GL/gl.h>
#include <string>
namespace sp {
Graphics::Graphics(PlatformApplication *platform)
{
m_width = 800;
m_height = 600;
m_display = new Display();
}
Graphics::~Graphics()
{
shutdown();
delete m_display;
}
bool Graphics::init()
{
DisplayMode mode(m_width, m_height);
DisplayDescription desc(mode);
desc.decoration = DisplayDecorate::Menu | DisplayDecorate::Close | DisplayDecorate::Resize;
m_display->create(desc);
setClearColor(0.0f, 0.0f, 0.0f);
swapBuffers();
return true;
}
void Graphics::shutdown()
{
m_display->destroy();
}
std::string Graphics::getVersion() const
{
char buf[512];
std::string prof = "Compability";
char *ver = (char*) glGetString(GL_VERSION);
char *ven = (char*) glGetString(GL_VENDOR);
char *ren = (char*) glGetString(GL_RENDERER);
GLint flags;
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &flags);
if (flags & GL_CONTEXT_CORE_PROFILE_BIT) {
prof = "Core";
}
snprintf(buf, sizeof(buf), "OpenGL %s %s profile - %s %s", ver, prof.c_str(), ren, ven);
return std::string(buf);
}
void Graphics::setDisplayMode(Display::Mode mode)
{
m_display->setVideoMode(mode);
}
void Graphics::setSize(int width, int height)
{
m_display->setSize(width, height);
}
void Graphics::setViewport(int x, int y, int width, int height)
{
glViewport(x, y, width, height);
}
void Graphics::setClearColor(float r, float g, float b)
{
glClearColor(r, g, b, 1.0f);
}
void Graphics::clearBuffer()
{
glClear(GL_COLOR_BUFFER_BIT);
}
void Graphics::swapBuffers()
{
m_display->swapBuffers();
}
} // namespace sp