static void initialize() { g_texture_width = 2048; g_texture_height = 2048; int max_texture_size = fs_ml_get_max_texture_size(); if (max_texture_size > 0) { if (max_texture_size < g_texture_width) { g_texture_width = max_texture_size; } if (max_texture_size < g_texture_height) { g_texture_height = max_texture_size; } } fs_log("using text cache texture size %dx%d\n", g_texture_width, g_texture_height); initialize_cache(); create_text_texture(); fs_gl_add_context_notification(context_notification_handler, NULL); g_buffer = malloc(g_texture_width * 32 * 4); #ifdef USE_FREETYPE init_freetype(); #endif g_initialized = 1; }
void initialize() { initialize_cache(); create_text_texture(); fs_gl_add_context_notification(context_notification_handler, NULL); g_buffer = g_malloc(TEXTURE_WIDTH * 32 * 4); g_initialized = 1; }
static int l_fs_emu_load_shader(lua_State *L) { const char *name = luaL_checkstring(L, 1); char *path = find_shader(name); if (!path) { lua_pushnil(L); return 1; } fs_emu_shader *shader = g_new0(fs_emu_shader, 1); shader->path = path; fs_emu_load_shader(shader); fs_gl_add_context_notification(context_notification_handler, shader); lua_pushlightuserdata(L, shader); luaL_newmetatable(L, "fs_emu_shader"); lua_setmetatable(L, -2); return 1; }
static void fs_emu_load_default_shader() { const char *name = fs_config_get_const_string("shader"); if (!name) { return; } char *path = find_shader(name); if (!path) { fs_emu_warning(_("Shader not found: %s"), name); return; } fs_emu_shader *shader= g_new0(fs_emu_shader, 1); shader->path = path; fs_emu_load_shader(shader); fs_gl_add_context_notification(context_notification_handler, shader); g_active_shader = shader; }
void fs_emu_initialize_opengl() { setup_opengl(); fs_emu_initialize_textures(); fs_gl_add_context_notification(context_notification_handler, NULL); }
fs_emu_texture *fs_emu_texture_new_from_file(const char *name) { char *full_name; char *path; if (fs_path_exists(name)) { full_name = fs_strdup(name); path = fs_strdup(name); } else { full_name = fs_strconcat(name, ".png", NULL); path = fs_get_program_data_file(full_name); if (path == NULL) { fs_emu_warning("Could not find texture %s\n", full_name); return NULL; } } fs_image *image = fs_image_new_from_file(path); fs_emu_log("loading texture \"%s\"\n", path); free(path); if (image == NULL) { fs_emu_warning("Could not load texture from %s\n", full_name); free(full_name); return NULL; } free(full_name); if (fs_emu_get_video_format() == FS_EMU_VIDEO_FORMAT_BGRA) { // convert to premultiplied alpha if (image->format == FS_IMAGE_FORMAT_RGBA) { int num_pixels = image->width * image->height; unsigned char *pixels = image->data; for (int i = 0; i < num_pixels; i++) { unsigned char alpha = pixels[3]; unsigned char temp = pixels[2]; pixels[2] = ((int) pixels[0]) * alpha / 255; pixels[1] = ((int) pixels[1]) * alpha / 255; pixels[0] = ((int) temp) * alpha / 255; pixels += 4; } } else { // FIXME: should swap R and B here... } } else { // convert to premultiplied alpha if (image->format == FS_IMAGE_FORMAT_RGBA) { int num_pixels = image->width * image->height; unsigned char *pixels = image->data; for (int i = 0; i < num_pixels; i++) { unsigned char alpha = pixels[3]; // should really divide by 255, but 256 is faster... //pixels[0] = ((int) pixels[0]) * alpha / 256; //pixels[1] = ((int) pixels[1]) * alpha / 256; //pixels[2] = ((int) pixels[2]) * alpha / 256; pixels[0] = ((int) pixels[0]) * alpha / 255; pixels[1] = ((int) pixels[1]) * alpha / 255; pixels[2] = ((int) pixels[2]) * alpha / 255; //pixels[0] = (unsigned char) ((pixels[0] * alpha + 0.5) / 255.0); //pixels[1] = (unsigned char) ((pixels[1] * alpha + 0.5) / 255.0); //pixels[2] = (unsigned char) ((pixels[2] * alpha + 0.5) / 255.0); pixels += 4; } } } fs_emu_texture *texture = fs_new(fs_emu_texture, 1); texture->width = image->width; texture->height = image->height; texture->image = image; load_texture(texture); fs_emu_set_texture(texture); fs_gl_add_context_notification(context_notification_handler, texture); return texture; }
void fs_emu_initialize_textures() { if (g_fs_emu_theme.width == 0) { fs_emu_fatal("theme is not initialized yet"); } //g_atlas = fs_emu_texture_new_from_file("atlas"); fs_image *image = fs_image_new(); image->width = 1024; image->height = 1024; image->format = FS_IMAGE_FORMAT_RGBA; image->data = fs_malloc0(1024 * 1024 * 4); initialize_atlas(image); g_atlas = fs_new(fs_emu_texture, 1); g_atlas->width = image->width; g_atlas->height = image->height; g_atlas->image = image; load_texture(g_atlas); fs_emu_set_texture(g_atlas); fs_gl_add_context_notification(context_notification_handler, g_atlas); if (g_fs_emu_theme.overlay_image[0]) { char *path = fs_emu_theme_get_resource(g_fs_emu_theme.overlay_image); fs_log("g_fs_emu_theme.overlay_image %s => %s\n", g_fs_emu_theme.overlay_image, path); if (path) { g_fs_emu_overlay_texture = fs_emu_texture_new_from_file(path); } } for (int i = 0; i < FS_EMU_MAX_OVERLAYS; i++) { for (int j = 0; j < FS_EMU_MAX_OVERLAY_STATES; j++) { fs_emu_texture *tex = NULL; char *name = fs_strdup_printf("custom_%d_%d.png", i - FS_EMU_FIRST_CUSTOM_OVERLAY, j); char *path = fs_emu_theme_get_resource(name); if (!path && g_fs_emu_theme.overlays[i].name) { free(name); name = fs_strdup_printf("%s_%d.png", g_fs_emu_theme.overlays[i].name, j); path = fs_emu_theme_get_resource(name); } if (path) { tex = fs_emu_texture_new_from_file(path); g_fs_emu_theme.overlays[i].textures[j] = tex; free(path); } else if (j == 1) { char *base_name = fs_strdup_printf("custom_%d.png", i - FS_EMU_FIRST_CUSTOM_OVERLAY); path = fs_emu_theme_get_resource(base_name); if (!path && g_fs_emu_theme.overlays[i].name) { free(name); name = fs_strdup_printf("%s.png", g_fs_emu_theme.overlays[i].name); path = fs_emu_theme_get_resource(name); } if (path) { tex = fs_emu_texture_new_from_file(path); g_fs_emu_theme.overlays[i].textures[j] = tex; free(path); } free(base_name); } else if (j >= 2) { g_fs_emu_theme.overlays[i].textures[j] = \ g_fs_emu_theme.overlays[i].textures[j - 1]; } free(name); // size will be determined from the last loaded texture/state // for the overlay if (tex) { g_fs_emu_theme.overlays[i].w = (double) tex->width / g_fs_emu_theme.width; g_fs_emu_theme.overlays[i].h = (double) tex->height / g_fs_emu_theme.height; } } } }