Drawing Drop shadows around a rectangle in open gl 2D

  2d, c++, linux, opengl

I am trying to create a rectangle with shadow around it. i have searched over the internet and found some docs which produces shadow using following methods:

  1. Drawing Multiple rectangles with different alpha values
  2. Using Shaders to create shadow

Here is the sample picture of what i need to achieve:

Shadow Sample

Here is a sample code of what i am working on:

float color[4] = {1.0, 0.3, 0.3, 1.0};
struct wlr_box box = 
{
  .x = view->current_box.x,
  .y = view->current_box.y,
  .width = 200,
  .height = 200
};
wlr_render_rect(renderer, &box, color,output->wlr_output->transform_matrix);

Here wlr_box is the coordinates and width for the rectangle and wlr_render_rect() creates a rectangle with those coordinates and fill it with the given color. what i need to achieve is to add shadow around this rectangle.

note: please don’t close the question saying seeking for recommendations and all, i am new to open gl and trying to learn something and i thought stack overflow is the best place to start.if you cant answer just let the question be there anyone else could answer

Source: Windows Questions C++

LEAVE A COMMENT