71 lines
2.5 KiB
C
71 lines
2.5 KiB
C
|
|
#include "../Common/def.h"
|
|
#include "../Common/gem.h"
|
|
#include <stdint.h>
|
|
|
|
#if COM_DEF_TARGET == COM_DEF_TARGET_WASM
|
|
uint8_t plr_draw_buffer[640 * 480 * 4];
|
|
|
|
__attribute__((export_name("plr_draw_get_pixel_buffer"))) uint8_t *
|
|
plr_draw_get_pixel_buffer(void) {
|
|
return plr_draw_buffer;
|
|
}
|
|
#endif
|
|
|
|
__attribute__((export_name("plr_draw_screen"))) void
|
|
plr_draw_screen(uint8_t *pixel_buffer) {
|
|
for (int y = 0; y < 480; y++) {
|
|
for (int x = 0; x < 640; x++) {
|
|
int pixel_index = (y * 640 + x) * 4;
|
|
|
|
// Assuming standard Little-Endian 32-bit BGRA format
|
|
pixel_buffer[pixel_index + 0] = (x) % 256; // Blue
|
|
pixel_buffer[pixel_index + 1] = (y) % 256; // Green
|
|
pixel_buffer[pixel_index + 2] = (x + y) % 256; // Red
|
|
pixel_buffer[pixel_index + 3] = 255; // Alpha/Padding
|
|
}
|
|
}
|
|
|
|
com_mat_t proj =
|
|
com_mat_perspective(640, 480, 1, 100 * COM_FIX_FRACUNIT, COM_FIX_PIHALF);
|
|
com_mat_t view = com_mat_look_at(com_vec_from(0, 0, 0),
|
|
com_vec_from(0, COM_FIX_FRACUNIT, 0),
|
|
com_vec_from(-COM_FIX_FRACUNIT, 0, 0));
|
|
com_mat_t mvp = com_mat_reoder(com_mat_mul(proj, view));
|
|
|
|
com_vec_t v0 = com_vec_from(5 * COM_FIX_FRACUNIT, 0, 2 * COM_FIX_FRACUNIT);
|
|
com_vec_t v1 = com_vec_from(5 * COM_FIX_FRACUNIT, 1 * COM_FIX_FRACUNIT,
|
|
4 * COM_FIX_FRACUNIT);
|
|
com_vec_t v2 = com_vec_from(5 * COM_FIX_FRACUNIT, 4 * COM_FIX_FRACUNIT,
|
|
4 * COM_FIX_FRACUNIT);
|
|
|
|
com_pnt_t uv0 = com_pnt_from(0 * COM_FIX_FRACUNIT, 0 * COM_FIX_FRACUNIT);
|
|
com_pnt_t uv1 = com_pnt_from(1 * COM_FIX_FRACUNIT, 0 * COM_FIX_FRACUNIT);
|
|
com_pnt_t uv2 = com_pnt_from(1 * COM_FIX_FRACUNIT, 1 * COM_FIX_FRACUNIT);
|
|
|
|
com_vec_t c0 = com_gem_vec_project_clip(mvp, v0);
|
|
com_vec_t c1 = com_gem_vec_project_clip(mvp, v1);
|
|
com_vec_t c2 = com_gem_vec_project_clip(mvp, v2);
|
|
|
|
com_pnt_t p0, p1, p2;
|
|
uint8_t cc0 = com_gem_clip_vis_project(c0, &p0);
|
|
uint8_t cc1 = com_gem_clip_vis_project(c1, &p1);
|
|
uint8_t cc2 = com_gem_clip_vis_project(c2, &p2);
|
|
|
|
com_pnt_print(p0);
|
|
com_pnt_print(p1);
|
|
com_pnt_print(p2);
|
|
|
|
uint8_t tex[32 * 32 * 3] = {0};
|
|
for (int y = 0; y < 32; ++y) {
|
|
for (int x = 0; x < 32; ++x) {
|
|
tex[(y * 32 + x) * 3 + 0] = (x / 2 + y / 2) % 2 == 0 ? 175 : 0;
|
|
tex[(y * 32 + x) * 3 + 1] = (x / 2 + y / 2) % 2 == 0 ? 0 : 0;
|
|
tex[(y * 32 + x) * 3 + 2] = (x / 2 + y / 2) % 2 == 0 ? 175 : 0;
|
|
}
|
|
}
|
|
|
|
com_gem_draw_triangle_textured(p0, p1, p2, (uint8_t *)pixel_buffer, uv0, uv1,
|
|
uv2, tex);
|
|
}
|