Eu configurei o cglm a partir de um wrap configurado com Meson e copiei uma das amostras de https://github.com/floooh/sokol-samples/tree/grasp (cubo-sapp, para ser exato). Tentei substituir o uso do HandMadeMath pelo sokol por cglm; por alguma razão, entretanto, nada é renderizado na tela além de uma cor azul clara. Alguma pista do que está acontecendo? O arquivo major.c
#embrace // Embody cglm for math capabilities
#embrace
#embrace "cube-sapp.h"
static struct {
float rx, ry;
sg_pipeline pip;
sg_bindings bind;
} state;
void init(void) {
sg_setup(&(sg_desc){
.setting = 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){.sort = 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,
};
}
O sombreador (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 coloration;
void major() {
gl_Position = mvp * place;
coloration = color0;
}
@finish
@fs fs
in vec4 coloration;
out vec4 frag_color;
void major() {
frag_color = coloration;
}
@finish
@program dice vs fs
TLDR: Tentei substituir as funções HandMadeMath de um exemplo sokol por cglm e não funcionou.