Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » al_draw_scaled_bitmpa not working if called more than 1 time

This thread is locked; no one can reply to it. rss feed Print
al_draw_scaled_bitmpa not working if called more than 1 time
Morshock
Member #16,875
July 2018

Hi,
I was trying to use al_draw_scaled_bitmap() but whenever this function is called more than 1 time every sub sequential calls after the first seems to just be ignore and nothing is drawn. In both the manual and the man page there is noting saying this is how it's intended to work. al_draw_bitmap() Seems to work just fine.
I've added a sample of code to show the issue.
Any idea on how to resolve the issue?

#SelectExpand
1#include <iostream> 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_image.h> 4 5using namespace std ; 6 7const int Dimensions = 800 ; 8const int DisplayDimensions = 512 ; 9const float Scale = static_cast<float>(Dimensions) / static_cast<float>(DisplayDimensions) ; 10const float OffSet = 64 ; 11const float NewOffSet = OffSet * Scale ; 12 13const char ChessBoardPath [] = "./Media/Images/ChessBoard.png" ; 14const char WKingPath [] = "./Media/Images/WhiteKing.png" ; 15 16int main () 17{ 18 al_init () ; 19 al_init_image_addon () ; 20 21 ALLEGRO_MONITOR_INFO MonitorInfo ; 22 al_get_monitor_info (0, &MonitorInfo) ; 23 al_set_new_window_title ("Test") ; 24 al_set_new_window_position (MonitorInfo.x2 / 2 - Dimensions / 2, MonitorInfo.y2 / 2 - Dimensions / 2) ; 25 26 ALLEGRO_DISPLAY * Display = al_create_display (Dimensions, Dimensions) ; 27 28 ALLEGRO_BITMAP * King = al_load_bitmap (WKingPath) ; 29 ALLEGRO_BITMAP * Board = al_load_bitmap (ChessBoardPath) ; 30 31 al_convert_mask_to_alpha (King, al_map_rgb (255, 0, 255)) ; 32 33 34 al_clear_to_color (al_map_rgb (0, 0, 0)) ; 35 al_draw_scaled_bitmap (Board, 0, 0, DisplayDimensions, DisplayDimensions, 0, 0, DisplayDimensions * Scale, DisplayDimensions * Scale, 0) ; 36 37 for (int i = 0 ; i < 2 ; i++) 38 for (int j = 0 ; j < 8 ; j++) 39 { 40 cout <<"i : " <<i <<". j : " <<j <<endl ; 41 al_draw_scaled_bitmap (King, j * NewOffSet, i * NewOffSet, OffSet, OffSet, j * NewOffSet, i * NewOffSet, NewOffSet, NewOffSet, 0) ; 42 al_draw_bitmap (King, j * NewOffSet, (i+6) * NewOffSet, 0) ; 43 } 44 45 al_flip_display() ; 46 47 sleep(10.0) ; 48 49 al_destroy_display (Display) ; 50 51 return 0 ; 52}

torhu
Member #2,727
September 2002
avatar

Are you sure you are using al_draw_scaled_bitmap correctly?

Isn't it like this?

al_draw_scaled_bitmap(King,
    0, 0,
    al_get_bitmap_width(King), al_get_bitmap_height(King),
    x_position, y_position,
    scaled_width, scaled_height,
    0);

Morshock
Member #16,875
July 2018

@torhu
Should be correct in theory, I should have renamed the variable to fit their use better.

al_draw_scaled_bitmap (
King is the ALLEGRO_BITMAP
j * NewOffSet is the X Coordinate of the Top Left Corner of the Source
i * NewOffSet is the Y Coordinate of the Top Left Corner of the Source
Offset is the bitmap Width
OffSet is the bitmap Height
j * NewOffSet is the X Coordinate of the Top Left Corner of the Destination
i * NewOffSet is the Y Coordinate of the Top Left Corner of the Destination
NewOffSet is the Width of the Destination
NewOffSet is the Height of the Destination
0 are the applied flags) ;

Basically was I was trying to do was to draw the pieces of chess on the chessboard but only the first piece is being drawn. Just to clarify this variables name are what I was using in the full program this is just a piece of code throw together to test out al_draw_scaled_bitmap().
I think I'm probably misunderstanding something on how the parameters off the function works.

Update : After some more trying I understood how the parameters works. Resolved.

Go to: