1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

Where to begin learning how to create shadows

Discussion in 'Programming' started by JML, Aug 16, 2019.

  1. JML

    JML Wabbajackalope

    Joined:
    Jun 22, 2016
    Posts:
    353
    i would like to learn how to create shadows on objects, preferably in a manner which would allow me to control the variables that effect the location of the light.

    where would i begin learning this?

    Thank you.
     
  2. Bentley

    Bentley Member

    Joined:
    Jun 18, 2017
    Posts:
    831
    His website has a tutorial about shadows: www.davetech.co.uk

    Basically, you draw every instance that you want to have a shadow to a surface, and draw that surface before you draw everything else.
    I didn't test this code, but I hopefully this shows you what I mean.
    Code:
    if (!surface_exists(surf))
    {
        surf = surface_create(room_width, room_height);
        surface_set_target(surf);
        draw_clear_alpha(c_black, 0);
        surface_reset_target();
    }
    
    surface_set_target(surf);
    with (par_shadow)
    {
        draw_self();
    }
    surface_reset_target();
    
    draw_surface_ext(surf, 16, 16, 1, 1, 0, c_black, 0.5);  
    draw_surface_ext lets you draw the surface offset (16, 16), black, and semi-transparent.
     

Share This Page