P62ZBEHGLDMT6JPMSFQBV6TFPW42JR6LNRJUV4NQZUJXPTWNYTMQC run_glfw_window = glfwCreateWindow(640, 480, "alias engine", NULL, NULL);if(!run_glfw_window)ALIAS_ERROR("glfw: could not create window");
run_glfw_window = glfwCreateWindow(640, 480, "alias engine", NULL, NULL);if(!run_glfw_window)ALIAS_ERROR("glfw: could not create window");
extern struct GL_ShaderResource u_time;extern struct GL_ShaderResource u_model_matrix;extern struct GL_ShaderResource u_view_matrix;extern struct GL_ShaderResource u_model_view_matrix;extern struct GL_ShaderResource u_projection_matrix;extern struct GL_ShaderResource u_view_projection_matrix;extern struct GL_ShaderResource u_model_view_projection_matrix;static inline void prepare_model_view(void) {GL_matrix_multiply(u_view_matrix.uniform.data.mat, u_model_matrix.uniform.data.mat,u_model_view_matrix.uniform.data.mat);}static inline void prepare_view_projection(void) {GL_matrix_multiply(u_projection_matrix.uniform.data.mat, u_view_matrix.uniform.data.mat,u_view_projection_matrix.uniform.data.mat);}static inline void prepare_model_view_projection(void) {GL_ShaderResource_prepare(&u_view_projection_matrix);GL_matrix_multiply(u_view_projection_matrix.uniform.data.mat, u_model_matrix.uniform.data.mat,u_model_view_projection_matrix.uniform.data.mat);}struct GL_ShaderResource u_time = {.type = GL_Type_Float, .name = "time"};struct GL_ShaderResource u_model_matrix = {.type = GL_Type_Float4x4, .name = "model_matrix"};struct GL_ShaderResource u_view_matrix = {.type = GL_Type_Float4x4, .name = "view_matrix"};struct GL_ShaderResource u_model_view_matrix = {.type = GL_Type_Float4x4, .name = "model_view_matrix", .uniform.prepare = prepare_model_view};struct GL_ShaderResource u_projection_matrix = {.type = GL_Type_Float4x4, .name = "projection_matrix"};struct GL_ShaderResource u_view_projection_matrix = {.type = GL_Type_Float4x4, .name = "view_projection_matrix", .uniform.prepare = prepare_view_projection};struct GL_ShaderResource u_model_view_projection_matrix = {.type = GL_Type_Float4x4, .name = "model_view_projection_matrix", .uniform.prepare = prepare_model_view_projection};THIN_GL_SHADER(_ui_vertex,code(layout(location = 0) out vec2 out_st;layout(location = 1) out vec4 out_rgba;),main(gl_Position = u_view_projection_matrix * vec4(in_xy, 0, 1);out_st = in_st;out_rgba = in_rgba;))THIN_GL_SHADER(_ui_fragment,code(layout(location = 0) in vec2 in_st;layout(location = 1) in vec4 in_rgba;layout(location = 0) out vec4 out_color;),main(out_color = texture(u_img, in_st) * in_rgba;))static struct GL_Buffer _ui_element_buffer;static struct GL_Buffer _ui_vertexes_buffer;static struct GL_DrawState _ui_draw_state = {.primitive = GL_TRIANGLES,.attribute[0] = {0, alias_memory_Format_Float32, 2, "xy", 0},.attribute[1] = {0, alias_memory_Format_Float32, 4, "rgba", 8},.attribute[2] = {0, alias_memory_Format_Float32, 2, "st", 24},.binding[0] = {sizeof(struct BackendUIVertex)},.global[0] = {THIN_GL_VERTEX_BIT, &u_view_projection_matrix},.image[0] = {THIN_GL_FRAGMENT_BIT, GL_Type_Sampler2D, "img"},.vertex_shader = &_ui_vertex_shader,.fragment_shader = &_ui_fragment_shader,.depth_range_min = 0,.depth_range_max = 1,.blend_enable = true,.blend_src_factor = GL_SRC_ALPHA,.blend_dst_factor = GL_ONE_MINUS_SRC_ALPHA};
_ui_element_buffer = GL_allocate_temporary_buffer(GL_ELEMENT_ARRAY_BUFFER, sizeof(uint32_t) * num_indexes);_ui_vertexes_buffer = GL_allocate_temporary_buffer(GL_ARRAY_BUFFER, sizeof(struct BackendUIVertex) * num_vertexes);*indexes_ptr = _ui_element_buffer.mapping;*vertexes_ptr = _ui_vertexes_buffer.mapping;
void BackendUIVertex_draw(void * image, uint32_t index_offset, uint32_t num_indexes) {
void BackendUIVertex_draw(struct BackendImage * image, uint32_t index_offset, uint32_t num_indexes) {GL_draw_elements(&_ui_draw_state, &(struct GL_DrawAssets){.image[0] = image->gl.image,.element_buffer = &_ui_element_buffer,.element_buffer_offset = index_offset,.vertex_buffers[0] = &_ui_vertexes_buffer}, num_indexes, 1, 0, 0);
int x = alias_pga2d_point_x(camera->viewport_min) * Engine_render_get_width();int y = alias_pga2d_point_y(camera->viewport_min) * Engine_render_get_height();int width = (alias_pga2d_point_x(camera->viewport_max) * Engine_render_get_width()) - x;int height = (alias_pga2d_point_y(camera->viewport_max) * Engine_render_get_height()) - y;
int x = alias_pga2d_point_x(camera->viewport_min) * run_render_width;int y = alias_pga2d_point_y(camera->viewport_min) * run_render_height;int width = (alias_pga2d_point_x(camera->viewport_max) * run_render_width) - x;int height = (alias_pga2d_point_y(camera->viewport_max) * run_render_height) - y;
void BackendUIVertex_begin_draw(uint32_t num_indexes, uint32_t ** indexes_ptr, uint32_t num_vertexes, struct BackendUIVertex ** vertexes_ptr);void BackendUIVertex_draw(void * image, uint32_t index_offset, uint32_t num_indexes);
void BackendUIVertex_begin_draw(uint32_t num_indexes, uint32_t **indexes_ptr, uint32_t num_vertexes,struct BackendUIVertex **vertexes_ptr);void BackendUIVertex_draw(struct BackendImage *image, uint32_t index_offset, uint32_t num_indexes);
void replacement_DrawText(const char * text, float x, float y, float size, alias_Color color);void replacement_MeasureTextEx(const char * text, float size, float spacing, float * width, float * height);
void replacement_DrawText(const char *text, float x, float y, float size, alias_Color color);void replacement_MeasureTextEx(const char *text, float size, float spacing, float *width, float *height);
void Font_draw(struct Font * font, const char * text, float x, float y, float size, float spacing, alias_Color color);void Font_measure(struct Font * font, const char * text, float size, float spacing, float * width, float * height);
void Font_draw(struct Font *font, const char *text, float x, float y, float size, float spacing, alias_Color color);void Font_measure(struct Font *font, const char *text, float size, float spacing, float *width, float *height);
void Engine__touch_resource(struct LoadedResource * resource);struct LoadedResource * Engine__loaded_resource_by_id(uint32_t id);struct LoadedResource * Engine__load_image(struct Image * img);
void Engine__touch_resource(struct LoadedResource *resource);struct LoadedResource *Engine__loaded_resource_by_id(uint32_t id);struct LoadedResource *Engine__load_image(struct Image *img);
#include "local.h"void BackendImage_load(struct BackendImage *image, const char *path) {int width, height, channels;uint8_t *data = stbi_load(path, &width, &height, &channels, 0);if(data == NULL) {return;}if(channels != 3 && channels != 4) {free(data);return;}GLenum internal_format = channels == 3 ? GL_RGB8 : GL_RGBA8;GLenum external_format = channels == 3 ? GL_RGB : GL_RGBA;int levels = 1, w = width, h = height;while(w > 1 && h > 1) {levels++;w = w >> (w > 1);h = h >> (h > 1);}glCreateTextures(GL_TEXTURE_2D, 1, &image->gl.image);glTextureStorage2D(image->gl.image, levels, internal_format, width, height);glTextureSubImage2D(image->gl.image, 0, 0, 0, width, height, external_format, GL_UNSIGNED_BYTE, data);glGenerateTextureMipmap(image->gl.image);glTextureParameteri(image->gl.image, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glTextureParameteri(image->gl.image, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
image->width = width;image->height = height;image->depth = 1;image->levels = levels;image->layers = 1;image->internal_format = internal_format;}void BackendImage_unload(struct BackendImage *image) {}
void Font_draw(struct Font * font, const char * text, float x, float y, float size, float spacing, alias_Color color) {struct BackendUIVertex * vertexes = NULL;uint32_t * indexes = NULL;
void Font_draw(struct Font *font, const char *text, float x, float y, float size, float spacing, alias_Color color) {struct BackendUIVertex *vertexes = NULL;uint32_t *indexes = NULL;
// BackendUIVertex_begin_draw(// 6 * alias_min(FONT_DRAW_CHARACTERS_PER_BATCH, length)// , &indexes// , 4 * alias_min(FONT_DRAW_CHARACTERS_PER_BATCH, length)// , &vertexes// );
BackendUIVertex_begin_draw(6 * alias_min(FONT_DRAW_CHARACTERS_PER_BATCH, length), &indexes,4 * alias_min(FONT_DRAW_CHARACTERS_PER_BATCH, length), &vertexes);
#define EMIT(I, V, H) \vertexes[i * 4 + I].xy[0] = x + glyph->plane_##H * size; \vertexes[i * 4 + I].xy[1] = y + (1.0f - glyph->plane_##V) * size; \vertexes[i * 4 + I].rgba[0] = color.r; \vertexes[i * 4 + I].rgba[1] = color.g; \vertexes[i * 4 + I].rgba[2] = color.b; \vertexes[i * 4 + I].rgba[3] = color.a; \vertexes[i * 4 + I].st[0] = glyph->atlas_##H * s_scale; \vertexes[i * 4 + I].st[1] = 1.0f - (glyph->atlas_##V * t_scale);
#define EMIT(I, V, H) \vertexes[i * 4 + I].xy[0] = x + glyph->plane_##H * size; \vertexes[i * 4 + I].xy[1] = y + (1.0f - glyph->plane_##V) * size; \vertexes[i * 4 + I].rgba[0] = color.r; \vertexes[i * 4 + I].rgba[1] = color.g; \vertexes[i * 4 + I].rgba[2] = color.b; \vertexes[i * 4 + I].rgba[3] = color.a; \vertexes[i * 4 + I].st[0] = glyph->atlas_##H * s_scale; \vertexes[i * 4 + I].st[1] = 1.0f - (glyph->atlas_##V * t_scale);
//alias_ui_initialize(alias_default_MemoryCB(), &run_ui);//run_ui_recording = false;//run_physics_speed = alias_R_ONE;//run_current_state = NULL;
uv_timer_init(&run_libuv_loop, &_sim_timer);uv_timer_start(&_sim_timer, _sim_timer_f, 0, 16); // 60fps
void intro_frame(void *ud) {
static void _intro_frame(void * ud) {(void)ud;if(main_inputs.menu_back.boolean) {Engine_pop_state();return;}if(main_inputs.menu_forward.boolean) {Engine_pop_state();//Engine_push_state(&main_menu_state);return;}}//static struct Image _intro_title_image = { .path = "intro_title.png" };static void _intro_ui(void * ud) {(void)ud;//Engine_ui_center();// Engine_ui_image(&_intro_title_image);Engine_ui_center();Engine_ui_font_color(alias_Color_GRAY);Engine_ui_vertical();Engine_ui_font_size(40);Engine_ui_text("Alias Town");Engine_ui_font_size(20);Engine_ui_text("A game by %s | Unicat", _unicat_names[(_intro_l++ >> 5) % (sizeof(_unicat_names)/sizeof(_unicat_names[0]))]);Engine_ui_end();Engine_ui_top();Engine_ui_font_color(alias_Color_BLACK);Engine_ui_text("version 1");