Skip to content

Commit

Permalink
can render each country in different color now
Browse files Browse the repository at this point in the history
  • Loading branch information
denizdiktas committed Aug 13, 2023
1 parent ee279d4 commit d97d364
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Main_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,11 @@ void Main_widget::initializeGL()
//auto triangle_points = Aos::get_triangles(arrh);
auto country_triangles_map = Aos::get_triangles_by_country(arrh);
qDebug() << "num countries = " << country_triangles_map.size();
auto rndm = [] {return rand() / double(RAND_MAX); };
for (auto& [country_name, triangle_points] : country_triangles_map)
{
auto country_triangles = std::make_unique<Triangles>(triangle_points);
country_triangles->set_color(QVector4D(rndm(), rndm(), rndm(), 1));
g_country_triangles.push_back(std::move(country_triangles));
}
//qDebug() << "num triangles = " << triangle_points.size() / 3;
Expand Down Expand Up @@ -558,7 +560,10 @@ void Main_widget::paintGL()
//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
//g_all_triangles->draw();
for (auto& country : g_country_triangles)
{
sp.set_uniform("u_color", country->get_color());
country->draw();
}

//sp.set_uniform("u_color", QVector4D(0,0,0,1));
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
Expand Down
9 changes: 9 additions & 0 deletions Arrangement_on_surface_2/demo/earth/Triangles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ Triangles::Triangles(std::vector<QVector3D>& vertices)
glBindVertexArray(0);
}

void Triangles::set_color(const QVector4D& rgba)
{
m_color = rgba;
}
const QVector4D& Triangles::get_color() const
{
return m_color;
}

void Triangles::draw()
{
// DRAW TRIANGLES
Expand Down
7 changes: 5 additions & 2 deletions Arrangement_on_surface_2/demo/earth/Triangles.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ class Triangles : protected OpenGLFunctionsBase
Triangles(std::vector<QVector3D>& vertices);

int get_num_triangles() const;
void set_color(const QVector4D& rgba);
const QVector4D& get_color() const;

void draw();

private:
GLuint m_vao, m_vbo;
int m_num_vertices;
GLuint m_vao, m_vbo;
int m_num_vertices;
QVector4D m_color;
};


Expand Down

0 comments on commit d97d364

Please sign in to comment.