diff --git a/source/GfxDriver/OpenGL/OpenGLDrv.cpp b/source/GfxDriver/OpenGL/OpenGLDrv.cpp new file mode 100644 index 0000000..ead2e2a --- /dev/null +++ b/source/GfxDriver/OpenGL/OpenGLDrv.cpp @@ -0,0 +1,53 @@ + +#include "OpenGLDrv.h" +#include + +namespace sp { + +std::string OpenGLDrv::getVendor() 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 OpenGLDrv::setViewport(int x, int y, int width, int height) +{ + glViewport(x, y, width, height); +} + +void OpenGLDrv::setClearColor(float r, float g, float b, float a) +{ + glClearColor(r, g, b, 1.0f); +} + +void OpenGLDrv::clearBuffer(GfxDriver::BufferFlags flags) +{ + int glFlags = 0; + + if (flags == GfxDriver::CLEAR_BUFFER_BIT) { + glFlags |= GL_COLOR_BUFFER_BIT; + } + + glClear(glFlags); +} + +void OpenGLDrv::clearColorBuffer() +{ + glClear(GL_COLOR_BUFFER_BIT); +} + +} // namespace sp diff --git a/source/GfxDriver/OpenGL/OpenGLDrv.h b/source/GfxDriver/OpenGL/OpenGLDrv.h new file mode 100644 index 0000000..c993fb0 --- /dev/null +++ b/source/GfxDriver/OpenGL/OpenGLDrv.h @@ -0,0 +1,25 @@ + +#ifndef SPECTRE_GFXDRIVER_OPENGL_OPENGLDRV_H +#define SPECTRE_GFXDRIVER_OPENGL_OPENGLDRV_H + +#include + +namespace sp { + +class OpenGLDrv : public GfxDriver +{ +public: + virtual std::string getVendor() const; + + virtual void setViewport(int x, int y, int width, int height); + + virtual void setClearColor(float r, float g, float b, float a); + + virtual void clearBuffer(GfxDriver::BufferFlags flags); + + virtual void clearColorBuffer(); +}; + +} // namespace sp + +#endif /* SPECTRE_GFXDRIVER_GFXDRIVER_H */