Author Topic: >16 colors in 80-column text mode?  (Read 4438 times)

0 Members and 1 Guest are viewing this topic.

Offline ZapJackson

  • Newbie
  • Posts: 10
    • View Profile
>16 colors in 80-column text mode?
« on: July 14, 2018, 03:16:56 pm »
I apologize if I'm just misreading the documentation, but is there a way to get more than 16 colors in text mode without switching to the 40-column square character shape of screen 13?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: >16 colors in 80-column text mode?
« Reply #1 on: July 14, 2018, 03:52:00 pm »
Hi.

Try this:

Code: QB64: [Select]
  1. FOR r = 0 TO 255
  2.     FOR g = 0 TO 255
  3.         FOR b = 0 TO 255
  4.             COLOR _RGB(r, g, b)
  5.             PRINT "Color:"; r; g; b
  6. NEXT b, g, r
  7.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: >16 colors in 80-column text mode?
« Reply #2 on: July 14, 2018, 04:01:00 pm »
you can create any size for screen 0  with SCREEN _NEWIMAGE (column, row, 0)

FellippeHeitor

  • Guest
Re: >16 colors in 80-column text mode?
« Reply #3 on: July 14, 2018, 05:53:12 pm »
@ZapJackson:
You can get all possible RGB combinations assigned to any of the 16 available attributes of screen 0 using _PALETTECOLOR. This way you can use the _RGB32 function as in:

Code: QB64: [Select]
  1. PRINT "This is printed in color 9, which maps to bright blue in the default VGA palette;"
  2. PRINT "Hit a key..."
  3. _PALETTECOLOR 9, _RGB32(218, 165, 32) 'reassigns index 9 with Goldenrod color values
  4. PRINT "But now color 9 is Goldenrod."
  5.  

But you'll still be limited to 16 attributes, 0 to 15. If you want to use *any* color in the 32bit color space, you can switch to graphics mode using _NEWIMAGE. The snippet below creates an 800x600 canvas in 32bit color mode:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)

This way you can use _RGB32 directly and use all possible combinations of Red, Green and Blue components:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. COLOR _RGB32(255, 255, 255), _RGB32(218, 165, 32)
  3. PRINT "This is bright white over goldenrod."
  4.  



@Petr:
Your code snippet above will only use the existing 16 colors of SCREEN 0, except you're using the _RGB function to select which of the attributes looks *closer* to the RGB values you give. That doesn't really use all possible colors.
« Last Edit: July 14, 2018, 05:54:31 pm by FellippeHeitor »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: >16 colors in 80-column text mode?
« Reply #4 on: July 15, 2018, 05:57:16 am »
I am sorry, its my fail.

Offline keybone

  • Forum Regular
  • Posts: 116
  • My name a Nursultan Tulyakbay.
    • View Profile
Re: >16 colors in 80-column text mode?
« Reply #5 on: July 16, 2018, 03:31:48 am »
so unless you want backwards compatibility with DOS QBASIC/QuickBasic you can do the following

Code: QB64: [Select]
  1.  
  2. DIM foregroundColor AS _UNSIGNED LONG
  3. DIM backgroundColor AS _UNSIGNED LONG
  4.  
  5. foregroundColor = _RGBA32(255,255,255,255)
  6. backgroundColor = _RGBA32(0,0,0,255)
  7.  
  8. COLOR foregroundColor, backgroundColor
  9.  
that might not be entirely correct cuz i wrote it off the top of my head without testing it.
the point is, if youre not going for backwards compatibility, you can just pick a resolution,
set a 32-bit screen mode, and use it in (fake) text-mode. The end user would see no difference other than more colors.


I am from a Kazakhstan, we follow the hawk.