drawing should be working
This commit is contained in:
+9
-26
@@ -13,26 +13,9 @@ 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
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL
|
||||||
window = glfwCreateWindow(width, height, "RayTracer", nullptr, nullptr);
|
window = glfwCreateWindow(width, height, "RayTracer", nullptr, nullptr);
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
float vertices[] = {
|
|
||||||
// positions
|
|
||||||
1, -1, 0,
|
|
||||||
-1, -1, 0,
|
|
||||||
1, 1, 0,
|
|
||||||
1, -1, 0
|
|
||||||
};
|
|
||||||
|
|
||||||
glGenVertexArrays(1, &vao);
|
|
||||||
glGenBuffers(1, &vbo);
|
|
||||||
// bind the Vertex Array Object first, then bind and set vertex buffer(s), and then configure vertex attributes(s).
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
// position attribute
|
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
assert(!glewInit());
|
assert(!glewInit());
|
||||||
|
glGenVertexArrays(1, &vao);
|
||||||
|
glBindVertexArray(vao);
|
||||||
glGenTextures(1, &texture);
|
glGenTextures(1, &texture);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||||
@@ -40,13 +23,13 @@ Window::Window(int width, int height) : width(width), height(height)
|
|||||||
vertShader = glCreateShader(GL_VERTEX_SHADER);
|
vertShader = glCreateShader(GL_VERTEX_SHADER);
|
||||||
fragShader = glCreateShader(GL_FRAGMENT_SHADER);
|
fragShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
int logLen = 0;
|
int logLen = 0;
|
||||||
const char* vertCode = GLSL(layout(location = 0) in vec3 position
|
const char* vertCode =
|
||||||
layout(location = 0) out vec2 outUV;
|
GLSL(layout(location = 0)out vec2 texcoords; // texcoords are in the normalized [0,1] range for the viewport-filling quad part of the triangle
|
||||||
|
void main() {
|
||||||
void main() {
|
vec2 vertices[3] = vec2[3](vec2(-1, -1), vec2(3, -1), vec2(-1, 3));
|
||||||
outUV = vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2);
|
gl_Position = vec4(vertices[gl_VertexID], 0, 1);
|
||||||
gl_Position = vec4(outUV * 2.0f + -1.0f, 0.0f, 1.0f);
|
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(layout(location = 0) in vec2 uv; layout(location = 0) out vec4 color;
|
||||||
|
|
||||||
uniform sampler2D tex;
|
uniform sampler2D tex;
|
||||||
|
|||||||
Reference in New Issue
Block a user