93 lines
No EOL
1.6 KiB
C++
93 lines
No EOL
1.6 KiB
C++
|
|
#include <Spectre/Graphics.h>
|
|
#include <Spectre/Graphics/OpenGL.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
|