Author Topic: [Bug or Feature?] _RGB & _RGBA issues with CONST  (Read 163 times)

[Bug or Feature?] _RGB & _RGBA issues with CONST
« on: May 08, 2019, 07:10:41 AM »
Hi guys
while I'm trying to code with QB64 version 1.3 96937f0  I have got this issue....
about CONST and _RGB / _RGBA

well CPR (copy->paste->run) this code

Code: QB64 [Select]
  1. CONST YVel = 5, Hscreen = 400, Wscreen = 600, Rball = 10, MaxBall = 10
  2.  
  3. DIM Yball(1 TO MaxBall) AS INTEGER, A AS LONG, W AS INTEGER, CountBall AS INTEGER
  4. A = _NEWIMAGE(Wscreen, Hscreen, 32)
  5. IF A < -2 THEN SCREEN A ELSE PRINT "Error in Screen setup"
  6. CONST Blu = _RGBA(0, 0, 255, 255), Green = _RGBA(0, 255, 0, 255)
  7.  
  8.     K = INKEY$
  9.     CLS
  10.     LOCATE 1, 1: PRINT " press Space to shoot, Esc to quit      Countball="; CountBall
  11.     PRINT " to test the issue press space while balls arrive to the top of screen"
  12.     FOR W = 1 TO MaxBall STEP 1
  13.         IF Yball(W) > 0 THEN
  14.             CIRCLE (400, Yball(W)), Rball, Blu
  15.             PAINT STEP(0, 0), Blu, Blu
  16.             LINE (200 - 1, Yball(W) - 1)-STEP(Rball + 2, Rball + 2), Green, B
  17.             LINE (200, Yball(W))-STEP(Rball, Rball), Blu, BF
  18.  
  19.             Yball(W) = Yball(W) - YVel
  20.             IF Yball(W) <= 0 THEN IF CountBall > 0 THEN CountBall = CountBall - 1
  21.         END IF
  22.     NEXT W
  23.     IF K = " " THEN
  24.         IF CountBall < MaxBall THEN
  25.             CountBall = CountBall + 1
  26.             Yball(CountBall) = (Hscreen - (2 * Rball))
  27.         END IF
  28.     END IF
  29.     _LIMIT 10
  30. LOOP UNTIL K = CHR$(27)
  31.  

as you can see assignation has been made after SCREEN settings to avoid  this issue https://www.qb64.org/forum/index.php?topic=1322.msg105258#msg105258 but _RGB and _RGBA are not avaiable to be used with CONST...
as the same wiki says at CONST page http://qb64.org/wiki/CONST

Questions:
 why has it been projected in this manner?
 Why can I use CONST value of colors only with 32bit screen and related functions (_RGB32 and _RGBA32)?

Thanks to read and for feedbacks

Re: [Bug or Feature?] _RGB & _RGBA issues with CONST
« Reply #1 on: May 09, 2019, 02:43:45 AM »
CONST executes before your program runs, so it won't be in any screen mode at the time.  Using _RGB32 or _RGBA32 forces it to use 32bit colour codes, otherwise I think _RGB and _RGBA will use SCREEN 0 text mode colours.

Re: [Bug or Feature?] _RGB & _RGBA issues with CONST
« Reply #2 on: May 09, 2019, 12:25:08 PM »
Thanks Raven_Singularity

if it is so, the only way to set colors as costants is to use the work of Steve. It seems that I remember a COLOR.BI file.

Re: [Bug or Feature?] _RGB & _RGBA issues with CONST
« Reply #3 on: May 16, 2019, 02:39:25 AM »
Thanks Raven_Singularity

if it is so, the only way to set colors as costants is to use the work of Steve. It seems that I remember a COLOR.BI file.

What do you mean?

Just use:

CONST Yellow = _RGBA32(255, 255, 0, 255)

That saves the 32bit colour value.

Re: [Bug or Feature?] _RGB & _RGBA issues with CONST
« Reply #4 on: May 17, 2019, 08:50:22 AM »
Hi Raven_Singularity
Thanks for your reply

to explain better my point of view

just as you said
Quote
CONST Yellow = _RGBA32(255, 255, 0, 255)

That saves the 32bit colour value.
so I can have in my code a CONST colorXXX

If I use a SCREEN legacy settings I cannot use _RGB32 or RGBA32 indeed I must use _RGB or _RGBA
because these last functions return the closest color attribute number as wiki says
Quote
The value returned is either the closest color attribute number or a 32-bit _UNSIGNED LONG color value.
.

Well in this case I cannot use a CONST colorXXX because these two last functions need a SCREEN legacy set before giving value of color.
It seems to remember that Steve has built a file of settings for this goal.

Good Coding

Offline Petr

  • The best code is the DNA of the hops.
Re: [Bug or Feature?] _RGB & _RGBA issues with CONST
« Reply #5 on: May 17, 2019, 10:00:50 AM »
I've done some experiments in this direction and my conclusion is that _RGB returns a value depending on the color palette used in the 256 color screen. This is not necessary for a 32-bit screen and therefore _RGB returns the same value as _RGB32 in a 32-bit screen.

Code: [Select]
CONST sed~& = _RGBA32(155, 12, 127, 255)
sed2~& = _RGB(155, 12, 127)

PRINT sed~&
PRINT sed2~&
SLEEP

SCREEN 13
sed2~& = _RGB(155, 12, 127)
PRINT sed~&
PRINT sed2~&
SLEEP


FOR f = 0 TO 255
    _PALETTECOLOR f, RND * 255
NEXT
sed2~& = _RGB(155, 12, 127)
PRINT sed~&
PRINT sed2~&
SLEEP
SCREEN _NEWIMAGE(1024, 768, 32)
sed2~& = _RGB(155, 12, 127)
PRINT sed~&
PRINT sed2~&

Offline SMcNeill

  • QB64 Developer
Re: [Bug or Feature?] _RGB & _RGBA issues with CONST
« Reply #6 on: May 17, 2019, 02:42:30 PM »
I've done some experiments in this direction and my conclusion is that _RGB returns a value depending on the color palette used in the 256 color screen. This is not necessary for a 32-bit screen and therefore _RGB returns the same value as _RGB32 in a 32-bit screen.


_RGB returns the closest posible color match *for the current screen mode*, unless one is specified.  Try this:

Code: [Select]
SCREEN 0
r1 = _RGB(255, 0, 0)
SCREEN 13
r2 = _RGB(255, 0, 0)
SCREEN _NEWIMAGE(600, 400, 32)
r3 = _RGB(255, 0, 0)
PRINT r1
PRINT r2
PRINT r3


Re: [Bug or Feature?] _RGB & _RGBA issues with CONST
« Reply #7 on: May 17, 2019, 09:38:00 PM »
TempodiBasic, what exactly are you trying to accomplish?

If you set a 32bit colour CONST, and then try to use it in a non-32bit mode, it will simply zap it at that point to the nearest colour in the current screen palette.

But if you're not trying to use a 32bit colour code, what's the point?  There are only 256 or 16 or whatever colours, why would you need constants?  Just use the number, or just do: CONST Blue = 1


Again, what are you trying to accomplish overall with your code?

Re: [Bug or Feature?] _RGB & _RGBA issues with CONST
« Reply #8 on: May 18, 2019, 01:42:13 PM »
Hi Raven_Singularity

Thanks for time spent for me

this solve my theorical issue

Quote
If you set a 32bit colour CONST, and then try to use it in a non-32bit mode, it will simply zap it at that point to the nearest colour in the current screen palette.