sent from android
This commit is contained in:
45
include/geometry.hpp
Normal file
45
include/geometry.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef GEOMETRY_HPP
|
||||
#define GEOMETRY_HPP
|
||||
|
||||
// Includes
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include "graphics.hpp"
|
||||
|
||||
// Object class
|
||||
class Object {
|
||||
public:
|
||||
Object(
|
||||
float *vertices, unsigned int vertex_size,
|
||||
unsigned int *indices, unsigned int index_size,
|
||||
float *normals = nullptr, unsigned int normal_size = 0,
|
||||
float *texcoords = nullptr, unsigned int texcoord_size = 0
|
||||
);
|
||||
~Object();
|
||||
void draw();
|
||||
|
||||
private:
|
||||
unsigned int VAO, VBO, EBO, NBO, TBO; // Vertex Array Object, Vertex Buffer Object, Element Buffer Object, Normal Buffer Object, Texture Buffer Object
|
||||
unsigned int vertex_count;
|
||||
unsigned int index_count;
|
||||
};
|
||||
|
||||
class UntexturedObject {
|
||||
public:
|
||||
UntexturedObject(
|
||||
float *vertices, unsigned int vertex_size,
|
||||
unsigned int *indices, unsigned int index_size,
|
||||
float *normals = nullptr, unsigned int normal_size = 0,
|
||||
float *texcoords = nullptr, unsigned int texcoord_size = 0
|
||||
);
|
||||
~UntexturedObject();
|
||||
void draw();
|
||||
|
||||
private:
|
||||
unsigned int VAO, VBO, EBO, NBO, TBO; // Vertex Array Object, Vertex Buffer Object, Element Buffer Object, Normal Buffer Object, Texture Buffer Object
|
||||
unsigned int vertex_count;
|
||||
unsigned int index_count;
|
||||
};
|
||||
|
||||
#endif
|
@@ -3,11 +3,11 @@
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
// Includes
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl3.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include <SDL3/SDL_opengl.h>
|
||||
#include "window.hpp"
|
||||
#include "shader.hpp"
|
||||
#include "texture.hpp"
|
||||
#include <iostream>
|
||||
|
||||
// Constants
|
||||
const int open_gl_major_version = 3;
|
||||
@@ -21,25 +21,13 @@ extern float frame_time;
|
||||
extern float fps;
|
||||
extern float frame_time_graph[100];
|
||||
extern SDL_GLContext gl_context;
|
||||
|
||||
extern ImGuiIO& io;
|
||||
extern ImGuiStyle& style;
|
||||
#define delta_time frame_time
|
||||
|
||||
// Functions
|
||||
int initialize_opengl();
|
||||
void cleanup_opengl();
|
||||
|
||||
// ImGui
|
||||
int initialize_imgui();
|
||||
void cleanup_imgui();
|
||||
void new_frame_imgui();
|
||||
void frame_time_ui();
|
||||
|
||||
// Frame time calculation
|
||||
void calc_frame_time();
|
||||
|
||||
// Shader management
|
||||
unsigned int compile_shader(const char* shader_source, GLenum shader_type);
|
||||
unsigned int create_program(unsigned int vertex_shader, unsigned int fragment_shader);
|
||||
|
||||
#endif
|
23
include/gui.hpp
Normal file
23
include/gui.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef GUI_HPP
|
||||
#define GUI_HPP
|
||||
|
||||
// Includes
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl3.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
#include "window.hpp"
|
||||
#include "graphics.hpp"
|
||||
#include <iostream>
|
||||
|
||||
// Variables
|
||||
extern ImGuiIO& io;
|
||||
extern ImGuiStyle& style;
|
||||
extern
|
||||
|
||||
// Functions
|
||||
int initialize_imgui();
|
||||
void cleanup_imgui();
|
||||
void new_frame_imgui();
|
||||
void frame_time_ui();
|
||||
|
||||
#endif
|
23
include/loader.hpp
Normal file
23
include/loader.hpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef LOADER_HPP
|
||||
#define LOADER_HPP
|
||||
|
||||
// Includes
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
// Obj struct
|
||||
struct Obj {
|
||||
float* vertices; // Pointer to vertex data
|
||||
size_t vertex_count; // Number of vertices
|
||||
float* normals; // Pointer to normal data
|
||||
size_t normal_count; // Number of normals
|
||||
float* texcoords; // Pointer to texture coordinate data
|
||||
size_t texcoord_count; // Number of texture coordinates
|
||||
unsigned int* indices; // Pointer to index data
|
||||
size_t index_count; // Number of indices
|
||||
};
|
||||
|
||||
// Function to load an OBJ file
|
||||
Obj load_obj(const std::string& filename);
|
||||
|
||||
#endif // LOADER_HPP
|
@@ -6,11 +6,17 @@
|
||||
#include "window.hpp"
|
||||
#include "graphics.hpp"
|
||||
#include "utils.hpp"
|
||||
#include "gui.hpp"
|
||||
#include "geometry.hpp"
|
||||
#include "loader.hpp"
|
||||
|
||||
// Variables
|
||||
extern bool running;
|
||||
|
||||
// Functions
|
||||
int main(int argc, char* argv[]);
|
||||
void init(); // Initialize SDL, OpenGL, and ImGui
|
||||
void handle_events(); // Handle SDL events
|
||||
void handle_keyboard_input(); // Handle keyboard input for camera movement
|
||||
|
||||
#endif
|
24
include/shader.hpp
Normal file
24
include/shader.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef SHADER_HPP
|
||||
#define SHADER_HPP
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
// Includes
|
||||
#include "utils.hpp"
|
||||
#include <iostream>
|
||||
#include <SDL3/SDL_opengl.h>
|
||||
#include "geometry.hpp"
|
||||
|
||||
// Shader class
|
||||
class Shader {
|
||||
public:
|
||||
unsigned int ID;
|
||||
Shader(const char* vertexPath, const char* fragmentPath);
|
||||
void use() const;
|
||||
void setBool(const std::string &name, bool value) const;
|
||||
void setInt(const std::string &name, int value) const;
|
||||
void setFloat(const std::string &name, float value) const;
|
||||
void setMat4(const std::string &name, const glm::mat4 &mat) const;
|
||||
~Shader();
|
||||
};
|
||||
|
||||
#endif
|
24
include/texture.hpp
Normal file
24
include/texture.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef TEXTURE_HPP
|
||||
#define TEXTURE_HPP
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
// Includes
|
||||
#include <SDL3_image/SDL_image.h>
|
||||
#include <SDL3/SDL_opengl.h>
|
||||
#include <iostream>
|
||||
|
||||
// Functions
|
||||
void flip_surface(SDL_Surface* surface);
|
||||
|
||||
// Classes
|
||||
class Texture {
|
||||
public:
|
||||
unsigned int ID;
|
||||
Texture(const char* file_path);
|
||||
~Texture();
|
||||
void bind() const;
|
||||
void bind(unsigned int unit) const;
|
||||
void unbind() const;
|
||||
};
|
||||
|
||||
#endif
|
@@ -2,18 +2,16 @@
|
||||
#define WINDOW_HPP
|
||||
|
||||
// Includes
|
||||
#include "iostream"
|
||||
#include <iostream>
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
// Constants
|
||||
const int window_width = 800;
|
||||
const int window_height = 600;
|
||||
|
||||
// Variables
|
||||
const SDL_WindowFlags window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY;
|
||||
extern float main_scale;
|
||||
extern SDL_Window* window;
|
||||
extern SDL_Event event;
|
||||
extern int window_width;
|
||||
extern int window_height;
|
||||
|
||||
// Functions
|
||||
int initialize_sdl();
|
||||
|
Reference in New Issue
Block a user