summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp77
1 files changed, 40 insertions, 37 deletions
diff --git a/main.cpp b/main.cpp
index 2d4ecce..f281df8 100644
--- a/main.cpp
+++ b/main.cpp
@@ -5,8 +5,9 @@
#include <stb_image.h>
#include <shader.h>
-#include "Canvas.h"
+#include "Canvas/Canvas.h"
#include "point.h"
+#include "Canvas/cuda/CalculateCanvasGPU.h"
#include <iostream>
#include <cmath>
@@ -17,15 +18,17 @@ void processInput(GLFWwindow *window);
void loadTexture(std::string path, unsigned int* texture, int* width, int* height);
void generateCanvasTexture(unsigned int *texture, unsigned char color);
+void window_size_callback(GLFWwindow* window, int width, int height);
// settings
-const unsigned int SCR_WIDTH = 800;
-const unsigned int SCR_HEIGHT = 600;
-const std::string PROJECT_PATH = "/home/saintruler/CLionProjects/opengltest/";
+unsigned int SCR_WIDTH = 768;
+unsigned int SCR_HEIGHT = 768;
+const std::string PROJECT_PATH = "/home/saintruler/Documents/opengl_gravity/";
unsigned char* canvas = (unsigned char*) malloc(SCR_HEIGHT * SCR_WIDTH * 3);
std::vector<point> points;
const double c = 1e5;
+cuda_point* gpuPoints = (cuda_point*) malloc(3 * sizeof(cuda_point));
int main()
{
@@ -62,13 +65,6 @@ int main()
// set up vertex data (and buffer(s)) and configure vertex attributes
// ------------------------------------------------------------------
- float vertices1[] = {
- // positions // colors // texture coords
- 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right
- 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right
- -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom left
- -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f // top left
- };
float vertices[] = {
// positions // colors // texture coords
@@ -115,6 +111,10 @@ int main()
points.emplace_back(point(500, 500));
points.emplace_back(point(200, 375));
+ gpuPoints[0] = cuda_point{.x=100, .y=100};
+ gpuPoints[1] = cuda_point{.x=500, .y=500};
+ gpuPoints[2] = cuda_point{.x=200, .y=200};
+
// render loop
// -----------
@@ -196,29 +196,31 @@ void generateCanvasTexture(unsigned int *texture, unsigned char color)
// load image, create texture and generate mipmaps
- for (int x = 0; x < SCR_WIDTH; x++)
- {
- for (int y = 0; y < SCR_HEIGHT; y++)
- {
-
- point canvas_pt(x, y);
- double f = 0;
- for (point pt : points)
- {
- point path = pt - canvas_pt;
-
- f += (c * 20 * 1) / path.length_sqared();
- }
-
- int l = (int) f;
- if (l > 255) l = 255;
-
-
- canvas[y * SCR_WIDTH * 3 + x * 3 + 0] = l;
- canvas[y * SCR_WIDTH * 3 + x * 3 + 1] = 0;
- canvas[y * SCR_WIDTH * 3 + x * 3 + 2] = 0;
- }
- }
+// for (int x = 0; x < SCR_WIDTH; x++)
+// {
+// for (int y = 0; y < SCR_HEIGHT; y++)
+// {
+//
+// point canvas_pt(x, y);
+// double f = 0;
+// for (point pt : points)
+// {
+// point path = pt - canvas_pt;
+//
+// f += (c * 20 * 1) / path.length_sqared();
+// }
+//
+// int l = (int) f;
+// if (l > 255) l = 255;
+//
+//
+// canvas[y * SCR_WIDTH * 3 + x * 3 + 0] = l;
+// canvas[y * SCR_WIDTH * 3 + x * 3 + 1] = 0;
+// canvas[y * SCR_WIDTH * 3 + x * 3 + 2] = 0;
+// }
+// }
+
+ generate_canvas(SCR_WIDTH, SCR_HEIGHT, canvas, gpuPoints, 3);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, SCR_WIDTH, SCR_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, (unsigned char*) canvas);
glGenerateMipmap(GL_TEXTURE_2D);
@@ -245,8 +247,10 @@ void processInput(GLFWwindow *window)
double xpos, ypos;
//getting cursor position
glfwGetCursorPos(window, &xpos, &ypos);
- points[0].x = xpos;
- points[0].y = SCR_HEIGHT - ypos;
+// points[0].x = xpos;
+// points[0].y = SCR_HEIGHT - ypos;
+ gpuPoints[0].x = xpos;
+ gpuPoints[0].y = SCR_HEIGHT - ypos;
}
// glfw: whenever the window size changed (by OS or user resize) this callback function executes
@@ -257,4 +261,3 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
// height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height);
}
-