Compare commits

...

2 Commits

Author SHA1 Message Date
bb4140b819 Add zoom to texture and a gray border around square 2019-10-01 14:27:08 +02:00
8e66150aae Add cglm to project 2019-10-01 14:25:27 +02:00
3 changed files with 37 additions and 17 deletions

View File

@ -14,6 +14,7 @@ find_package(OpenCL REQUIRED)
add_subdirectory(glade)
add_subdirectory(cglm)
include_directories(${GLIB_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS} ${CAIRO_INCLUDE_DIRS} ${OPENCL_INCLUDE_DIRS})
link_directories(${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS} ${CAIRO_LINK_DIRS})
@ -25,9 +26,9 @@ aux_source_directory("src" SOURCES)
add_compile_options(-Wall)
add_executable(${PROJECT_NAME} ${SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/glade/resources.c)
add_dependencies(${PROJECT_NAME} glib-resources)
add_dependencies(${PROJECT_NAME} glib-resources cglm)
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/glade/resources.c PROPERTIES GENERATED 1)
target_link_libraries(${PROJECT_NAME} ${GLIB_LDFLAGS} ${GTK3_LDFLAGS} ${CAIRO_LDFLAGS} m pthread ${OPENCL_LIBRARIES} epoxy)
target_link_libraries(${PROJECT_NAME} ${GLIB_LDFLAGS} ${GTK3_LDFLAGS} ${CAIRO_LDFLAGS} m pthread ${OPENCL_LIBRARIES} epoxy cglm)
install (TARGETS ${PROJECT_NAME} DESTINATION bin)
message(STATUS "OpenCL found: ${OPENCL_FOUND}")

14
cglm/CMakeLists.txt Normal file
View File

@ -0,0 +1,14 @@
project(cglm)
cmake_minimum_required(VERSION 2.8)
include_directories(${GLIB_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS} ${CAIRO_INCLUDE_DIRS} ${OPENCL_INCLUDE_DIRS})
link_directories(${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS} ${CAIRO_LINK_DIRS})
add_definitions(${GLIB2_CFLAGS_OTHER})
aux_source_directory("cglm/src" SOURCES)
add_library(${PROJECT_NAME} STATIC ${SOURCES})
add_compile_options(-Wall -std=gnu99 -O3 -Wstrict-aliasing=2 -fstrict-aliasing -pedantic)
target_include_directories(${PROJECT_NAME} PUBLIC "cglm/include")
target_link_libraries(${PROJECT_NAME} m)

View File

@ -7,16 +7,18 @@
#include <epoxy/gl.h>
#include <epoxy/glx.h>
#include <time.h>
#include <cglm/call.h>
static const char * const vertex_shader = "#version 330 core\n \
layout (location = 0) in vec3 aPos;\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";
@ -29,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 {
@ -206,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[] = {
@ -225,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);
@ -253,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);
@ -345,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());
@ -376,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;