this is way too complicated for what it is doing
This commit is contained in:
Vendored
+2
-1
@@ -1,3 +1,4 @@
|
||||
{
|
||||
"cmake.buildDirectory": "${workspaceFolder}/bin/"
|
||||
"cmake.buildDirectory": "${workspaceFolder}/bin/",
|
||||
"cmake.generator": ""
|
||||
}
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
bin/compile_commands.json
|
||||
+4
-2
@@ -8,12 +8,14 @@ int main()
|
||||
bvh.addModels(ModelLoader::loadModel("../cube.fbx"), glm::mat4());
|
||||
bvh.generate();
|
||||
Window w(1920, 1080);
|
||||
std::vector<uint32_t> texture(1920 * 1080);
|
||||
std::vector<unsigned char> 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)
|
||||
|
||||
+20
-11
@@ -2,7 +2,7 @@
|
||||
#include <assert.h>
|
||||
#include <iostream>
|
||||
|
||||
#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() <<std::endl;
|
||||
std::cout <<glewGetErrorString(1) <<std::endl;
|
||||
assert(!glewInit());
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
std::vector<unsigned char> 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<uint32_t>& textureData)
|
||||
void Window::update(const std::vector<unsigned char>& 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();
|
||||
|
||||
+1
-2
@@ -8,13 +8,12 @@ class Window
|
||||
public:
|
||||
Window(int width, int height);
|
||||
~Window();
|
||||
void update(const std::vector<uint32_t>& textureData);
|
||||
void update(const std::vector<unsigned char>& textureData);
|
||||
|
||||
private:
|
||||
int width;
|
||||
int height;
|
||||
GLuint vao;
|
||||
GLuint vbo;
|
||||
GLuint texture;
|
||||
GLuint program;
|
||||
GLuint vertShader;
|
||||
|
||||
Reference in New Issue
Block a user