Say I have a game, and when I pause it, I want the entire screen become darker, so the image is still there but darker. and in the middle I want a box with a message in to apperar in th normal brightness, how can I do this. Please help.
If you're using all 256 colors on the screen at the same time, you can't do that. Otherwise you go through all the colors except those you want to use for the box and divide their rgb values by two... using PALETTE.............................
Otherwise................. you can use ugl's alpha blending thingo... if you're doing it in ugl.......
Sorry...... details are........ bad.......
I assume this is QB and you are using 256 colors?
Code:
DEFINT A-Z
Type PalType
Red As Integer
Green As Integer
Blue As Integer
End Type
Dim Shared Pal(255) As PalType, I% As Integer
SUB Pause (BrightColor%)
'Special Thanks to Xyphos for this routine.
'He is the greatest programmer in the world!!!
' (^.^)
For I% = 0 To 255 'Number Of Colors
If I% <> BrightColor% Then 'Make sure we don't modify the Brighter Color.
'Fetch current color attributes for this color
Out &H3C7, I% 'Write VGA, The color to be read
Pal(I%).Red = Inp(&H3C9) 'Get Red, Green and Blue
Pal(I%).Green = Inp(&H3C9)
Pal(I%).Blue = Inp(&H3C9)
'Now write this color back as halved.
Out &H3C8, I% 'Write VGA, The color to be written
Out &H3C9, Pal(I%).Red \ 2
Out &H3C9, Pal(I%).Green \ 2
Out &H3C9, Pal(I%).Blue \ 2
END IF
NEXT I%
' < YOUR MESSAGE CODE GOES HERE >
' < SOME TYPE OF CONTROLED LOOP GOES HERE >
'Now restore everything
For I% = 0 to 255
Out &H3C8, I% 'Write VGA, The color to be written
Out &H3C9, Pal(I%).Red
Out &H3C9, Pal(I%).Green
Out &H3C9, Pal(I%).Blue
NEXT
' Viola! such a masterpiece!
END SUB
' sorry if the code is a little buggy, but I do know the vast secreats of programming
You're not limited to 256 color modes or even VGA modes to use a palette fade. On a VGA card, using OUT to modify the palette is effect on colors 0-4 in text mode, and 0-7 in EGA modes. In screen 12, a vga mode with 16 colors, you can modify every color on the pallete.
Here's a little something that should work on 256 color modes. If you are using mode 12h or an EGA, find all the little "255"s and change them to the highest color you can modfiy.
Code:
DECLARE SUB fadein (pal() AS ANY, steps!)
DECLARE SUB fadeout (pal() AS ANY, steps AS INTEGER)
DECLARE SUB getpal (pal() AS ANY)
TYPE pal
r AS INTEGER
g AS INTEGER
b AS INTEGER
END TYPE
SCREEN 13
DIM pal(0 TO 255) AS pal
FOR x = 0 TO 255
LINE (x, 0)-(x, 199), x
NEXT x
getpal pal()
SLEEP
fadeout pal(), 200
SLEEP
fadein pal(), 200
SUB fadein (pal() AS pal, steps)
FOR y = 1 TO steps
OUT &H3C8, 0
FOR x = 0 TO 255
OUT &H3C9, (pal(x).r / steps) * y
OUT &H3C9, (pal(x).g / steps) * y
OUT &H3C9, (pal(x).b / steps) * y
NEXT x
NEXT y
END SUB
SUB fadeout (pal() AS pal, steps AS INTEGER)
FOR y = 1 TO steps
OUT &H3C8, 0
FOR x = 0 TO 255
OUT &H3C9, pal(x).r - (pal(x).r / steps) * y
OUT &H3C9, pal(x).g - (pal(x).g / steps) * y
OUT &H3C9, pal(x).b - (pal(x).b / steps) * y
NEXT x
NEXT y
END SUB
SUB getpal (pal() AS pal)
OUT &H3C7, 0
FOR x = 0 TO 255
pal(x).r = INP(&H3C9)
pal(x).g = INP(&H3C9)
pal(x).b = INP(&H3C9)
NEXT x
END SUB
if you want help understanding it, or you want to modify it to suit your needs, just reply and I will tell.
on a side note, for those who care: this is just a sad testament to how much perl has corrupted me. I need to return multiple values, arrays and hashes in an inefficient manner, it's a sick, disgusting, perform-hogging trait of my programming of late, but I could never turn back.
Had this little snippet at my fingers. This uses OUT as well.
Code:
'TRANSBOX.BAS
'Simple Transparent box routine
DEFINT A-Z
DECLARE SUB TRANSBOX (x1%, y1%, x2%, y2%, clr%)
SCREEN 13
'draw some lines
FOR i% = 1 TO 200
LINE (RND * 319, RND * 199)-(RND * 319, RND * 199), RND * 255
NEXT
TRANSBOX 40, 40, 80, 80, 33
SUB TRANSBOX (x1%, y1%, x2%, y2%, clr%)
FOR i% = 239 TO 255: OUT 968, i%
OUT 969, r%: r% = r% + clr% / 16
OUT 969, g%: g% = g% + clr% / 16
OUT 969, B%: B% = B% + clr% / 16
NEXT
REDIM TT(255) AS INTEGER
FOR i% = 0 TO 255: OUT 967, i%
TT(i) = 239 + ((INP(969) + INP(969) + INP(969)) / 4) / 63 * 16
NEXT
DEF SEG = &HA000
offset& = y1% * 320&
FOR y% = y1% TO y2%
FOR x% = x1% TO x2%
POKE offset& + x%, TT(POINT(x%, y%))
NEXT
offset& = offset& + 320
NEXT
DEF SEG
LINE (x1%, y1%)-(x2%, y2%), 255, B
END SUB
Here's a little 'fake' trans box routine I have using PUT instead. It's not that great looking, put it might be worth posting too:
Code:
DEFINT A-Z
SCREEN 13
FOR x% = 1 TO 320 STEP 2
FOR y% = 20 TO 180 STEP 2
PSET (x%, y%), RND * 22
NEXT
NEXT
LOCATE 25, 15: PRINT "PRESS A KEY";
A$ = INPUT$(1)
'Translucent window
REDIM Image&(0 TO 6800) 'Use 16000 for whole screen
GET (50, 50)-(270, 170), Image& 'Store Screen
LINE (50, 50)-(270, 170), 33, BF 'Fill in a dark area
PUT (50, 50), Image&, AND 'Merge or Impose Image (AND/OR)
'AND makes darker windows
LINE (50, 50)-(270, 170), 22, B 'Give it a Border
LINE (51, 51)-(269, 169), 55, B 'Give it a Border
A$ = INPUT$(1) 'Pause......
PUT (50, 50), Image&, PSET 'Restore Screen Image
SLEEP
- Dav
Quote:You're not limited to 256 color modes or even VGA modes to use a palette fade. On a VGA card, using OUT to modify the palette is effect on colors 0-4 in text mode, and 0-7 in EGA modes.
(again) In fact, you can change every colour in every mode:
http://faq.qbasicnews.com/?blast=DacRegi...ScreenNine
This applies to text mode and SCREEN 9.
In Screen 7 and Screen 8 you have to OUT &H3C8,0-7 for colours 0-7 and OUT &H3C8,16-23 for colours 8-15 (note : add 8 ).
Code:
' Palette in SCREEN 7 - 8
SUB SetDAC78 (reg%, r%, g%, b%)
IF reg%>7 THEN reg%=reg%+8
OUT &H3C8, reg%
OUT &H3C9, r%
OUT &H3C9, g%
OUT &H3C9, b%
END SUB
Code:
' Palette in SCREEN 0, SCREEN 9
SUB SetDAC09 (reg%, r%, g%, b%)
PALETTE reg%, reg%
OUT &H3C8, reg%
OUT &H3C9, r%
OUT &H3C9, g%
OUT &H3C9, b%
END SUB
(Toonsk, I think I explained this to you in a previous post... May I be mistaken)
Oh, wow. I need to read mesages more closely. You want to leave everything but area darker. In that case, you have a few options:
1) Use an RGB table to find RGB matches closest to the palette's current selection (memory consuming).
2) Fake a 332 RGB palette, that is use 3 bytes for red, and 3 bytes for green and 2 for blue, and you can span the entire spectrum with only 256 colors (crummy quality).
3) use an overlapping palette (good if you're clever)
There really isnt a perfect way to do this, you just have to play with illusion tricks. Number 3 works the best in my honest opinion, but it would be potentially slow.
I dont know.
I'm confused, could you explain this in more detail?
EDIT: Yeah, nate, I didn't know you could go above 7 in EGA modes. Thanks for enlightening me, I was going off previous experiences.
Well, I had the same prob. When I first coded "Jill" I did it with no libs and in SCREEN 7. I discovered that by mistake, but
oh, most good discovers have been by mistake.
As for the topic, what I would do is something that is implied in some of the replies above: I'd pick up some colours that I'd only use for messages and GUI, and would not use them in any graphics so when I wanted to darken screen as explained I'd only darken the remaining colours, leaving the GUI colours untouched.
The best way would be using a hicolour or truecolour palette and overlay a translucent black box, but I guess you're using Mode 13h so don't mind.
Thanks, I tred xyphos's first and it works fine. I had to change some things like I had to define the arays, and pal(i%).red etc, was not allowed I had to change it to palred(i%) as my version of qbasic will not allow "periods" or in english dots. Anyway thaks to everyone who posted.