proyecto-carga-electrica/main/main.c
2025-10-30 23:34:17 -06:00

102 lines
2.5 KiB
C

#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <cglm/cglm.h>
#define SKR_BACKEND_API 0 // opengl
#define SKR_BACKEND_WINDOW 0 // glfw
#include <skr/skr.h>
int main(void) {
SkrState state = SkrInit(
&(SkrWindow){
.Title = "Hello SKR",
.Width = 800,
.Height = 600,
},
SKR_BACKEND_API_GL);
glewInit();
// SkrTriangle(&state);
#include <main/shaders/texture.frag.c>
#include <main/shaders/texture.vert.c>
SkrShader shaders[] = {
{GL_VERTEX_SHADER, texture_vert, NULL},
{GL_FRAGMENT_SHADER, texture_frag, NULL},
};
GLuint prog =
m_skr_gl_create_program_from_shaders(shaders, sizeof(shaders));
static SkrShaderProgram program = {.Backend.GL.ID = 0};
program.Backend.GL.ID = prog;
static SkrVertex vertices[] = {
{.Position = {0.5f, 0.5f, 0.0f},
.Normal = {0.0f, 0.0f, 1.0f},
.UV = {1.0f, 1.0f},
.Color = {1.0f, 0.0f, 0.0f}},
{.Position = {0.5f, -0.5f, 0.0f},
.Normal = {0.0f, 0.0f, 1.0f},
.UV = {1.0f, 0.0f},
.Color = {0.0f, 1.0f, 0.0f}},
{.Position = {-0.5f, -0.5f, 0.0f},
.Normal = {0.0f, 0.0f, 1.0f},
.UV = {0.0f, 0.0f},
.Color = {0.0f, 0.0f, 1.0f}},
{.Position = {-0.5f, 0.5f, 0.0f},
.Normal = {0.0f, 0.0f, 1.0f},
.UV = {0.0f, 1.0f},
.Color = {1.0f, 1.0f, 0.0f}},
};
static unsigned int indices[] = {0, 1, 3, 1, 2, 3};
// Make mesh
static SkrMesh mesh = {
.Vertices = vertices,
.VertexCount = 4,
.Indices = indices,
.IndexCount = 6,
.Program = &program,
};
// Make model
static SkrModel model = {
.Meshes = &mesh,
.MeshCount = 1,
};
const char* paths[] = {"assets/container.jpg",
"assets/awesomeface.png"};
unsigned int tex_ids[2];
m_skr_gl_load_textures_2d_from_paths(paths, tex_ids, 2);
static SkrTexture textures[2] = {0};
for (int i = 0; i < 2; i++) {
textures[i].Backend.GL.ID = tex_ids[i];
textures[i].Type =
(i == 0) ? SKR_TEXTURE_DIFFUSE : SKR_TEXTURE_SPECULAR;
}
model.Textures = textures;
model.TextureCount = 2;
state.Models = &model;
state.ModelCount = 1;
glUseProgram(prog);
m_skr_gl_shader_set_int(prog, "texture1", 0);
m_skr_gl_shader_set_int(prog, "texture2", 1);
while (!SkrShouldClose(&state)) {
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
SkrRendererRender(&state);
}
return 0;
}