Add outline rendering.
This commit is contained in:
parent
f04d86e0ad
commit
a20c0183df
20 changed files with 291 additions and 64 deletions
|
@ -3,7 +3,9 @@
|
|||
#include "DrawingContext.h"
|
||||
#include "DrawingSurface.h"
|
||||
#include "SceneModel.h"
|
||||
|
||||
#include "TriMesh.h"
|
||||
#include "LineMesh.h"
|
||||
|
||||
#include "OpenGlShaderProgram.h"
|
||||
|
||||
|
@ -43,7 +45,7 @@ void OpenGlMeshPainter::initializeBuffers()
|
|||
glGenVertexArrays(1, &mVertexArray);
|
||||
}
|
||||
|
||||
void OpenGlMeshPainter::paint(const std::vector<float>& verts, const std::vector<unsigned>& elements, const std::vector<float>& color)
|
||||
void OpenGlMeshPainter::paint(const std::vector<float>& verts, const std::vector<unsigned>& elements, const std::vector<float>& color, bool lines)
|
||||
{
|
||||
glBindVertexArray(mVertexArray);
|
||||
|
||||
|
@ -66,7 +68,15 @@ void OpenGlMeshPainter::paint(const std::vector<float>& verts, const std::vector
|
|||
glUniform4f(vertexColorLocation, float(color[0]), float(color[1]), float(color[2]), float(color[3]));
|
||||
|
||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||
|
||||
if (lines)
|
||||
{
|
||||
glDrawElements(GL_LINES, elements.size(), GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
glDrawElements( GL_TRIANGLES, elements.size(), GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
|
@ -86,19 +96,14 @@ void OpenGlMeshPainter::paint(SceneModel* model, DrawingContext* context)
|
|||
const auto width = float(surface->getWidth());
|
||||
const auto height = float(surface->getHeight());
|
||||
|
||||
auto mesh = dynamic_cast<TriMesh*>(model->getMesh());
|
||||
std::cout << "Paint mesh for model " << model->getName() << std::endl;
|
||||
|
||||
auto transform = model->getTransform();
|
||||
|
||||
auto vertices = mesh->getVerticesFlat<float>();
|
||||
auto vertices = model->getMesh()->getVerticesFlat<float>();
|
||||
for (std::size_t idx = 0; idx<vertices.size(); idx++)
|
||||
{
|
||||
if (idx % 3 == 0)
|
||||
{
|
||||
auto x = vertices[idx]*transform.getScaleX() + transform.getLocation().getX();
|
||||
vertices[idx] = 2*x/width - 1.0;
|
||||
std::cout << "Vert x is " << vertices[idx] << std::endl;
|
||||
}
|
||||
else if(idx%3 == 1)
|
||||
{
|
||||
|
@ -107,11 +112,19 @@ void OpenGlMeshPainter::paint(SceneModel* model, DrawingContext* context)
|
|||
}
|
||||
}
|
||||
|
||||
const auto indices = mesh->getFaceNodeIds();
|
||||
std::vector<unsigned> indices;
|
||||
const bool line_mesh = model->getMesh()->getType() == AbstractMesh::MeshType::LINE;
|
||||
if (line_mesh)
|
||||
{
|
||||
indices = dynamic_cast<LineMesh*>(model->getMesh())->getEdgeNodeIds();
|
||||
}
|
||||
else
|
||||
{
|
||||
indices = dynamic_cast<TriMesh*>(model->getMesh())->getFaceNodeIds();
|
||||
|
||||
}
|
||||
auto model_color = model->getColor().getAsVectorDouble();
|
||||
std::cout << "Color is " << model_color[0] << "|" << model_color[0] << std::endl;
|
||||
std::vector<float> color = {float(model_color[0]), float(model_color[1]), float(model_color[2]), float(model_color[3])};
|
||||
|
||||
paint(vertices, indices, color);
|
||||
paint(vertices, indices, color, line_mesh);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ private:
|
|||
void initializeShader();
|
||||
void initializeBuffers();
|
||||
|
||||
void paint(const std::vector<float>& verts, const std::vector<unsigned>& elements, const std::vector<float>& color);
|
||||
void paint(const std::vector<float>& verts, const std::vector<unsigned>& elements, const std::vector<float>& color, bool lines = false);
|
||||
|
||||
unsigned mVertexBuffer{0};
|
||||
unsigned mElementBuffer{0};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue