+ | First sphere

This commit is contained in:
TheRedShip
2024-10-14 23:16:28 +02:00
parent 163828707a
commit 9d7a30800e
10 changed files with 239 additions and 110 deletions

View File

@ -14,8 +14,8 @@
int main(void)
{
Window window;
Shader shader("shaders/vertex.glsl", "shaders/frag.glsl");
Window window(WIDTH, HEIGHT, "RT_GPU", 1);
Shader shader("shaders/vertex.vert", "shaders/frag.frag");
shader.attach();
@ -23,8 +23,9 @@ int main(void)
{ -1.0f, -1.0f }, { 1.0f, -1.0f }, { -1.0f, 1.0f },
{ 1.0f, -1.0f }, { 1.0f, 1.0f }, { -1.0f, 1.0f }
};
size_t size = sizeof(vertices) / sizeof(RT::Vec2f) / 3;
shader.setupVertexBuffer(vertices, sizeof(vertices));
shader.setupVertexBuffer(vertices, size);
while (!window.shouldClose())
{
@ -33,7 +34,7 @@ int main(void)
shader.setVec2f("u_resolution", RT::Vec2f(WIDTH, HEIGHT));
glUseProgram(shader.getProgram());
shader.drawTriangles();
shader.drawTriangles(size);
window.display();
window.pollEvents();

View File

@ -110,7 +110,7 @@ void Shader::setupVertexBuffer(const RT::Vec2f* vertices, size_t size)
glBindVertexArray(_screen_VAO);
glBindBuffer(GL_ARRAY_BUFFER, _screen_VBO);
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, size * 3 * sizeof(RT::Vec2f), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
@ -119,10 +119,10 @@ void Shader::setupVertexBuffer(const RT::Vec2f* vertices, size_t size)
glBindVertexArray(0);
}
void Shader::drawTriangles(void)
void Shader::drawTriangles(size_t size)
{
glBindVertexArray(_screen_VAO);
glDrawArrays(GL_TRIANGLES, 0, 6);
glDrawArrays(GL_TRIANGLES, 0, size * 3);
}

View File

@ -12,7 +12,7 @@
#include "Window.hpp"
Window::Window(void)
Window::Window(int width, int height, const char *title, int sleep)
{
if (!glfwInit())
{
@ -24,8 +24,8 @@ Window::Window(void)
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
_window = glfwCreateWindow(WIDTH, HEIGHT, "RT_GPU", NULL, NULL);
if (!_window )
_window = glfwCreateWindow(width, height, title, NULL, NULL);
if (!_window)
{
fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
glfwTerminate();
@ -40,7 +40,7 @@ Window::Window(void)
glfwSetMouseButtonCallback(_window, mouseButtonCallback);
gladLoadGL(glfwGetProcAddress);
glfwSwapInterval(1);
glfwSwapInterval(sleep);
}
Window::Window(Window const &src)
{