mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Basic shader
This commit is contained in:
29
srcs/RT.cpp
29
srcs/RT.cpp
@ -6,7 +6,7 @@
|
||||
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/27 14:51:49 by TheRed #+# #+# */
|
||||
/* Updated: 2024/10/13 20:58:06 by ycontre ### ########.fr */
|
||||
/* Updated: 2024/10/14 19:54:42 by ycontre ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -20,37 +20,20 @@ int main(void)
|
||||
shader.attach();
|
||||
|
||||
RT::Vec2f vertices[6] = {
|
||||
{ -0.5f, -1.0f }, { 1.0f, -1.0f }, { -1.0f, 1.0f },
|
||||
{ -1.0f, -1.0f }, { 1.0f, -1.0f }, { -1.0f, 1.0f },
|
||||
{ 1.0f, -1.0f }, { 1.0f, 1.0f }, { -1.0f, 1.0f }
|
||||
};
|
||||
|
||||
unsigned int VAO, VBO;
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glGenBuffers(1, &VBO);
|
||||
|
||||
// Bind the VAO
|
||||
glBindVertexArray(VAO);
|
||||
|
||||
// Bind the VBO and upload the vertex data to it
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
|
||||
// Set vertex attributes
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
// Unbind the VBO and VAO
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
shader.setupVertexBuffer(vertices, sizeof(vertices));
|
||||
|
||||
while (!window.shouldClose())
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glUseProgram(shader.getProgram());
|
||||
glBindVertexArray(VAO);
|
||||
shader.setVec2f("u_resolution", RT::Vec2f(WIDTH, HEIGHT));
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glUseProgram(shader.getProgram());
|
||||
shader.drawTriangles();
|
||||
|
||||
window.display();
|
||||
window.pollEvents();
|
||||
|
Reference in New Issue
Block a user