First opengl/x11/window integration.
This commit is contained in:
parent
7c6a92f4ec
commit
cea3d2c39f
30 changed files with 254 additions and 72 deletions
|
@ -1,16 +1,13 @@
|
|||
#include "DrawingContext.h"
|
||||
|
||||
#include "AbstractGeometricItem.h"
|
||||
#include "AbstractPainter.h"
|
||||
#include "OpenGlPainter.h"
|
||||
#include "RasterPainter.h"
|
||||
#include "Grid.h"
|
||||
#include "TriMesh.h"
|
||||
|
||||
#include "DrawingSurface.h"
|
||||
#include "Scene.h"
|
||||
#include "Grid.h"
|
||||
|
||||
#include "MeshBuilder.h"
|
||||
|
||||
#include "TriMesh.h"
|
||||
|
||||
DrawingContext::DrawingContext(DrawingSurface* surface, DrawingMode requestedDrawingMode)
|
||||
: mSurface(surface),
|
||||
|
@ -32,11 +29,6 @@ std::unique_ptr<DrawingContext> DrawingContext::Create(DrawingSurface* surface,
|
|||
return std::make_unique<DrawingContext>(surface, requestedDrawingMode);
|
||||
}
|
||||
|
||||
void DrawingContext::updateMesh()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Scene* DrawingContext::getScene() const
|
||||
{
|
||||
return mScene.get();
|
||||
|
@ -49,5 +41,6 @@ DrawingSurface* DrawingContext::getSurface() const
|
|||
|
||||
void DrawingContext::paint()
|
||||
{
|
||||
|
||||
mScene->update(mDrawingMode == DrawingMode::RASTER ? mSurface->getImage() : nullptr);
|
||||
mPainter->paint(this);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
class Scene;
|
||||
class AbstractPainter;
|
||||
class DrawingSurface;
|
||||
class TriMesh;
|
||||
|
||||
enum class DrawingMode
|
||||
{
|
||||
|
@ -28,12 +27,10 @@ public:
|
|||
void paint();
|
||||
|
||||
private:
|
||||
void updateMesh();
|
||||
|
||||
DrawingMode mDrawingMode;
|
||||
std::unique_ptr<TriMesh> mMesh;
|
||||
std::unique_ptr<Scene> mScene;
|
||||
|
||||
DrawingSurface* mSurface{nullptr};
|
||||
std::unique_ptr<Scene> mScene;
|
||||
std::unique_ptr<AbstractPainter> mPainter;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#include "OpenGlPainter.h"
|
||||
|
||||
#include "DrawingContext.h"
|
||||
#include "DrawingSurface.h"
|
||||
#include "Scene.h"
|
||||
#include "TriMesh.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
|
@ -8,19 +11,47 @@
|
|||
|
||||
#include <GL/gl.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void OpenGlPainter::paint(DrawingContext* context)
|
||||
{
|
||||
auto surface = context->getSurface();
|
||||
const auto width = double(surface->getWidth());
|
||||
const auto height = double(surface->getHeight());
|
||||
|
||||
const auto num_mesh = context->getScene()->getNumMeshes();
|
||||
|
||||
glClearColor(0.4, 0.4, 0.4, 0.4);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glColor3f(1.0, 1.0, 1.0);
|
||||
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
glVertex3f(-0.7, 0.7, 0);
|
||||
glVertex3f(0.7, 0.7, 0);
|
||||
glVertex3f(0, -1, 0);
|
||||
glEnd();
|
||||
for (std::size_t idx=0; idx<num_mesh; idx++)
|
||||
{
|
||||
auto mesh = context->getScene()->getMesh(idx);
|
||||
const auto faces = mesh->getFaceVertices();
|
||||
|
||||
glColor3f(1.0, 0.0, 1.0);
|
||||
|
||||
for (const auto& face : faces)
|
||||
{
|
||||
glBegin(GL_TRIANGLES);
|
||||
double x0 = 2.0*face[0].getX() / width - 1.0;
|
||||
double y0 = 2.0*face[0].getY() / height - 1.0;
|
||||
|
||||
double x1 = 2.0*face[1].getX() / width - 1.0;
|
||||
double y1 = 2.0*face[1].getY() / height - 1.0;
|
||||
|
||||
double x2 = 2.0*face[2].getX() / width - 1.0;
|
||||
double y2 = 2.0*face[2].getY() / height - 1.0;
|
||||
|
||||
glVertex3f(x0, y0, 0);
|
||||
glVertex3f(x1, y1, 0);
|
||||
glVertex3f(x2, y2, 0);
|
||||
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
glFlush();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue