stuff-from-scratch/src/graphics/opengl/OpenGlPainter.cpp
2022-11-16 09:39:05 +00:00

68 lines
1.5 KiB
C++

#include "OpenGlPainter.h"
#include "DrawingContext.h"
#include "DrawingSurface.h"
#include "Scene.h"
#include "TriMesh.h"
#include "FontsManager.h"
#include "FontGlyph.h"
#include "TextData.h"
#include "OpenGlShaderProgram.h"
#include "OpenGlMeshPainter.h"
#include "OpenGlTextPainter.h"
#include "OpenGlFontTexture.h"
#include "File.h"
#ifdef _WIN32
#include <windows.h>
#endif
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glx.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
OpenGlPainter::OpenGlPainter()
: mMeshPainter(std::make_unique<OpenGlMeshPainter>()),
mTextPainter(std::make_unique<OpenGlTextPainter>())
{
}
void OpenGlPainter::paint(DrawingContext* context)
{
auto surface = context->getSurface();
const auto width = double(surface->getWidth());
const auto height = double(surface->getHeight());
glViewport(0, 0, width, height);
glOrtho(0, width, 0, height, -1.0, 1.0);
glClearColor(0.5, 0.5, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
const auto num_mesh = context->getScene()->getNumMeshes();
for (std::size_t idx=0 ; idx< num_mesh; idx++)
{
auto mesh = context->getScene()->getMesh(idx);
mMeshPainter->paint(mesh, context);
}
auto text_data = context->getScene()->getTextData();
for (const auto& text_item : context->getScene()->getTextData())
{
mTextPainter->paint(text_item, context);
break;
}
glFlush();
}