Qbasicnews.com
July 02, 2020, 01:39:10 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: darken  (Read 4837 times)
andy
Senior Member
**
Posts: 175



WWW
« on: October 17, 2003, 08:49:18 AM »

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.
Logged

eminiscing about trapezoids in conjunction with stratospherical parabolas:

No questions asked.

www.stickskate.com
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #1 on: October 17, 2003, 10:55:07 AM »

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.......
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Xyphos
New Member

Posts: 6



WWW
« Reply #2 on: October 17, 2003, 11:24:06 AM »

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    Cheesy
Logged

model tiny
.386
.stack 200h
jmp start
msg db 'Hello, World!$'
start:
push ds
push cs
pop ds
mov ah,9
mov dx,offset msg
int 21h
pop ds
mov ax,4c00h
int 21h
end
toonski84
__/--\__
*****
Posts: 2567



« Reply #3 on: October 17, 2003, 03:52:35 PM »

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.
Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Dav
Administrator
Ancient Guru
*****
Posts: 709



WWW
« Reply #4 on: October 17, 2003, 06:17:39 PM »

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
Logged

na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #5 on: October 17, 2003, 06:19:40 PM »

Quote from: "toonski84"
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=DacRegistersInScreenNine

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)
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
toonski84
__/--\__
*****
Posts: 2567



« Reply #6 on: October 17, 2003, 06:34:55 PM »

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.
Logged

i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #7 on: October 17, 2003, 09:38:36 PM »

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 Tongue 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.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #8 on: October 18, 2003, 04:10:23 AM »

RelGammaBlock ;*)
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
andy
Senior Member
**
Posts: 175



WWW
« Reply #9 on: October 18, 2003, 01:22:09 PM »

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.
Logged

eminiscing about trapezoids in conjunction with stratospherical parabolas:

No questions asked.

www.stickskate.com
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #10 on: October 19, 2003, 03:44:25 PM »

Which version are you using? qb 1.1?
Logged
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #11 on: October 19, 2003, 07:33:53 PM »

You can't use "."s in your arrays unless you define a TYPE for it. It's got nothing to do with the version...

Code:
TYPE PalType
  Red AS INTEGER
  Green AS INTEGER
  Blue AS INTEGER
END TYPE

DIM Pal(1 TO 64) AS PalType

' yada yada...

Pal(1).Red = 63
Pal(1).Green = 45
'......
Logged

andy
Senior Member
**
Posts: 175



WWW
« Reply #12 on: October 20, 2003, 04:34:46 AM »

I think I'm using v1.1.
It came with windows 3.11 about nine years ago.
Logged

eminiscing about trapezoids in conjunction with stratospherical parabolas:

No questions asked.

www.stickskate.com
TheBigBasicQ
*/-\*
*****
Posts: 4550



WWW
« Reply #13 on: October 20, 2003, 02:56:22 PM »

Ah, then try to download qb 4.5 or 7.1. It is a *lot* better than 1.1

http://www.qbcafe.net/english/dl_pages/compiler/qbasic.html
Logged
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #14 on: October 20, 2003, 04:45:45 PM »

How about a nice, direct link: http://homepages.ihug.co.nz/~twotowers/software/qb45.zip Wink
Logged

Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!