|
al_draw_scaled_bitmpa not working if called more than 1 time |
Morshock
Member #16,875
July 2018
|
Hi, 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
|
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 al_draw_scaled_bitmap ( 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(). Update : After some more trying I understood how the parameters works. Resolved. |
|