Added own shaders

This commit is contained in:
2026-04-13 00:51:32 +02:00
parent c964fcc984
commit 64b27a6b84
9 changed files with 219 additions and 10 deletions

19
include/Shader.hpp Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include <string>
#include <GL/glew.h>
#include "defines.hpp"
struct Shader {
Shader(const char* vertexShaderFileName, const char* fragmentShaderFileName);
virtual ~Shader();
void bind();
void unbind();
private:
GLuint compile(std::string shaderSource, GLenum shaderType);
std::string parse(const char* filename);
GLuint createShader(const char* vertexShaderFileName, const char* fragmentShaderFileName);
GLuint shaderId;
};

34
include/VertexBuffer.hpp Normal file
View File

@@ -0,0 +1,34 @@
#pragma once
#include <GL/glew.h>
#include "defines.hpp"
struct VertexBuffer {
VertexBuffer(void* data, uint32 numVertices) {
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &bufferId);
glBindBuffer(GL_ARRAY_BUFFER, bufferId);
glBufferData(GL_ARRAY_BUFFER, numVertices*sizeof(Vertex), data, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), offsetof(struct Vertex,x));
glBindVertexArray(0);
};
virtual ~VertexBuffer() {
glDeleteBuffers(1, &bufferId);
}
void bind() {
glBindVertexArray(vao);
}
void unbind() {
glBindVertexArray(0);
}
private:
GLuint bufferId;
GLuint vao;
};

19
include/defines.hpp Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include <cstdint>
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef int64_t int64;
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
typedef float float32;
typedef double float64;
struct Vertex {
float32 x, y, z;
};