Add zoom to texture and a gray border around square
This commit is contained in:
parent
8e66150aae
commit
bb4140b819
32
src/main.c
32
src/main.c
@ -14,10 +14,11 @@ static const char * const vertex_shader = "#version 330 core\n \
|
|||||||
layout (location = 1) in vec2 aTexCoord;\n\
|
layout (location = 1) in vec2 aTexCoord;\n\
|
||||||
out vec2 texCoord;\n\
|
out vec2 texCoord;\n\
|
||||||
out vec3 vertPos;\n \
|
out vec3 vertPos;\n \
|
||||||
|
uniform float zoom;\n\
|
||||||
void main()\n \
|
void main()\n \
|
||||||
{\n \
|
{\n \
|
||||||
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n \
|
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n \
|
||||||
texCoord = aTexCoord;\n\
|
texCoord = aTexCoord / zoom;\n\
|
||||||
vertPos = aPos;\n\
|
vertPos = aPos;\n\
|
||||||
}\n";
|
}\n";
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ static const char * const orange_framgment_shader = " \
|
|||||||
\n \
|
\n \
|
||||||
void main()\n \
|
void main()\n \
|
||||||
{\n \
|
{\n \
|
||||||
FragColor = texture(ourTexture, texCoord); //+ vec4(vertPos.x, -vertPos.x, vertPos.y, 0.0);\n \
|
FragColor = texture(ourTexture, texCoord);\n\
|
||||||
}";
|
}";
|
||||||
|
|
||||||
struct canvas_buffer {
|
struct canvas_buffer {
|
||||||
@ -207,10 +208,10 @@ static int calculate_mandelbrot(struct canvas_buffer *buff)
|
|||||||
|
|
||||||
float vertices[] = {
|
float vertices[] = {
|
||||||
// Vertex Texture
|
// Vertex Texture
|
||||||
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, // bottom left
|
-0.95f, -0.95f, 0.0f, 0.0f, 0.0f, // bottom left
|
||||||
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f, // top left
|
-0.95f, 0.95f, 0.0f, 0.0f, 1.0f, // top left
|
||||||
1.0f, -1.0f, 0.0f, 1.0f, 0.0f, // bottom right
|
0.95f, -0.95f, 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, 1.0f, 1.0f, // top right
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int indices[] = {
|
unsigned int indices[] = {
|
||||||
@ -226,13 +227,17 @@ static unsigned int texture_id;
|
|||||||
|
|
||||||
gboolean render(GtkGLArea *gl_area, GdkGLContext *context, gpointer user_data)
|
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);
|
gtk_gl_area_make_current(gl_area);
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
glUseProgram(shader_program_id);
|
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);
|
glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||||
glBindVertexArray(vertex_array_object);
|
glBindVertexArray(vertex_array_object);
|
||||||
//glDrawArrays(GL_TRIANGLES, 0, 3);
|
//glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||||
@ -254,7 +259,7 @@ void realize(GtkGLArea *gl_area, gpointer user_data)
|
|||||||
char info_log[512];
|
char info_log[512];
|
||||||
|
|
||||||
gtk_gl_area_make_current(gl_area);
|
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);
|
glGenVertexArrays(1, &vertex_array_object);
|
||||||
glBindVertexArray(vertex_array_object);
|
glBindVertexArray(vertex_array_object);
|
||||||
@ -346,13 +351,13 @@ int main(int argc, char **argv)
|
|||||||
g_signal_connect(window, "delete-event", G_CALLBACK(on_main_window_close), NULL);
|
g_signal_connect(window, "delete-event", G_CALLBACK(on_main_window_close), NULL);
|
||||||
|
|
||||||
|
|
||||||
mandelbrot_buff.x_span = 0.05;//2.8;
|
mandelbrot_buff.x_span = 0.1;//2.8;
|
||||||
mandelbrot_buff.y_span = 0.05;//2.25;
|
mandelbrot_buff.y_span = 0.1;//2.25;
|
||||||
mandelbrot_buff.center_x = -0.6;
|
mandelbrot_buff.center_x = -0.6;
|
||||||
mandelbrot_buff.center_y = 0.44;
|
mandelbrot_buff.center_y = 0.44;
|
||||||
mandelbrot_buff.width = 5000;
|
mandelbrot_buff.width = 4000;
|
||||||
mandelbrot_buff.height = 5000;
|
mandelbrot_buff.height = 4000;
|
||||||
mandelbrot_buff.iterations = 600;
|
mandelbrot_buff.iterations = 1000;
|
||||||
mandelbrot_buff.mandelbrot_buffer = NULL;
|
mandelbrot_buff.mandelbrot_buffer = NULL;
|
||||||
|
|
||||||
printf("Compile and run Mandelbrot on OpenCL HW\n");
|
printf("Compile and run Mandelbrot on OpenCL HW\n");
|
||||||
@ -377,7 +382,6 @@ int main(int argc, char **argv)
|
|||||||
gtk_gl_area_make_current(gl_area);
|
gtk_gl_area_make_current(gl_area);
|
||||||
|
|
||||||
printf("Gui will be displayed\n");
|
printf("Gui will be displayed\n");
|
||||||
|
|
||||||
gtk_main();
|
gtk_main();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user