I’ve setup cglm from a wrap configured with Meson, and have copied one of many samples from https://github.com/floooh/sokol-samples/tree/grasp (cube-sapp, to be actual). I’ve tried to interchange sokol’s use of HandMadeMath, with cglm; for some cause nevertheless, nothing renders to the display aside from a blue clear shade. Any clue on what is going on on? The principle.c file
#embody // Embody cglm for math features
#embody
#embody "cube-sapp.h"
static struct {
float rx, ry;
sg_pipeline pip;
sg_bindings bind;
} state;
void init(void) {
sg_setup(&(sg_desc){
.surroundings = sglue_environment(),
.logger.func = slog_func,
});
/* dice vertex buffer */
float vertices[] = {
-1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, -1.0, -1.0,
1.0, 0.0, 0.0, 1.0, 1.0, 1.0, -1.0, 1.0, 0.0, 0.0,
1.0, -1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0,
-1.0, -1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, -1.0, 1.0,
0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0,
1.0, -1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
-1.0, -1.0, -1.0, 0.0, 0.0, 1.0, 1.0, -1.0, 1.0, -1.0,
0.0, 0.0, 1.0, 1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 1.0,
1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0,
1.0, -1.0, -1.0, 1.0, 0.5, 0.0, 1.0, 1.0, 1.0, -1.0,
1.0, 0.5, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5, 0.0,
1.0, 1.0, -1.0, 1.0, 1.0, 0.5, 0.0, 1.0,
-1.0, -1.0, -1.0, 0.0, 0.5, 1.0, 1.0, -1.0, -1.0, 1.0,
0.0, 0.5, 1.0, 1.0, 1.0, -1.0, 1.0, 0.0, 0.5, 1.0,
1.0, 1.0, -1.0, -1.0, 0.0, 0.5, 1.0, 1.0,
-1.0, 1.0, -1.0, 1.0, 0.0, 0.5, 1.0, -1.0, 1.0, 1.0,
1.0, 0.0, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.5,
1.0, 1.0, 1.0, -1.0, 1.0, 0.0, 0.5, 1.0};
sg_buffer vbuf = sg_make_buffer(&(sg_buffer_desc){
.information = SG_RANGE(vertices), .label = "cube-vertices"});
/* create an index buffer for the dice */
uint16_t indices[] = {0, 1, 2, 0, 2, 3, 6, 5, 4, 7, 6, 4,
8, 9, 10, 8, 10, 11, 14, 13, 12, 15, 14, 12,
16, 17, 18, 16, 18, 19, 22, 21, 20, 23, 22, 20};
sg_buffer ibuf =
sg_make_buffer(&(sg_buffer_desc){.kind = SG_BUFFERTYPE_INDEXBUFFER,
.information = SG_RANGE(indices),
.label = "cube-indices"});
/* create shader */
sg_shader shd = sg_make_shader(cube_shader_desc(sg_query_backend()));
/* create pipeline object */
state.pip = sg_make_pipeline(&(sg_pipeline_desc){
.structure =
{/* check to supply buffer stride, however no attr offsets */
.buffers[0].stride = 28,
.attrs = {[ATTR_cube_position].format = SG_VERTEXFORMAT_FLOAT3,
[ATTR_cube_color0].format = SG_VERTEXFORMAT_FLOAT4}},
.shader = shd,
.index_type = SG_INDEXTYPE_UINT16,
.cull_mode = SG_CULLMODE_BACK,
.depth =
{
.write_enabled = true,
.evaluate = SG_COMPAREFUNC_LESS_EQUAL,
},
.label = "cube-pipeline"});
/* setup useful resource bindings */
state.bind = (sg_bindings){.vertex_buffers[0] = vbuf, .index_buffer = ibuf};
}
void body(void) {
/* NOTE: the vs_params_t struct has been code-generated by the
* shader-code-gen */
vs_params_t vs_params;
const float w = sapp_widthf();
const float h = sapp_heightf();
const float t = (float)(sapp_frame_duration() * 60.0);
/* Utilizing cglm for matrix operations */
mat4 proj, view, rxm, rym, mannequin;
glm_perspective(glm_rad(60.0f), w / h, 0.01f, 100.0f, proj);
glm_lookat((vec3){0.0f, 1.5f, 6.0f}, (vec3){0.0f, 0.0f, 0.0f},
(vec3){0.0f, 1.0f, 0.0f}, view);
glm_translate(view, (vec3){0.0f, 0.0f, 10.0f});
state.rx += 1.0f * t;
state.ry += 2.0f * t;
glm_rotate(rxm, glm_rad((float)state.rx), (vec3){1.0f, 0.0f, 0.0f});
glm_rotate(rym, glm_rad((float)state.ry), (vec3){0.0f, 1.0f, 0.0f});
glm_mat4_mul(rxm, rym, mannequin);
glm_mat4_mulN((mat4*[]){&proj, &view, &mannequin}, 3, vs_params.mvp);
sg_begin_pass(&(sg_pass){
.motion =
{
.colours[0] = {.load_action = SG_LOADACTION_CLEAR,
.clear_value = {0.25f, 0.5f, 0.75f, 1.0f}},
},
.swapchain = sglue_swapchain()});
sg_apply_pipeline(state.pip);
sg_apply_bindings(&state.bind);
sg_apply_uniforms(UB_vs_params, &SG_RANGE(vs_params));
sg_draw(0, 36, 1);
sg_end_pass();
sg_commit();
}
void cleanup(void) { sg_shutdown(); }
sapp_desc sokol_main(int argc, char* argv[]) {
(void)argc;
(void)argv;
return (sapp_desc){
.init_cb = init,
.frame_cb = body,
.cleanup_cb = cleanup,
.width = 800,
.peak = 600,
.sample_count = 4,
.window_title = "Dice (sokol-app)",
.icon.sokol_default = true,
.logger.func = slog_func,
};
}
The shader (cube-sapp.glsl):
@ctype mat4 mat4
@ctype vec4 vec4
@vs vs
structure(binding=0) uniform vs_params {
mat4 mvp;
};
in vec4 place;
in vec4 color0;
out vec4 shade;
void important() {
gl_Position = mvp * place;
shade = color0;
}
@finish
@fs fs
in vec4 shade;
out vec4 frag_color;
void important() {
frag_color = shade;
}
@finish
@program dice vs fs
TLDR: I attempted changing HandMadeMath features from a sokol instance with cglm, and it did not work.