![]() |
|
How to draw an opaque, screen-sized, black rectangle? |
cameron
Member #8,219
January 2007
|
Hey all, I have a game in development and to add a more professional touch I want it so when certain messages appear to the player, and when the user pauses the game, etc, the following should happen: 1. a black rectangle at 50% opacity should fill the entire screen I have #3 done as the following: how would i go about drawing a large black opaque rectangle though - i don't know how to do opacity in allegro! thanks for your help, cameron |
Kauhiz
Member #4,798
July 2004
|
Actually, you apparently don't want an opaque rectangle - opaque means 100% opacity --- |
gnolam
Member #2,030
March 2002
![]() |
To be specific, look up BTW, the rest()s in your code concern me. You're not doing your game timing with rest(), are you? -- |
piccolo
Member #3,163
January 2003
![]() |
try messin around with this stuff use a square spite or drawRectangle /* Some one time initialisation code. */ COLOR_MAP global_trans_table; create_trans_table(&global_trans_table, my_palette, 128, 128, 128, NULL); ... if (get_color_depth() == 8) color_map = &global_trans_table; else set_trans_blender(128, 128, 128, 128); draw_trans_sprite(buffer, ghost_sprite, x, y);
makeacol32
wow |
gnolam
Member #2,030
March 2002
![]() |
piccolo strikes again! Seriously, that's the clumsiest way to draw rectangles in Allegro that I've ever seen. -- |
cameron
Member #8,219
January 2007
|
gnolam, yes, i am. this is my second game ever. (first was pong) i have a lot to learn. piccolo i am confused as to how to use that.. (and why not just use rectfill() ) and thanks for all the help guys. |
gnolam
Member #2,030
March 2002
![]() |
Implement that. Please. Friends don't let friends do rest() timing. -- |
Kikaru
Member #7,616
August 2006
![]() |
Exactly! Timed game loops saved two of my best games from the recycle bin! |
cameron
Member #8,219
January 2007
|
gnolam, i have implemented the counter as you suggested, still not sure what to do in relation to the black-transparency screen problem. i looked at the docu, i guess i just don't know enough about allegro and it's functions to mess with it yet. thanks guys. oh, and what is the primary benefits to doing this counter over rest()? |
gnolam
Member #2,030
March 2002
![]() |
Quote: gnolam, i have implemented the counter as you suggested, still not sure what to do in relation to the black-transparency screen problem. i looked at the docu, i guess i just don't know enough about allegro and it's functions to mess with it yet. Well, what's the problem? Quote: thanks guys. oh, and what is the primary benefits to doing this counter over rest()? The timer-based method actually works. rest() will, at best, work on one computer - yours. -- |
Kikaru
Member #7,616
August 2006
![]() |
Rest works like this: //loop took 5 milliseconds rest(20) //rest for 20 milliseconds //total time: 25 milliseconds Timed Loops work like this: //loop took 5 milliseconds while (timer < loop_start+20){}; //waits until it was been at least 20 //milliseconds since the START of the loop //total time: 20 milliseconds
|
LennyLen
Member #5,313
December 2004
![]() |
Quote:
//loop took 5 milliseconds That's providing of course the loop takes 5 miliseconds, which it won't on all machines. Which is why you don't use rest() for timing.
|
cameron
Member #8,219
January 2007
|
thanks for the explanation. I'm now rest()-free. il update you on the black screen thing tomorrow.. i'm off to bed. |
Evert
Member #794
November 2000
![]() |
Quote: 1. a black rectangle at 50% opacity should fill the entire screen An old-school (and cheap) way of getting this effect is to use dithering: turn alternate pixels black in a checkerboard pattern. If your resolution is high enough, the difference is not noticable unless you look closely. You could even make this an option. |
piccolo
Member #3,163
January 2003
![]() |
that can be done something like this.
edited wow |
Evert
Member #794
November 2000
![]() |
Nope - that masks out alternate scanlines (and can therefore be optimised considerably). That could also work to achieve the same effect though.. |
piccolo
Member #3,163
January 2003
![]() |
yeah i fix the color from 255 0 255 to 0 0 0 wow |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
A lot of the video cut scenes from mid-90's games such as Tomb Raider I used alternate scan lines to improve frame rate, it'd look much better with higher resolutions but still a bit dark. In other words, half the scan lines were black and built to stay that way. They all watch too much MSNBC... they get ideas. |
Kikaru
Member #7,616
August 2006
![]() |
Quote: That's providing of course the loop takes 5 milliseconds, which it won't on all machines. Which is why you don't use rest() for timing.
It's called an "example". |
LennyLen
Member #5,313
December 2004
![]() |
Quote: It's called an "example". I'm aware of that. But your example doesn't explain very well why not to use rest().
|
ImLeftFooted
Member #3,935
October 2003
![]() |
Anything wrong with taking a screenshot of the game, tinting it, and displaying that? As for code that will do this... ugh.. (/me goes to lookup random source code...) Alright found it. Heres some code i found in old code and (lucky you) rewritten for your uses! // If howMuch is 1, dest is turned black. If howMuch is 0, dest is left unchanged void shade(BITMAP *dest, float howMuch) { const int val = (int)(howMuch * 0xff); set_trans_blender(0xff, 0xff, 0xff, val); drawing_mode(DRAW_MODE_TRANS, 0, 0, 0); rectfill(dest, 0, 0, dest->w, dest->h, makeacol32(0xff, 0xff, 0xff, val)); drawing_mode(DRAW_MODE_SOLID, 0, 0, 0); } Shesh I spend more time writing code in this little a.cc textbox then I do anywhere else. Example usage:
|
gnolam
Member #2,030
March 2002
![]() |
Quote: Anything wrong with taking a screenshot of the game, tinting it, and displaying that? It's much more work than just drawing a DRAW_MODE_TRANS rectfill() over the buffer? [EDIT] Quote: rectfill(dest, 0, 0, dest->w, dest->h, makeacol32(0xff, 0xff, 0xff, val)); ... and that alpha is completely unnecessary. -- |
ImLeftFooted
Member #3,935
October 2003
![]() |
The docs don't really say so I just put the alpha value everywhere I could. Never actually tested which one is actually used. |
|