-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
452cd88
commit 74b54a3
Showing
6 changed files
with
128 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
Arrangement_on_surface_2/demo/earth/World_coordinate_axes.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
#include "World_coordinate_axes.h" | ||
|
||
#include <qvector3d.h> | ||
|
||
#include <vector> | ||
|
||
|
||
World_coord_axes::World_coord_axes(float length) | ||
{ | ||
initializeOpenGLFunctions(); | ||
|
||
const auto a = length; | ||
const float c = 0.0; | ||
std::vector<QVector3D> vertex_data { | ||
QVector3D(0,0,0), QVector3D(1,0,0), | ||
QVector3D(a,0,0), QVector3D(1,0,0), | ||
|
||
QVector3D(0,0,0), QVector3D(0,1,0), | ||
QVector3D(0,a,0), QVector3D(0,1,0), | ||
|
||
QVector3D(0,0,0), QVector3D(c,c,1), | ||
QVector3D(0,0,a), QVector3D(c,c,1) | ||
}; | ||
|
||
|
||
// DEFINE OPENGL BUFFERS | ||
glGenVertexArrays(1, &m_vao); | ||
glBindVertexArray(m_vao); | ||
|
||
|
||
// Vertex Buffer | ||
glGenBuffers(1, &m_vbo); | ||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo); | ||
auto vertex_buffer_size = sizeof(QVector3D) * vertex_data.size(); | ||
auto vertex_buffer_data = reinterpret_cast<const void*>(vertex_data.data()); | ||
glBufferData(GL_ARRAY_BUFFER, | ||
vertex_buffer_size, | ||
vertex_buffer_data, | ||
GL_STATIC_DRAW); | ||
|
||
// Position Vertex-Attribute | ||
GLint position_attrib_index = 0; | ||
const void* position_offset = 0; | ||
GLsizei stride = 6 * sizeof(float); | ||
glVertexAttribPointer(position_attrib_index, | ||
3, | ||
GL_FLOAT, GL_FALSE, | ||
stride, | ||
position_offset); | ||
glEnableVertexAttribArray(position_attrib_index); | ||
|
||
// Color Vertex-Attribute | ||
GLint color_attrib_index = 1; | ||
auto* color_offset = reinterpret_cast<const void*>(3 * sizeof(float)); | ||
glVertexAttribPointer(color_attrib_index, | ||
3, | ||
GL_FLOAT, | ||
GL_FALSE, | ||
stride, | ||
color_offset); | ||
glEnableVertexAttribArray(color_attrib_index); | ||
|
||
glBindBuffer(GL_ARRAY_BUFFER, 0); | ||
glBindVertexArray(0); | ||
} | ||
|
||
void World_coord_axes::draw() | ||
{ | ||
glBindVertexArray(m_vao); | ||
{ | ||
const int count = 2 * 3; // = 2 * number of lines | ||
glDrawArrays(GL_LINES, 0, count); | ||
} | ||
glBindVertexArray(0); | ||
} |
21 changes: 21 additions & 0 deletions
21
Arrangement_on_surface_2/demo/earth/World_coordinate_axes.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
#ifndef WORLD_COORD_AXES_H | ||
#define WORLD_COORD_AXES_H | ||
|
||
#include "Common_defs.h" | ||
#include <qvector4d.h> | ||
|
||
|
||
class World_coord_axes : protected OpenGLFunctionsBase | ||
{ | ||
public: | ||
World_coord_axes(float length); | ||
|
||
void draw(); | ||
|
||
private: | ||
GLuint m_vao, m_vbo; | ||
}; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
Arrangement_on_surface_2/demo/earth/shaders/color_only_fs.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
|
||
#version 330 | ||
|
||
uniform vec4 u_color; | ||
|
||
|
||
in vec3 v_color; | ||
out vec4 out_color; | ||
|
||
|
||
void main() | ||
{ | ||
out_color = u_color; | ||
out_color = vec4(v_color, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters