58 lines
1.3 KiB
C++
58 lines
1.3 KiB
C++
|
|
#define RENDERER_OPENGL
|
|
#ifdef RENDERER_OPENGL
|
|
#undef RENDERER_OPENGL
|
|
|
|
#include "pch.hpp"
|
|
|
|
#include "utils/Renderer/Renderer.h"
|
|
|
|
#define GLEW_STATIC
|
|
#include <GL/glew.h>
|
|
|
|
|
|
namespace Archimedes {
|
|
|
|
class VertexArrayOpenGL : public VertexArray {};
|
|
|
|
class IndexArrayOpenGL : public IndexArray {};
|
|
|
|
class ShaderOpenGL : public Shader {};
|
|
|
|
class RendererOpenGL : public Renderer {
|
|
|
|
public:
|
|
typedef void renderCmd();
|
|
|
|
RendererOpenGL() {};
|
|
~RendererOpenGL() {};
|
|
|
|
bool init() override {
|
|
return glewInit() == GLEW_OK;
|
|
};
|
|
|
|
void render() override {
|
|
|
|
glViewport(0, 0, w, h);
|
|
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
}
|
|
|
|
void draw(const VertexArray& va, const IndexArray& ia, const Shader& shader) override {
|
|
|
|
glUseProgram(shader.id);
|
|
|
|
glBindVertexArray(va.id);
|
|
|
|
glDrawElements(GL_TRIANGLES, va.count, GL_UNSIGNED_INT, 0);
|
|
|
|
glBindVertexArray(0);
|
|
}
|
|
|
|
RendererOpenGL* getRendererImpl() override { return this; }
|
|
};
|
|
}
|
|
|
|
#endif
|