Julia pos slider

This commit is contained in:
hodasemi 2018-10-21 16:18:27 +02:00
parent 26144217b4
commit fdf5073e31
4 changed files with 36 additions and 1 deletions

View file

@ -5,6 +5,7 @@
in vec4 fragment_color;
in vec2 vertex_pos;
in vec2 julia_position;
out vec4 color;
@ -15,7 +16,7 @@ const int i_max = 200;
void main()
{
vec2 z = vertex_pos * m;
vec2 z = julia_position * m;
int i;
for(i = 0; i < i_max; i++) {

View file

@ -9,8 +9,11 @@ in vec4 in_color;
uniform mat4 view;
uniform mat4 proj;
uniform vec2 julia_positions[3];
out vec4 fragment_color;
out vec2 vertex_pos;
out vec2 julia_position;
void main()
{
@ -18,4 +21,6 @@ void main()
gl_Position = proj * view * in_position;
fragment_color = in_color;
julia_position = julia_positions[gl_VertexID];
}

View file

@ -26,6 +26,13 @@ private:
nanogui::Slider* sldJuliaCY;
nanogui::Slider* sldJuliaZoom; //Zoom factor for the Julia fractal
nanogui::Slider* point1X;
nanogui::Slider* point1Y;
nanogui::Slider* point2X;
nanogui::Slider* point2Y;
nanogui::Slider* point3X;
nanogui::Slider* point3Y;
// The following variables hold OpenGL object IDs
GLuint vertex_shader_id, // ID of the vertex shader
fragment_shader_id, // ID of the fragment shader
@ -40,6 +47,8 @@ private:
GLint julia_m_id;
GLint julia_c_id;
GLint julia_pos_id;
// Read, Compile and link the shader codes to a shader program
void CreateShaders();
// Create and define the vertex array and add a number of vertex buffers

View file

@ -15,6 +15,8 @@
#include "glsl.h"
using namespace nse::gui;
Viewer::Viewer()
: AbstractViewer("CG1 Exercise 1")
{
@ -29,6 +31,8 @@ Viewer::Viewer()
julia_m_id = glGetUniformLocation(program_id, "m");
julia_c_id = glGetUniformLocation(program_id, "c");
julia_pos_id = glGetUniformLocation(program_id, "julia_positions");
modelViewMatrix.setIdentity();
projectionMatrix.setIdentity();
@ -50,6 +54,13 @@ void Viewer::SetupGUI()
sldJuliaCY = nse::gui::AddLabeledSliderWithDefaultDisplay(mainWindow, "JuliaC.Y", std::make_pair(-1.0f, 1.0f), -0.3f, 2);
sldJuliaZoom = nse::gui::AddLabeledSliderWithDefaultDisplay(mainWindow, "Julia Zoom", std::make_pair(0.01f, 10.0f), 1.0f, 2);
point1X = AddLabeledSliderWithDefaultDisplay(mainWindow, "Point1.X", std::make_pair(-1.0f, 1.0f), 0.0f, 2);
point1Y = AddLabeledSliderWithDefaultDisplay(mainWindow, "Point1.Y", std::make_pair(-1.0f, 1.0f), 0.0f, 2);
point2X = AddLabeledSliderWithDefaultDisplay(mainWindow, "Point2.X", std::make_pair(-1.0f, 1.0f), -1.0f, 2);
point2Y = AddLabeledSliderWithDefaultDisplay(mainWindow, "Point2.Y", std::make_pair(-1.0f, 1.0f), -1.0f, 2);
point3X = AddLabeledSliderWithDefaultDisplay(mainWindow, "Point3.X", std::make_pair(-1.0f, 1.0f), 1.0f, 2);
point3Y = AddLabeledSliderWithDefaultDisplay(mainWindow, "Point3.Y", std::make_pair(-1.0f, 1.0f), 1.0f, 2);
performLayout();
}
@ -247,6 +258,13 @@ void Viewer::drawContents()
else
glDisable(GL_DEPTH_TEST);
// create uniform buffer for julia_positions
float julia_positions[6] = {
point1X->value(), point1Y->value(),
point2X->value(), point2Y->value(),
point3X->value(), point3Y->value()
};
// Activate the shader program
glUseProgram(program_id);
@ -262,6 +280,8 @@ void Viewer::drawContents()
glUniform1f(julia_m_id, juliaZoom);
glUniform2fv(julia_c_id, 1, juliaC.data());
glUniform2fv(julia_pos_id, 6, julia_positions);
// Bind the vertex array
glBindVertexArray(vertex_array_id);
// Draw the bound vertex array. Start at element 0 and draw 3 vertices