void RenderTarget::resize(int32_t w, int32_t h) { ALLEGRO_BITMAP *newBitmap = al_create_bitmap(w, h); // Check if we have changed Smooth2D in between creating this rendertarget // and calling this function. If so, we need to clone this bitmap, because // bitmap resize operation flags have changed. ALLEGRO_BITMAP *bitmapToDrawResized; int bmFlags = al_get_bitmap_flags(this->bitmap); int32_t origW = this->width(); int32_t origH = this->height(); bool smooth2d = CBEnchanted::instance()->isSmooth2D(); if ((!smooth2d && (bmFlags & ALLEGRO_MAG_LINEAR) == ALLEGRO_MAG_LINEAR) || (smooth2d && (bmFlags & ALLEGRO_MAG_LINEAR) != ALLEGRO_MAG_LINEAR)) { // We need to clone. bitmapToDrawResized = al_clone_bitmap(this->bitmap); al_destroy_bitmap(this->bitmap); } else { // Phew, no need to clone. bitmapToDrawResized = this->bitmap; } al_set_target_bitmap(newBitmap); al_clear_to_color(al_map_rgb(0, 0, 0)); int32_t a, b, c; al_get_blender(&a, &b, &c); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); al_draw_scaled_bitmap(bitmapToDrawResized, 0, 0, origW, origH, 0, 0, w, h, 0); al_set_blender(a, b, c); al_destroy_bitmap(bitmapToDrawResized); this->bitmap = newBitmap; bindRenderTarget = this; }
void clear_rect_to_color (ALLEGRO_BITMAP *to, struct rect *r, ALLEGRO_COLOR color) { int op, src, dst; al_get_blender (&op, &src, &dst); al_set_blender (ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); draw_filled_rect (to, r, color); al_set_blender (op, src, dst); }
void ImGui_ImplA5_RenderDrawLists(ImDrawData* draw_data) { int op, src, dst; al_get_blender(&op, &src, &dst); al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA); for (int n = 0; n < draw_data->CmdListsCount; n++) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; // FIXME-OPT: Unfortunately Allegro doesn't support 32-bits packed colors so we have to convert them to 4 floats static ImVector<ImDrawVertAllegro> vertices; vertices.resize(cmd_list->VtxBuffer.Size); for (int i = 0; i < cmd_list->VtxBuffer.Size; ++i) { const ImDrawVert &dv = cmd_list->VtxBuffer[i]; ImDrawVertAllegro v; v.pos = dv.pos; v.uv = dv.uv; unsigned char *c = (unsigned char*)&dv.col; v.col = al_map_rgba(c[0], c[1], c[2], c[3]); vertices[i] = v; } // FIXME-OPT: Unfortunately Allegro doesn't support 16-bit indices // You can also use '#define ImDrawIdx unsigned int' in imconfig.h and request ImGui to output 32-bit indices static ImVector<int> indices; indices.resize(cmd_list->IdxBuffer.Size); for (int i = 0; i < cmd_list->IdxBuffer.Size; ++i) indices[i] = (int)cmd_list->IdxBuffer.Data[i]; int idx_offset = 0; for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; if (pcmd->UserCallback) { pcmd->UserCallback(cmd_list, pcmd); } else { ALLEGRO_BITMAP* texture = (ALLEGRO_BITMAP*)pcmd->TextureId; al_set_clipping_rectangle(pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z-pcmd->ClipRect.x, pcmd->ClipRect.w-pcmd->ClipRect.y); al_draw_indexed_prim(&vertices[0], g_VertexDecl, texture, &indices[idx_offset], pcmd->ElemCount, ALLEGRO_PRIM_TRIANGLE_LIST); } idx_offset += pcmd->ElemCount; } } // Restore modified state al_set_blender(op, src, dst); al_set_clipping_rectangle(0, 0, al_get_display_width(g_Display), al_get_display_height(g_Display)); }
static mrb_value blender_getter(mrb_state *mrb, mrb_value self) { int op; int src; int dst; mrb_value a; al_get_blender(&op, &src, &dst); a = mrb_ary_new_capa(mrb, 3); mrb_ary_push(mrb, a, mrb_fixnum_value(op)); mrb_ary_push(mrb, a, mrb_fixnum_value(src)); mrb_ary_push(mrb, a, mrb_fixnum_value(dst)); return a; }
void RenderTarget::copyBox(RenderTarget *src, int32_t sx, int32_t sy, int32_t w, int32_t h, int32_t tx, int32_t ty) { setAsCurrent(); int32_t a, b, c; al_get_blender(&a, &b, &c); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); if(src->getBitmap() == this->getBitmap()) { ALLEGRO_BITMAP *src_clone = al_clone_bitmap(src->getBitmap()); al_draw_bitmap_region(src_clone, sx, sy, w, h, tx, ty, 0); al_destroy_bitmap(src_clone); } else { al_draw_bitmap_region(src->getBitmap(), sx, sy, w, h, tx, ty, 0); } al_set_blender(a, b, c); }
void GameStateWinGame::RenderAfter( IRender & render, const IGameContext & context ) { if ( m_fadeIn || m_fadeOut ) { int alpha = (m_fadeTimer / m_fadeMax) * 255; if ( alpha < 0 ) alpha = 0; if ( alpha > 255 ) alpha = 255; Color c = m_fadeColor; if ( m_fadeIn ) c.a = alpha; else if ( m_fadeOut ) c.a = 255 - alpha; int a, b, d; al_get_blender( &a, &b, &d ); al_set_blender( ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA ); render.DrawRectFill( 0, 0, SCREEN_W, SCREEN_H, c ); al_set_blender( a, b, d ); } }
void MenuSelectLevel::Render( IRender *pRender ) { GameMenu::Render( pRender ); if ( m_levelObjectImage.IsValid() ) { const IImage *pImage = pRender->GetImageByHandle( m_levelObjectImage ); if ( !pImage ) return; const int w = pImage->GetWidth()*0.5f; const int h = pImage->GetHeight()*0.5f; const int x = m_x + m_width/2 - w / 2; const int y = m_y + m_height/2 - h / 2 - 40; float opacity = 1.0f; switch( m_state ) { case STATE_FADE_IN: opacity = 1.0f - m_timer / (float)FADE_TIME; break; case STATE_FADE_OUT: opacity = m_timer / (float)FADE_TIME; break; } int a,b,c; al_get_blender( &a, &b, &c ); al_set_blender( ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA ); //pRender->StretchImage( m_levelObjectImage, x, y, 0.5f, 0.5f, 0 ); pRender->DrawTintedImage( m_levelObjectImage, Color(255,255,255,opacity*255), x, y, 0, 0, 0, 0, 0, w, h, 0 ); al_set_blender( a, b, c ); } }
// Render function. // (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop) void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data) { // Backup Allegro state that will be modified ALLEGRO_TRANSFORM last_transform = *al_get_current_transform(); ALLEGRO_TRANSFORM last_projection_transform = *al_get_current_projection_transform(); int last_clip_x, last_clip_y, last_clip_w, last_clip_h; al_get_clipping_rectangle(&last_clip_x, &last_clip_y, &last_clip_w, &last_clip_h); int last_blender_op, last_blender_src, last_blender_dst; al_get_blender(&last_blender_op, &last_blender_src, &last_blender_dst); // Setup render state al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA); // Setup orthographic projection matrix // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). { float L = draw_data->DisplayPos.x; float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x; float T = draw_data->DisplayPos.y; float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y; ALLEGRO_TRANSFORM transform; al_identity_transform(&transform); al_use_transform(&transform); al_orthographic_transform(&transform, L, T, 1.0f, R, B, -1.0f); al_use_projection_transform(&transform); } for (int n = 0; n < draw_data->CmdListsCount; n++) { const ImDrawList* cmd_list = draw_data->CmdLists[n]; // Allegro's implementation of al_draw_indexed_prim() for DX9 is completely broken. Unindex our buffers ourselves. // FIXME-OPT: Unfortunately Allegro doesn't support 32-bits packed colors so we have to convert them to 4 float as well.. static ImVector<ImDrawVertAllegro> vertices; vertices.resize(cmd_list->IdxBuffer.Size); for (int i = 0; i < cmd_list->IdxBuffer.Size; i++) { const ImDrawVert* src_v = &cmd_list->VtxBuffer[cmd_list->IdxBuffer[i]]; ImDrawVertAllegro* dst_v = &vertices[i]; dst_v->pos = src_v->pos; dst_v->uv = src_v->uv; unsigned char* c = (unsigned char*)&src_v->col; dst_v->col = al_map_rgba(c[0], c[1], c[2], c[3]); } const int* indices = NULL; if (sizeof(ImDrawIdx) == 2) { // FIXME-OPT: Unfortunately Allegro doesn't support 16-bit indices.. You can '#define ImDrawIdx int' in imconfig.h to request Dear ImGui to output 32-bit indices. // Otherwise, we convert them from 16-bit to 32-bit at runtime here, which works perfectly but is a little wasteful. static ImVector<int> indices_converted; indices_converted.resize(cmd_list->IdxBuffer.Size); for (int i = 0; i < cmd_list->IdxBuffer.Size; ++i) indices_converted[i] = (int)cmd_list->IdxBuffer.Data[i]; indices = indices_converted.Data; } else if (sizeof(ImDrawIdx) == 4) { indices = (const int*)cmd_list->IdxBuffer.Data; } // Render command lists int idx_offset = 0; ImVec2 clip_off = draw_data->DisplayPos; for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i]; if (pcmd->UserCallback) { pcmd->UserCallback(cmd_list, pcmd); } else { ALLEGRO_BITMAP* texture = (ALLEGRO_BITMAP*)pcmd->TextureId; al_set_clipping_rectangle(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y, pcmd->ClipRect.z - pcmd->ClipRect.x, pcmd->ClipRect.w - pcmd->ClipRect.y); al_draw_prim(&vertices[0], g_VertexDecl, texture, idx_offset, idx_offset + pcmd->ElemCount, ALLEGRO_PRIM_TRIANGLE_LIST); } idx_offset += pcmd->ElemCount; } } // Restore modified Allegro state al_set_blender(last_blender_op, last_blender_src, last_blender_dst); al_set_clipping_rectangle(last_clip_x, last_clip_y, last_clip_w, last_clip_h); al_use_transform(&last_transform); al_use_projection_transform(&last_projection_transform); }