Fix Julia and let gui configure it

This commit is contained in:
hodasemi 2018-10-17 16:39:10 +02:00
parent 8e8fb66873
commit 907100c0a4
4 changed files with 38 additions and 54 deletions

View file

@ -8,22 +8,21 @@ in vec2 vertex_pos;
out vec4 color;
uniform float m;
uniform vec2 c;
const int i_max = 200;
void main()
{
float m = 0.3;
vec2 c = vec2(0.5, 1.5);
vec2 z = vertex_pos * m;
int i;
int i = 0;
for(; i < i_max; i++) {
for(i = 0; i < i_max; i++) {
float x = (z.x * z.x - z.y * z.y) + c.x;
float y = (z.y * z.x - z.x * z.y) + c.y;
float y = (z.y * z.x + z.x * z.y) + c.y;
if (x*x + y*y > 4.0) {
if ((x*x + y*y) > 4.0) {
break;
}
@ -38,13 +37,4 @@ void main()
}
color = vec4(alpha, alpha, alpha, alpha) * 10.0 * fragment_color;
/**** Begin of tasks ***
- 1.2.5
Implement the pseudo-code for calculating the julia fractal at a point.
To get the point you can declare a new "in" variable which contains the
position and just use the X- and Y- value.
*** End of tasks ***/
}

View file

@ -18,18 +18,4 @@ void main()
gl_Position = proj * view * in_position;
fragment_color = in_color;
/* - 1.2.2 (b)
* Declare a new "in" variable with the name "in_color". Instead of setting
* "fragment_color" to the position, set it to "in_color. */
/* - 1.2.4 (a)
* Declare two new "uniform" variables with the type "mat4" (above the main function)
* that store the modelview and projection matrix. To apply the transformations
* multiply the value of "in_position" before setting "gl_Position". */
/* - 1.2.5
* The algorithm to calculate the julia fractal needs a position as input.
* Declare another "out" variable and set it to the untransformed input
* position. */
}

View file

@ -37,6 +37,8 @@ private:
GLint view_uniform_id;
GLint proj_uniform_id;
GLint julia_m_id;
GLint julia_c_id;
// Read, Compile and link the shader codes to a shader program
void CreateShaders();

View file

@ -26,6 +26,9 @@ Viewer::Viewer()
view_uniform_id = glGetUniformLocation(program_id, "view");
proj_uniform_id = glGetUniformLocation(program_id, "proj");
julia_m_id = glGetUniformLocation(program_id, "m");
julia_c_id = glGetUniformLocation(program_id, "c");
modelViewMatrix.setIdentity();
projectionMatrix.setIdentity();
@ -59,40 +62,40 @@ void Viewer::CreateVertexBuffers()
// Define 3 vertices for one face
GLfloat positions[] = {
-1, 1, -1, 1,
1, -1, -1, 1,
1, 1, 1, 1,
-1, -1, -1, 1, // 1
1, -1, 1, 1, // 6
-1, 1, 1, 1, // 8
-1, 1, -1, 1,
-1, -1, 1, 1,
1, -1, -1, 1,
-1, -1, -1, 1, // 1
1, 1, -1, 1, // 3
1, -1, 1, 1, // 6
-1, 1, -1, 1,
-1, -1, 1, 1,
1, 1, 1, 1,
-1, -1, -1, 1, // 1
-1, 1, 1, 1, // 8
1, 1, -1, 1, // 3
1, -1, -1, 1,
1, 1, 1, 1,
-1, -1, 1, 1,
1, 1, -1, 1, // 3
-1, 1, 1, 1, // 8
1, -1, 1, 1, // 6
};
GLfloat colors[] = {
1, 0, 0, 1,
1, 0, 0, 1,
1, 0, 0, 1,
0, 1, 0, 1,
0, 1, 0, 1,
0, 1, 0, 1,
0, 0, 1, 1,
0, 0, 1, 1,
0, 0, 1, 1,
1, 0, 0, 1,
0, 1, 0, 1,
0, 0, 1, 1,
1, 0, 0, 1,
0, 1, 0, 1,
0, 0, 1, 1,
1, 0, 0, 1,
0, 1, 0, 1,
0, 0, 1, 1,
1, 1, 0, 1,
1, 1, 0, 1,
1, 1, 0, 1,
};
// Generate the vertex array
@ -255,6 +258,9 @@ void Viewer::drawContents()
glUniformMatrix4fv(view_uniform_id, 1, false, modelViewMatrix.data());
glUniformMatrix4fv(proj_uniform_id, 1, false, projectionMatrix.data());
glUniform1f(julia_m_id, juliaZoom);
glUniform2fv(julia_c_id, 1, juliaC.data());
// Bind the vertex array
glBindVertexArray(vertex_array_id);
// Draw the bound vertex array. Start at element 0 and draw 3 vertices