0
我無法弄清楚如何在屏幕表面上繪製一個半透明的紅色矩形。 這裏是我到目前爲止的代碼:SDL:繪製一個半透明的矩形
#!/usr/bin/perl
use SDL;
use SDL::Video;
use SDL::Surface;
use SDL::Rect;
# the size of the window box or the screen resolution if fullscreen
my $screen_width = 800;
my $screen_height = 600;
SDL::init(SDL_INIT_VIDEO);
# setting video mode
my $screen_surface = SDL::Video::set_video_mode($screen_width, $screen_height, 32, SDL_ANYFORMAT|SDL_SRCALPHA);
# drawing something somewhere
my $mapped_color = SDL::Video::map_RGBA($screen_surface->format(), 255, 0, 0, 128); #should be half-transparent, I suppose?
SDL::Video::fill_rect($screen_surface,
SDL::Rect->new($screen_width/4, $screen_height/4,
$screen_width/2, $screen_height/2), $mapped_color);
# update an area on the screen so its visible
SDL::Video::update_rect($screen_surface, 0, 0, $screen_width, $screen_height);
sleep(5); # just to have time to see it
它導致在黑色的背景,這不是我所試圖達到的紅色不透明的矩形。
謝謝,它幫助! – varnie
我需要問,爲什麼你把「(void)」?這是否讓編譯器忽略返回值並不保存它? –