|
Question about sprites and masking |
FreeCastle
Member #7,724
September 2006
|
After setting the display mode and so on, I load a bitmap with the following code: Then I did a forum search and found a thread with a similar problem. So I changed my code to something like this: set_color_conversion(COLORCONV_TOTAL | COLORCONV_KEEP_TRANS); BITMAP* tmp = load_bitmap("sprite.bmp",NULL); BITMAP* image = create_video_bitmap(tmp->w,tmp->h); int c = bitmap_mask_color(tmp); clear_to_color(image,c); blit(tmp,image,0,0,0,0,tmp->w,tmp->h); destroy_bitmap(tmp); draw_sprite(screen,image,0,0); With exactly these lines it works as it should. But I want to know why ? I used Allegro time ago and I remember that I didn't have to do something like this at that time. Maybe there are also other ways ? Another Question: Is it good to create the sprites in video memory as I did in the above code or should I create them in normal memory ? P.S. Do you know why I can't reply on my other started topic ? http://www.allegro.cc/forums/thread/587370 |
Richard Phipps
Member #1,632
November 2001
|
The reason that video memory is being used is that some gfx cards can blit from video memory to video memory very fast, gaining a considerable speed boost over normal memory. From the manual: Quote: If the GFX_HW_VRAM_BLIT_MASKED bit in the gfx_capabilities flag is set, the current driver supports hardware accelerated sprite drawing when the source image is a video memory bitmap or a sub-bitmap of the screen. This is extremely fast, so when this flag is set it may be worth storing some of your more frequently used sprites in an offscreen portion of the video memory. Warning: if the hardware acceleration flag is not set, draw_sprite() will not work correctly when used with a sprite image in system or video memory so the latter must be a memory bitmap. It sounds like your grey problems were due to the sprite and the screen being different colour depths. draw_sprite doesn't do proper colour conversion, whereas the blit in the code you posted above does. See the manual for draw_sprite: |
Don Freeman
Member #5,110
October 2004
|
When do you call set_color_depth()? I use the following and it works fine for me:
About memory/video bitmaps: About replying: -- |
gnolam
Member #2,030
March 2002
|
Quote: set_gfx_mode(GFX_DIRECTX_WIN,500,500,0,0); Not only are you unnecessarily using a platform-dependant driver, you are trying to set a 500x500 resolution... without error checking. Yikes. -- |
FreeCastle
Member #7,724
September 2006
|
Quote: It sounds like your grey problems were due to the sprite and the screen being different colour depths. draw_sprite doesn't do proper colour conversion, whereas the blit in the code you posted above does. See the manual for draw_sprite:
Yes I think this is the reason. But I don't know how to handle it. I created e.g. a simple bitmap with MS-Paint and then saved it as a 24-bit bitmap (thats the only true-color option). Then in my allegro app I also set the color depth to 24 (later 32). But I don't get the correct image represented About that video/memory bitmap thing: @Freeman |
Don Freeman
Member #5,110
October 2004
|
gnolam: FreeCastle: -- |
William Labbett
Member #4,486
March 2004
|
sorry to hijack the thread but i've read it and it made me wonder what the difference between a system bitmap and a memory bitmap is ? maybe others might learn seomething here too
|
Derezo
Member #1,666
April 2001
|
"He who controls the stuffing controls the Universe" |
FreeCastle
Member #7,724
September 2006
|
Arrrr... |
Evert
Member #794
November 2000
|
Quote: And considering I ONLY use windows You're aware, I hope, that GFX_AUTODETECT_WINDOWED gives you GFX_DIRECTX_WIN in Windows by default? SO even if you're only interested in Windows, there is no valid reason for not using GFX_AUTODETECT_WINDOWED. Quote: I didn't see it clearly that the set_color_depth() function should be called always before the set_gfx_mode() function.
man set_gfx_mode said: The color depth of the graphic mode has to be specified before calling this function with set_color_depth().
man set_color_depth said: Sets the pixel format to be used by subsequent calls to set_gfx_mode() and create_bitmap().
Seems pretty clear to me... |
|