You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.4 KiB
C++
113 lines
3.4 KiB
C++
/******************************************************************************
|
|
* File - glGraphics.h
|
|
* Author - Joey Pollack
|
|
* Date - 2021/08/30 (y/m/d)
|
|
* Mod Date - 2021/09/02 (y/m/d)
|
|
* Description - An openGL implementation of the engine Graphics interface.
|
|
******************************************************************************/
|
|
|
|
#ifndef OGLGRAPHICS_H_
|
|
#define OGLGRAPHICS_H_
|
|
|
|
#include "../igraphics.h"
|
|
#include <glad/gl.h>
|
|
#include "glShader.h"
|
|
#include "glText.h"
|
|
#include <map>
|
|
#include <string>
|
|
|
|
|
|
namespace lunarium
|
|
{
|
|
class OglGraphics : public IGraphics
|
|
{
|
|
private: // Interface methods for use only by the engine
|
|
friend Core;
|
|
|
|
OglGraphics();
|
|
|
|
virtual OpRes Initialize(Window* pWindow, bool enableDebugMessages = true);
|
|
virtual void Shutdown();
|
|
|
|
virtual void ResizeCanvas();
|
|
|
|
virtual void BeginDraw(RenderTarget rt = RenderTarget::RT_WINDOW);
|
|
|
|
/// The image returned by this method is dynamic
|
|
/// and needs to be cleaned up
|
|
virtual Image* EndDraw();
|
|
|
|
public: //
|
|
|
|
virtual void SetClearColor(Color c);
|
|
virtual Color GetClearColor() const;
|
|
|
|
// Draw Methods
|
|
virtual void DrawLine(glm::vec2 point1, glm::vec2 point2, Color color, float lineWidth);
|
|
virtual void DrawEllipse(glm::vec2 center, glm::vec2 radii, Color color, float thickness, int resolution);
|
|
virtual void DrawFilledEllipse(glm::vec2 center, glm::vec2 radii, Color color, int resolution);
|
|
virtual void DrawBox(Rectangle dimensions, Color color, float thickness);
|
|
virtual void DrawFilledBox(glm::vec2 topLeft, glm::vec2 botRight, Color color);
|
|
virtual void DrawImage(Image& image, glm::vec2 topLeft, Color color);
|
|
virtual void DrawImage(Image& image, Rectangle source, Rectangle destination, Color color);
|
|
virtual void DrawString(const char* string, Rectangle boundingArea, Color color, float scale = 1.0f, int font = 0);
|
|
|
|
// Takes raw image data and creates and Image class instance out of it.
|
|
// The raw data must be in one of the ImageFormats and it must be 1 byte per channel.
|
|
virtual Image* CreateImage(const unsigned char* pData, int width, int height, ImageFormat format);
|
|
virtual void DestroyImage(Image* i);
|
|
|
|
// Fonts
|
|
int DefaultFont() const;
|
|
|
|
// For weight, 400 is normal and 700 is bold
|
|
virtual int CreateNewFont(const char* fontName, float size = 12.0f, int weight = 400);
|
|
|
|
private: // DATA
|
|
Window* mpWindow;
|
|
glm::mat4 mProjection;
|
|
|
|
// Viewport/Framebuffer width and height
|
|
int mFBWidth;
|
|
int mFBHeight;
|
|
|
|
// Objects for rendering to texture
|
|
unsigned int mFBO;
|
|
unsigned int mRBO; // for depth and stencil
|
|
RenderTarget mRT;
|
|
|
|
// TEXT
|
|
glText mText;
|
|
|
|
// Sprite Data
|
|
unsigned int mImageVAO;
|
|
glShader mImageShader;
|
|
|
|
// Shapes
|
|
GLuint mRectVAO;
|
|
GLuint mRectVBO;
|
|
glShader mShapeShader;
|
|
|
|
// Ellipse
|
|
GLuint mEllipseVAO;
|
|
GLuint mEllipseVBO;
|
|
|
|
private: // Helper Initializers
|
|
void InitDebugMsgSystem();
|
|
void InitImageSystem();
|
|
void InitShapeSystem();
|
|
void InitTextureFrameBuffer();
|
|
|
|
private: // Helper methods
|
|
|
|
private: // Debug Message System
|
|
|
|
friend void GLAPIENTRY MessageCallback(GLenum source, GLenum type, GLuint id,
|
|
GLenum severity, GLsizei length, const GLchar* message, const void* userParam);
|
|
static std::map<int, std::string> mDebugMsgTypes;
|
|
static std::map<int, std::string> mDebugMsgSources;
|
|
static std::map<int, std::string> mDebugMsgSeverity;
|
|
};
|
|
}
|
|
|
|
#endif // OGLGRAPHICS_H_
|