int say_window_open(say_window *win, size_t w, size_t h, const char *title, uint8_t style) { if (w < 1 || h < 1) { say_error_set("window size must be at least (1,1)"); return 0; } win->show_cursor = true; if (!say_imp_window_open(win->win, title, w, h, style)) return false; say_target_set_context_proc(win->target, (say_context_proc)say_context_create_for_window); say_target_set_bind_hook(win->target, say_window_unbind_fbo); say_target_set_custom_data(win->target, (void*)win); say_target_set_size(win->target, say_make_vector2(w, h)); say_view_set_size(win->target->view, say_make_vector2(w, h)); say_view_set_center(win->target->view, say_make_vector2(w / 2.0, h / 2.0)); say_target_make_current(win->target); return 1; }
void say_image_target_set_image(say_image_target *target, say_image *image) { say_context_ensure(); target->img = image; if (target->img) { say_target_set_custom_data(target->target, target); //say_target_need_own_contxt(target->target, 0); say_target_set_context_proc(target->target, say_image_target_make_context); say_target_set_bind_hook(target->target, (say_bind_hook)say_image_target_bind); say_vector2 size = say_image_get_size(image); say_target_set_size(target->target, size); say_view_set_size(target->target->view, size); say_view_set_center(target->target->view, say_make_vector2(size.x / 2.0, size.y / 2.0)); say_view_flip_y(target->target->view, 0); say_fbo_make_current(target->fbo); say_image_bind(image); glGenerateMipmapEXT(GL_TEXTURE_2D); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, image->texture, 0); say_rbo_make_current(target->rbo); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, say_image_get_width(image), say_image_get_height(image)); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, target->rbo); } }