diff --git a/src/main.c b/src/main.c index 1bf4254..a5a2693 100644 --- a/src/main.c +++ b/src/main.c @@ -14,10 +14,11 @@ static const char * const vertex_shader = "#version 330 core\n \ layout (location = 1) in vec2 aTexCoord;\n\ out vec2 texCoord;\n\ out vec3 vertPos;\n \ + uniform float zoom;\n\ void main()\n \ {\n \ gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n \ - texCoord = aTexCoord;\n\ + texCoord = aTexCoord / zoom;\n\ vertPos = aPos;\n\ }\n"; @@ -30,7 +31,7 @@ static const char * const orange_framgment_shader = " \ \n \ void main()\n \ {\n \ - FragColor = texture(ourTexture, texCoord); //+ vec4(vertPos.x, -vertPos.x, vertPos.y, 0.0);\n \ + FragColor = texture(ourTexture, texCoord);\n\ }"; struct canvas_buffer { @@ -207,10 +208,10 @@ static int calculate_mandelbrot(struct canvas_buffer *buff) float vertices[] = { // Vertex Texture - -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, // bottom left - -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // top left - 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, // bottom right - 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, // top right + -0.95f, -0.95f, 0.0f, 0.0f, 0.0f, // bottom left + -0.95f, 0.95f, 0.0f, 0.0f, 1.0f, // top left + 0.95f, -0.95f, 0.0f, 1.0f, 0.0f, // bottom right + 0.95f, 0.95f, 0.0f, 1.0f, 1.0f, // top right }; unsigned int indices[] = { @@ -226,13 +227,17 @@ static unsigned int texture_id; gboolean render(GtkGLArea *gl_area, GdkGLContext *context, gpointer user_data) { + int zoom_loc; + static float zoom = 1.0f; gtk_gl_area_make_current(gl_area); glClear(GL_COLOR_BUFFER_BIT); glUseProgram(shader_program_id); - //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + zoom_loc = glGetUniformLocation(shader_program_id, "zoom"); + glUniform1f(zoom_loc, zoom); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glBindTexture(GL_TEXTURE_2D, texture_id); glBindVertexArray(vertex_array_object); //glDrawArrays(GL_TRIANGLES, 0, 3); @@ -254,7 +259,7 @@ void realize(GtkGLArea *gl_area, gpointer user_data) char info_log[512]; gtk_gl_area_make_current(gl_area); - glClearColor(0, 0, 0, 1); + glClearColor(0.2, 0.2, 0.2, 1); glGenVertexArrays(1, &vertex_array_object); glBindVertexArray(vertex_array_object); @@ -346,20 +351,20 @@ int main(int argc, char **argv) g_signal_connect(window, "delete-event", G_CALLBACK(on_main_window_close), NULL); - mandelbrot_buff.x_span = 0.05;//2.8; - mandelbrot_buff.y_span = 0.05;//2.25; + mandelbrot_buff.x_span = 0.1;//2.8; + mandelbrot_buff.y_span = 0.1;//2.25; mandelbrot_buff.center_x = -0.6; mandelbrot_buff.center_y = 0.44; - mandelbrot_buff.width = 5000; - mandelbrot_buff.height = 5000; - mandelbrot_buff.iterations = 600; + mandelbrot_buff.width = 4000; + mandelbrot_buff.height = 4000; + mandelbrot_buff.iterations = 1000; mandelbrot_buff.mandelbrot_buffer = NULL; printf("Compile and run Mandelbrot on OpenCL HW\n"); start = clock(); calculate_mandelbrot(&mandelbrot_buff); end = clock(); - printf("Calculation finished. Time needed: %lf ms\n", ((double) (end - start)) / CLOCKS_PER_SEC * 1000.0); + printf("Calculation finished. Time needed: %lf ms\n", ((double)(end - start)) / CLOCKS_PER_SEC * 1000.0); gl_area = GTK_GL_AREA(gtk_gl_area_new()); @@ -377,7 +382,6 @@ int main(int argc, char **argv) gtk_gl_area_make_current(gl_area); printf("Gui will be displayed\n"); - gtk_main(); return 0;