initial commit

This commit is contained in:
2026-04-29 00:17:00 -04:00
commit 5cc2a5f269
11 changed files with 3878 additions and 0 deletions

28
src/Mesh.cpp Normal file
View File

@@ -0,0 +1,28 @@
//
// Created by slinky on 4/26/26.
//
#include "Mesh.h"
Mesh::Mesh(const std::vector<float> &positions, const std::vector<float> &uvs, const std::vector<float> &normals, const std::vector<int> &indices) {
vao = 0;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
// positions
GLuint positionVbo = 0;
glGenBuffers(1, &positionVbo);
glBindBuffer(GL_ARRAY_BUFFER, positionVbo);
glBufferData(GL_ARRAY_BUFFER, positions.size() * sizeof(float), positions.data(), GL_STATIC_DRAW);
// uvs
GLuint uvVbo = 0;
glGenBuffers(1, &uvVbo);
glBindBuffer(GL_ARRAY_BUFFER, uvVbo);
glBufferData(GL_ARRAY_BUFFER, uvs.size() * sizeof(float), uvs.data(), GL_STATIC_DRAW);
// normals
GLuint normalVbo = 0;
glGenBuffers(1, &normalVbo);
glBindBuffer(GL_ARRAY_BUFFER, normalVbo);
glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(float), normals.data(), GL_STATIC_DRAW);
}

26
src/Mesh.h Normal file
View File

@@ -0,0 +1,26 @@
//
// Created by slinky on 4/26/26.
//
#ifndef B_ENGINE_MESH_H
#define B_ENGINE_MESH_H
#include <vector>
#include "glad/gl.h"
class Mesh {
public:
Mesh() = default;
Mesh(const std::vector<float>& positions,
const std::vector<float>& uvs,
const std::vector<float>& normals,
const std::vector<float>& indices);
void bind();
private:
GLuint vao;
};
#endif //B_ENGINE_MESH_H

80
src/main.cpp Normal file
View File

@@ -0,0 +1,80 @@
#include <iostream>
#include "glad/gl.h"
#include "GLFW/glfw3.h"
#include "spdlog/spdlog.h"
GLFWwindow* gWindow;
int gWindowWidth = 800;
int gWindowHeight = 600;
int glVersionMajor;
int glVersionMinor;
void glfw_error_callback(int error, const char* description);
void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
void glfw_framebuffer_size_callback(GLFWwindow* window, int width, int height);
int main() {
spdlog::info("b_engine start");
if (!glfwInit()) {
spdlog::error("could not initialize glfw");
std::exit(1);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwSetErrorCallback(glfw_error_callback);
gWindow = glfwCreateWindow(gWindowWidth, gWindowHeight, "b_engine v0.0.1", nullptr, nullptr);
if (!gWindow) {
spdlog::error("failed to create glfw window");
std::exit(1);
}
glfwMakeContextCurrent(gWindow);
glfwSetKeyCallback(gWindow, glfw_key_callback);
glfwSetFramebufferSizeCallback(gWindow, glfw_framebuffer_size_callback);
int version = gladLoadGL(glfwGetProcAddress);
glVersionMajor = GLAD_VERSION_MAJOR(version);
glVersionMinor = GLAD_VERSION_MINOR(version);
spdlog::info("gl version {}.{}", glVersionMajor, glVersionMinor);
int fbWidth, fbHeight;
glfwGetFramebufferSize(gWindow, &fbWidth, &fbHeight);
glViewport(0, 0, fbWidth, fbHeight);
while (!glfwWindowShouldClose(gWindow)) {
glfwPollEvents();
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(gWindow);
}
glfwDestroyWindow(gWindow);
glfwTerminate();
return 0;
}
void glfw_error_callback(int error, const char* description) {
spdlog::error("glfw error: {}", description);
}
void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
glfwSetWindowShouldClose(window, GL_TRUE);
}
}
void glfw_framebuffer_size_callback(GLFWwindow *window, int width, int height) {
glViewport(0, 0, width, height);
}