add shader stuff

This commit is contained in:
CJSatnarine
2025-02-15 12:19:40 -05:00
parent 6ea22726b0
commit 3f40ad4003
3 changed files with 62 additions and 11 deletions

View File

@@ -3,6 +3,9 @@
* window in OpenGL.
*/
#include "classes/ElementBufferObject.h"
#include "classes/VertexArrayObject.h"
#include "classes/VertexBufferObject.h"
#include "glad/glad.h"
#include "GLFW/glfw3.h"
#include "classes/Classes.h"
@@ -15,6 +18,18 @@ void processInput(GLFWwindow *window);
const unsigned int WINDOW_WIDTH = 800;
const unsigned int WINDOW_HEIGHT = 600;
float vertices[] = {
1.0f, 1.0f, 0.0f, // top right
1.0f, -1.0f, 0.0f, // bottom right
-1.0f, -1.0f, 0.0f, // bottom left
-1.0f, 1.0f, 0.0f // top left
};
unsigned int indices[] = {
0, 1, 3, // first Triangle
1, 2, 3 // second Triangle
};
int main(void) {
// Initialisation and configuration.
glfwInit();
@@ -23,7 +38,8 @@ int main(void) {
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Create window.
GLFWwindow *window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Learn Shaders", NULL, NULL);
GLFWwindow *window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT,
"Learn Shaders", NULL, NULL);
if (window == NULL) {
LogInfo("Failed to create GLFW window.");
glfwTerminate();
@@ -37,17 +53,38 @@ int main(void) {
return -1;
}
// Shader stuff.
Shader shader("../src/shaders/vertexShader.vert.glsl", "../src/shaders/fragmentShader.frag.glsl");
VertexArrayObject VAO;
VAO.Bind();
VertexBufferObject VBO(vertices, sizeof(vertices));
VBO.Bind();
ElementBufferObject EBO(indices, sizeof(indices));
EBO.Bind();
VAO.LinkVBO(VBO, 0);
// while loop goes here.
while (!glfwWindowShouldClose(window)) {
processInput(window);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
shader.Activate();
VAO.Bind();
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glfwSwapBuffers(window);
glfwPollEvents();
}
VAO.Delete();
VBO.Delete();
EBO.Delete();
shader.Delete();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}

View File

@@ -0,0 +1,7 @@
#version 330 core
out vec4 FragColour;
void main() {
FragColour = vec4(1.0f, 0.0f, 1.0f, 1.0f);
}

View File

@@ -0,0 +1,7 @@
#version 330 core
layout(location = 0) in vec3 aPos;
void main() {
gl_Position = vec4(aPos, 1.0);
}