Advertisement
Guest User

Untitled

a guest
Dec 10th, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.97 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. #include "allegro5/allegro.h"
  6. #include "allegro5/allegro_font.h"
  7. #include "allegro5/allegro_ttf.h"
  8. #include "allegro5/allegro_image.h"
  9. #include "allegro5/allegro_primitives.h"
  10.  
  11.  
  12.  
  13. void DrawLightB(int x , int y , int r , float fr , float fg , float fb);
  14. void DrawLightB(int x , int y , int r , float fr , float fg , float fb) {
  15.    al_draw_filled_circle(x,y,r,al_map_rgb_f(fr,fg,fb));
  16. }
  17. void DrawLightA(int x , int y , int r , float fr , float fg , float fb);
  18. void DrawLightA(int x , int y , int r , float fr , float fg , float fb) {
  19.    int rad = r;
  20.    float l = 1. / ((float) r);
  21.    while (rad > 0) {
  22.       al_draw_filled_circle(x , y , rad , al_map_rgb_f(fr*l,fg*l,fb*l));
  23.       rad -= 1;
  24.    }
  25. }
  26. void DrawLightC(int x , int y , int r , float fr , float fg , float fb);
  27. void DrawLightC(int x , int y , int r , float fr , float fg , float fb) {
  28.    int rad = r;
  29.    while (rad > 0) {
  30.       float l = (r-rad)/(float)(r*10.0);///1. / ((float) r);
  31.       al_draw_filled_circle(x , y , rad , al_map_rgb_f(fr*l,fg*l,fb*l));
  32.       rad -= 10;
  33.    }
  34. }
  35.  
  36.  
  37.  
  38. ///#include "allegro5/allegro_direct3d.h"
  39.  
  40.  
  41.  
  42. int main(int argc , char** argv) {
  43.  
  44.    (void)argc;
  45.    (void)argv;
  46.  
  47.  
  48.    if (!al_init()) {
  49.       return 1;
  50.    }
  51.    if (!al_init_image_addon()) {return 2;}
  52.    if (!al_init_font_addon()) {return 3;}
  53.    if (!al_init_ttf_addon()) {return 4;}
  54.    if (!al_init_primitives_addon()) {return 5;}
  55.  
  56.    al_install_keyboard();
  57.    al_install_mouse();
  58.  
  59.    al_set_new_display_flags(ALLEGRO_FULLSCREEN | ALLEGRO_OPENGL);
  60. ///   al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW | ALLEGRO_OPENGL);
  61.    ALLEGRO_DISPLAY* d = al_create_display(1920,1080);
  62.  
  63.    ALLEGRO_TIMER* t = al_create_timer(1.0/60.0);
  64.  
  65.    ALLEGRO_EVENT_QUEUE* q = al_create_event_queue();
  66.  
  67.    al_register_event_source(q , al_get_timer_event_source(t));
  68.    al_register_event_source(q , al_get_display_event_source(d));
  69.    al_register_event_source(q , al_get_keyboard_event_source());
  70.    al_register_event_source(q , al_get_mouse_event_source());
  71.  
  72.    ALLEGRO_BITMAP* lmap = al_create_bitmap(1920,1080);
  73.    ALLEGRO_BITMAP* bg = al_load_bitmap("BG.png");
  74.  
  75.    if (!bg || !lmap) {return 7;}
  76.  
  77.    int mx = 0;
  78.    int my = 0;
  79.  
  80.    
  81.    
  82.    ALLEGRO_BITMAP* lmap2 = al_create_bitmap(2048,2048);
  83.    
  84.    /// draw our light map
  85.    al_set_target_bitmap(lmap2);
  86.    al_clear_to_color(al_map_rgb(0,0,0));
  87.  
  88.    mx = 1024;
  89.    my = 1024;
  90.    
  91.    // Additive blending
  92.    al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
  93. ///         DrawLight(0 , 0 , 200);
  94. ///         DrawLight(mx , my , 200 , 1.0 , 1.0 , 1.0);
  95.    DrawLightA(mx - 100 , my - 100 , 400 , 1.0 , 0.0 , 0.0);
  96.    DrawLightA(mx + 100 , my - 100 , 400 , 0.0 , 1.0 , 0.0);
  97.    DrawLightA(mx       , my + 73  , 400 , 0.0 , 0.0 , 1.0);
  98.  
  99.    al_start_timer(t);
  100.    
  101.    bool run = true;
  102.    bool draw = true;
  103.    while (run) {
  104.       if (draw) {
  105.          /// draw our light map
  106.          al_set_target_bitmap(lmap);
  107.          al_clear_to_color(al_map_rgb(0,0,0));
  108.  
  109.          // Additive blending
  110.          al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
  111.          
  112.          al_draw_bitmap(lmap2 , mx - 1024 , my - 1024 , 0);
  113.          
  114. ///         DrawLight(0 , 0 , 200);
  115. ///         DrawLight(mx , my , 200 , 1.0 , 1.0 , 1.0);
  116. /**
  117.  
  118.          DrawLightA(mx - 100 , my - 100 , 400 , 1.0 , 0.0 , 0.0);
  119.          DrawLightA(mx + 100 , my - 100 , 400 , 0.0 , 1.0 , 0.0);
  120.          DrawLightA(mx       , my + 73  , 400 , 0.0 , 0.0 , 1.0);
  121.  
  122.          DrawLightB(mx - 100 , my - 100 , 300 , 1.0 , 0.0 , 0.0);
  123.          DrawLightB(mx + 100 , my - 100 , 300 , 0.0 , 1.0 , 0.0);
  124.          DrawLightB(mx       , my + 73  , 300 , 0.0 , 0.0 , 1.0);
  125.  
  126.          DrawLightC(mx - 100 , my - 100 , 400 , 1.0 , 0.0 , 0.0);
  127.          DrawLightC(mx + 100 , my - 100 , 400 , 0.0 , 1.0 , 0.0);
  128.          DrawLightC(mx       , my + 73  , 400 , 0.0 , 0.0 , 1.0);
  129. */
  130.  
  131.          al_set_target_backbuffer(d);
  132.          al_clear_to_color(al_map_rgb_f(1,1,1));
  133.  
  134.          // Default blending (premult alpha)
  135.          al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
  136.          al_draw_bitmap(bg , (1920 - al_get_bitmap_width(bg))/2 , (1080 - al_get_bitmap_height(bg))/2 , 0);
  137.  
  138.          // Mult source & dest blending
  139.          al_set_blender(ALLEGRO_ADD, ALLEGRO_DEST_COLOR, ALLEGRO_ZERO);
  140.          al_draw_bitmap(lmap , 0 , 0 , 0);
  141.          al_flip_display();
  142.          draw = false;
  143.       }
  144.  
  145.       do {
  146.          ALLEGRO_EVENT ev;
  147.          al_wait_for_event(q , &ev);
  148.          if (ev.type == ALLEGRO_EVENT_MOUSE_AXES) {
  149.             mx = ev.mouse.x;
  150.             my = ev.mouse.y;
  151.             draw = true;
  152.          }
  153.          if (ev.type == ALLEGRO_EVENT_KEY_DOWN && ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
  154.             run = false;
  155.          }
  156.          if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
  157.             run = false;
  158.          }
  159.          if (ev.type == ALLEGRO_EVENT_TIMER) {
  160.             draw = true;
  161.          }
  162.       } while (!al_is_event_queue_empty(q));
  163.  
  164.    }
  165.    return 0;
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement