void text_renderer_new(text_renderer_p renderer, size_t texture_width, size_t texture_height) { FT_Error error = FT_Init_FreeType(&renderer->freetype); if (error) { printf("FT_Init_FreeType error\n"); return; } renderer->texture = texture_new(texture_width, texture_height, GL_R8); size_t black_data_size = texture_width * texture_height; void* black_data = malloc(black_data_size); memset(black_data, 0, black_data_size); texture_update(renderer->texture, GL_RED, black_data); free(black_data); glBindTexture(GL_TEXTURE_RECTANGLE, renderer->texture); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_RECTANGLE, 0); renderer->fonts = hash_of(text_renderer_font_t); renderer->lines = array_of(text_renderer_line_t); }
static int lupdate_texture(lua_State *L) { int id = luaL_checkinteger(L,1); int width = luaL_checkinteger(L,2); int height = luaL_checkinteger(L,3); int step = luaL_checkinteger(L,4); luaL_checktype(L,5,LUA_TTABLE); int size = width*height*step; int len = lua_rawlen(L,5); if (size != len) { return luaL_error(L, "no match pixels size:%d, should be %d*%d*%d=%d", len, width, height, step, size); } uint8_t *buffer = (uint8_t*)malloc(size); int i; for (i=0; i<size; ++i) { lua_rawgeti(L,-1,i+1); buffer[i] = (uint8_t)lua_tointeger(L,-1); lua_pop(L,1); } texture_update(id, width, height, buffer); free(buffer); return 0; }
int renderer_sdl2::draw(int update) { texture_info *texture=nullptr; float vofs, hofs; int blit_pixels = 0; if (video_config.novideo) { return 0; } auto win = assert_window(); osd_dim wdim = win->get_size(); if (has_flags(FI_CHANGED) || (wdim.width() != m_width) || (wdim.height() != m_height)) { destroy_all_textures(); m_width = wdim.width(); m_height = wdim.height(); SDL_RenderSetViewport(m_sdl_renderer, nullptr); m_blittimer = 3; clear_flags(FI_CHANGED); } //SDL_SelectRenderer(window().sdl_window); if (m_blittimer > 0) { /* SDL Underlays need alpha = 0 ! */ SDL_SetRenderDrawBlendMode(m_sdl_renderer, SDL_BLENDMODE_NONE); //SDL_SetRenderDrawColor(0,0,0,255); SDL_SetRenderDrawColor(m_sdl_renderer, 0,0,0,0); SDL_RenderFillRect(m_sdl_renderer, nullptr); m_blittimer--; } // compute centering parameters vofs = hofs = 0.0f; if (video_config.centerv || video_config.centerh) { int ch, cw; ch = wdim.height(); cw = wdim.width(); if (video_config.centerv) { vofs = (ch - m_blit_dim.height()) / 2.0f; } if (video_config.centerh) { hofs = (cw - m_blit_dim.width()) / 2.0f; } } m_last_hofs = hofs; m_last_vofs = vofs; win->m_primlist->acquire_lock(); // now draw for (render_primitive &prim : *win->m_primlist) { Uint8 sr, sg, sb, sa; switch (prim.type) { case render_primitive::LINE: sr = (int)(255.0f * prim.color.r); sg = (int)(255.0f * prim.color.g); sb = (int)(255.0f * prim.color.b); sa = (int)(255.0f * prim.color.a); SDL_SetRenderDrawBlendMode(m_sdl_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim.flags))); SDL_SetRenderDrawColor(m_sdl_renderer, sr, sg, sb, sa); SDL_RenderDrawLine(m_sdl_renderer, prim.bounds.x0 + hofs, prim.bounds.y0 + vofs, prim.bounds.x1 + hofs, prim.bounds.y1 + vofs); break; case render_primitive::QUAD: texture = texture_update(prim); if (texture) blit_pixels += (texture->raw_height() * texture->raw_width()); render_quad(texture, prim, round_nearest(hofs + prim.bounds.x0), round_nearest(vofs + prim.bounds.y0)); break; default: throw emu_fatalerror("Unexpected render_primitive type\n"); } } win->m_primlist->release_lock(); m_last_blit_pixels = blit_pixels; m_last_blit_time = -osd_ticks(); SDL_RenderPresent(m_sdl_renderer); m_last_blit_time += osd_ticks(); return 0; }
void cls_object_screen_image( t_object *object) { t_context *C = ctx_get(); texture_update( object->texture, object->data); ui_texture_draw( C, object->texture , 0, 0, 1 ,1); }
static int draw13_window_draw(sdl_window_info *window, UINT32 dc, int update) { sdl_info *sdl = (sdl_info *) window->dxdata; render_primitive *prim; texture_info *texture=NULL; float vofs, hofs; int blit_pixels = 0; if (video_config.novideo) { return 0; } if (sdl->resize_pending) { SDL_SetWindowSize(window->sdl_window, sdl->resize_width, sdl->resize_height); SDL_GetWindowSize(window->sdl_window, &window->width, &window->height); sdl->resize_pending = 0; SDL_RenderSetViewport(sdl->sdl_renderer, NULL); } //SDL_SelectRenderer(window->sdl_window); if (sdl->blittimer > 0) { /* SDL Underlays need alpha = 0 ! */ SDL_SetRenderDrawBlendMode(sdl->sdl_renderer, SDL_BLENDMODE_NONE); //SDL_SetRenderDrawColor(0,0,0,255); SDL_SetRenderDrawColor(sdl->sdl_renderer, 0,0,0,0); SDL_RenderFillRect(sdl->sdl_renderer, NULL); sdl->blittimer--; } // compute centering parameters vofs = hofs = 0.0f; if (video_config.centerv || video_config.centerh) { int ch, cw; if ((window->fullscreen) && (!video_config.switchres)) { ch = window->monitor->center_height; cw = window->monitor->center_width; } else { ch = window->height; cw = window->width; } if (video_config.centerv) { vofs = (ch - window->blitheight) / 2.0f; } if (video_config.centerh) { hofs = (cw - window->blitwidth) / 2.0f; } } sdl->last_hofs = hofs; sdl->last_vofs = vofs; window->primlist->acquire_lock(); // now draw for (prim = window->primlist->first(); prim != NULL; prim = prim->next()) { Uint8 sr, sg, sb, sa; switch (prim->type) { case render_primitive::LINE: sr = (int)(255.0f * prim->color.r); sg = (int)(255.0f * prim->color.g); sb = (int)(255.0f * prim->color.b); sa = (int)(255.0f * prim->color.a); SDL_SetRenderDrawBlendMode(sdl->sdl_renderer, map_blendmode(PRIMFLAG_GET_BLENDMODE(prim->flags))); SDL_SetRenderDrawColor(sdl->sdl_renderer, sr, sg, sb, sa); SDL_RenderDrawLine(sdl->sdl_renderer, prim->bounds.x0 + hofs, prim->bounds.y0 + vofs, prim->bounds.x1 + hofs, prim->bounds.y1 + vofs); break; case render_primitive::QUAD: texture = texture_update(window, prim); if (texture) blit_pixels += (texture->rawheight * texture->rawwidth); render_quad(sdl, texture, prim, round_nearest(hofs + prim->bounds.x0), round_nearest(vofs + prim->bounds.y0)); break; default: throw emu_fatalerror("Unexpected render_primitive type\n"); } } window->primlist->release_lock(); sdl->last_blit_pixels = blit_pixels; sdl->last_blit_time = -osd_ticks(); SDL_RenderPresent(sdl->sdl_renderer); sdl->last_blit_time += osd_ticks(); return 0; }