diff --git a/.vscode/settings.json b/.vscode/settings.json index 66005ff..88ffd3c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "cmake.buildDirectory": "${workspaceFolder}/bin/" + "cmake.buildDirectory": "${workspaceFolder}/bin/", + "cmake.generator": "" } \ No newline at end of file diff --git a/compile_commands.json b/compile_commands.json new file mode 120000 index 0000000..b8bca52 --- /dev/null +++ b/compile_commands.json @@ -0,0 +1 @@ +bin/compile_commands.json \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 1075c7c..02e2172 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,12 +8,14 @@ int main() bvh.addModels(ModelLoader::loadModel("../cube.fbx"), glm::mat4()); bvh.generate(); Window w(1920, 1080); - std::vector texture(1920 * 1080); + std::vector texture(1920 * 1080 * 3); for (int j = 10; j < 100; ++j) { for (int i = 0; i < 1920; ++i) { - texture[j * 1920 + i] = 0xff00ffff; + texture[(j * 1920 + i) * 3] = 0xff; + texture[(j * 1920 + i) * 3 + 1] = 0xff; + texture[(j * 1920 + i) * 3 + 2] = 0x0; } } while (true) diff --git a/src/window/Window.cpp b/src/window/Window.cpp index 7a3daf6..529bc11 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -2,7 +2,7 @@ #include #include -#define GLSL(...) "#version 450\n#extension GL_KHR_vulkan_glsl : enable\n" #__VA_ARGS__ +#define GLSL(...) "#version 400\n" #__VA_ARGS__ Window::Window(int width, int height) : width(width), height(height) { @@ -13,29 +13,39 @@ Window::Window(int width, int height) : width(width), height(height) glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL window = glfwCreateWindow(width, height, "RayTracer", nullptr, nullptr); glfwMakeContextCurrent(window); - std::cout << glewInit() < texture(1920 * 1080 * 4); + for (int j = 0; j < 1080; ++j) + { + for (int i = 0; i < 1920; ++i) + { + texture[(j * 1920 + i) * 3] = 0xff; + texture[(j * 1920 + i) * 3 + 1] = 0xff; + texture[(j * 1920 + i) * 3 + 2] = 0x0; + texture[(j * 1920 + i) * 3 + 2] = 0xff; + } + } + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture.data()); program = glCreateProgram(); vertShader = glCreateShader(GL_VERTEX_SHADER); fragShader = glCreateShader(GL_FRAGMENT_SHADER); int logLen = 0; const char* vertCode = - GLSL(layout(location = 0)out vec2 texcoords; // texcoords are in the normalized [0,1] range for the viewport-filling quad part of the triangle + GLSL(out vec2 texcoords; // texcoords are in the normalized [0,1] range for the viewport-filling quad part of the triangle void main() { vec2 vertices[3] = vec2[3](vec2(-1, -1), vec2(3, -1), vec2(-1, 3)); gl_Position = vec4(vertices[gl_VertexID], 0, 1); texcoords = 0.5 * gl_Position.xy + vec2(0.5); }); - const char* fragCode = GLSL(layout(location = 0) in vec2 uv; layout(location = 0) out vec4 color; + const char* fragCode = GLSL(in vec2 texcoords; out vec4 color; uniform sampler2D tex; - void main() { color = texture(tex, uv); }); + void main() { color = texture(tex, texcoords); }); glShaderSource(vertShader, 1, &vertCode, nullptr); glCompileShader(vertShader); int success; @@ -71,18 +81,17 @@ Window::Window(int width, int height) : width(width), height(height) } glDeleteShader(vertShader); glDeleteShader(fragShader); - textureLocation = glGetUniformLocation(program, "tex"); glClearColor(0, 0, 0, 0); } Window::~Window() {} -void Window::update(const std::vector& textureData) +void Window::update(const std::vector& textureData) { glClear(GL_COLOR_BUFFER_BIT); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, textureData.data()); + glBindTexture(GL_TEXTURE_2D, texture); + //glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, textureData.data()); glUseProgram(program); - glUniform1i(textureLocation, 0); glDrawArrays(GL_TRIANGLES, 0, 3); glfwSwapBuffers(window); glfwPollEvents(); diff --git a/src/window/Window.h b/src/window/Window.h index 132a5b1..4eed59d 100644 --- a/src/window/Window.h +++ b/src/window/Window.h @@ -8,13 +8,12 @@ class Window public: Window(int width, int height); ~Window(); - void update(const std::vector& textureData); + void update(const std::vector& textureData); private: int width; int height; GLuint vao; - GLuint vbo; GLuint texture; GLuint program; GLuint vertShader;