Changing colors

342 views
Skip to first unread message

mtmigs

unread,
Aug 25, 2017, 6:13:21 PM8/25/17
to Harbour Users
I have found the "set color to" and SETCOLOR() for changing the color of the screen. My problem is I want an orange screen and neither of those have orange. I know graphic cards with color depth of more the 4 bits can produce a nice orange color. Is there some other way to set the screen colors with a bigger selection?

Paul Smith

unread,
Aug 26, 2017, 6:13:00 AM8/26/17
to Harbour Users
Hello Mtmigs

I have used Hb_gtinfo( HB_GTI_PALETTE,n,n ) to change palate colors
I'll attach some code that changes color 12 (normally red ) to an orange type color 
compile test.prg with

hbmk2 test hbwin.hbc - run

Cheers
Paul






*:*********************************************************************
*:
*:        Program: TEST.PRG
*:  Procs & Fncts: MAIN()
*:               : RGB()
*:               : SET_ORANGE()
*:
*:*********************************************************************

*!*********************************************************************
*!
*!      Procedure: MAIN()
*!
*!          Calls: SET_ORANGE()   (function  in TEST.PRG)
*!
*!*********************************************************************
PROCEDURE MAIN()

#include "hbwin.ch"
#include "hbgtinfo.ch"
Hb_gtinfo( HB_GTI_WINTITLE, "Test Colours" )

Setmode(25,80)
CLEAR
set_orange()


*-----  DISPLAY COLORS

SET COLOR TO 0
@ 05 ,25 SAY REPLICATE(CHR(219),10)
SET COLOR TO 1
@ 06 ,25 SAY REPLICATE(CHR(219),10)
SET COLOR TO 2
@ 07 ,25 SAY REPLICATE(CHR(219),10)
SET COLOR TO 3
@ 08 ,25 SAY REPLICATE(CHR(219),10)
SET COLOR TO 4
@ 09 ,25 SAY REPLICATE(CHR(219),10)
SET COLOR TO 5
@ 10 ,25 SAY REPLICATE(CHR(219),10)
SET COLOR TO 6
@ 11 ,25 SAY REPLICATE(CHR(219),10)
SET COLOR TO 7
@ 12 ,25 SAY REPLICATE(CHR(219),10)
@ 05 ,35 SAY " 0"
@ 06 ,35 SAY " 1"
@ 07 ,35 SAY " 2"
@ 08 ,35 SAY " 3"
@ 09 ,35 SAY " 4"
@ 10, 35 SAY " 5"
@ 11 ,35 SAY " 6"
@ 12 ,35 SAY " 7"

SET COLOR TO 8
@ 05 ,43 SAY REPLICATE(CHR(219),10)
SET COLOR TO 9
@ 06 ,43 SAY REPLICATE(CHR(219),10)
SET COLOR TO 10
@ 07 ,43 SAY REPLICATE(CHR(219),10)
SET COLOR TO 11
@ 08 ,43 SAY REPLICATE(CHR(219),10)
SET COLOR TO 12
@ 09 ,43 SAY REPLICATE(CHR(219),10)
SET COLOR TO 13
@ 10 ,43 SAY REPLICATE(CHR(219),10)
SET COLOR TO 14
@ 11 ,43 SAY REPLICATE(CHR(219),10)
SET COLOR TO 15
@ 12 ,43 SAY REPLICATE(CHR(219),10)

SET COLOR TO 7
@ 05 ,54 SAY " 8"
@ 06 ,54 SAY " 9"
@ 07 ,54 SAY "10"
@ 08 ,54 SAY "11"
@ 09, 54 SAY "12 orange"
@ 10 ,54 SAY "13"
@ 11 ,54 SAY "14"
@ 12 ,54 SAY "15"
INKEY(0)

*!*********************************************************************
*!
*!       Function: RGB()
*!
*!      Called by: SET_ORANGE()   (function  in TEST.PRG)
*!
*!*********************************************************************
FUNCTION rgb

PARAMETERS R, G, b
RETURN ( R + ( G * 256 ) + ( b * 256 * 256 ) )

*!*********************************************************************
*!
*!       Function: SET_ORANGE()
*!
*!      Called by: MAIN()         (procedure in TEST.PRG)
*!
*!          Calls: RGB()          (function  in TEST.PRG)
*!
*!*********************************************************************
FUNCTION set_orange

#include "hbgtinfo.ch"

Hb_gtinfo( HB_GTI_PALETTE,12,rgb( 255,  153,   0 ) )

*----- set the color

// "15" rgb( 180, 180, 180 ) 15 W+  +white
// "14" rgb( 192, 144,   0 ) 14 GR+ yellow
// "13" rgb(  96,  96, 192 ) 13 RB+ +magenta
// "12" rgb( 255, 153,   0 )  12 R+  +red
// "11" rgb(   0, 164, 164 )  11 BG+ +cyan
// "10" rgb( 126, 126, 126 )  10 G+  +silver
// "9" rgb(    0, 96,  192 )  9 b+  +blue
// "8" rgb(  155, 155, 155 )  8 N+  gray
// "7" rgb(  155, 155, 155 )  7 W   white
// "6"  rgb(  96,  96,   0 )  6 GR  olive
// "5"  rgb(  20,   0,  60 )  5 RB  magenta
// "4"  rgb( 255,  53,   0 )  4 R   red
// "3"  rgb(   0,  96,  96 )  3 BG  cyan
// "2"  rgb(   0,  96,   0 )  2 G   green
// "1"  rgb(   0,  48, 108 )  1 b   blue
// "0"  rgb(   0,   0,   0 )  0 N   black


*: EOF: TEST.PRG

mtmigs

unread,
Aug 29, 2017, 9:58:29 AM8/29/17
to Harbour Users
Thank you for the test program. It seems I do not have hbwin. Where can I find it?

mtmigs

unread,
Aug 29, 2017, 5:24:02 PM8/29/17
to Harbour Users
I do not have the hbgtinfo.ch file on my system so your test program does not compile. I found documentation for a similar function vgapalette(). It seems to exist, or at least it does not give an error while compiling or running. However, it does not work either.


On Saturday, August 26, 2017 at 5:13:00 AM UTC-5, Paul Smith wrote:

Klas Engwall

unread,
Aug 29, 2017, 6:17:24 PM8/29/17
to harbou...@googlegroups.com
Hi mtmigs,

> I do not have the hbgtinfo.ch file on my system so
> your test program does not compile. I found documentation for a similar
> function vgapalette(). It seems to exist, or at least it does not give
> an error while compiling or running. However, it does not work either.

hbgtinfo.ch has existed in the include directory "forever" and it is
used in dozens of prg files in the harbour source tree, so I find it
very strange that it does not exist on your system. I think you need to
try again.

Regarding your previous question, hbwin.hbc and hbwin.ch exist in the
contrib\hbwin directory since many years. But they are not needed for
Paul's test application, so just comment the header file out of it and
skip the hbwin.hbc file from the commandline. Doing so I had no problems
whatsoever compiling the test.

Regards,
Klas

mtmigs

unread,
Aug 29, 2017, 7:59:41 PM8/29/17
to Harbour Users
I did find the hbgtinfo.ch file and was able to get the compiler to find it also. So now I am able to compile and link the test program I was given. However, it does not seem to work. No matter what rgb value I try to assign to any of the palette colors the colors on the screen (as drawn by the program) are the same. Even if I use Hb_gtinfo( HB_GTI_PALETTE,12,rgb( 0,  0,  0 ) ) the #12 color is still red.

Klas Engwall

unread,
Aug 30, 2017, 2:44:40 PM8/30/17
to harbou...@googlegroups.com
Hi mtmigs,

> I did find the hbgtinfo.ch file and was able to get the compiler to find
> it also. So now I am able to compile and link the test program I was
> given. However, it does not seem to work. No matter what rgb value I try
> to assign to any of the palette colors the colors on the screen (as
> drawn by the program) are the same. Even if I use Hb_gtinfo(
> HB_GTI_PALETTE,12,rgb( 0,  0,  0 ) ) the #12 color is still red.

I get an orange box using Paul's RGB settings, then it reverts back to
red after exiting the program.

Regards,
Klas

mtmigs

unread,
Aug 30, 2017, 5:12:24 PM8/30/17
to Harbour Users

I get an orange box using Paul's RGB settings, then it reverts back to
red after exiting the program.

Regards,
Klas

Hi Klas

My program, in its current form, (which is a modification of Paul's program) sets all colors, 0 throught 15, to black (0). Then it is to displays blocks of each color. When I run the program it just displays the default colors. I do know that the Hb_gtinfo( HB_GTI_WINTITLE, "Test Colours" ) I put at the beginning of my program does change the title on the program's window properly.

I do not know the harbour language (I do some writing in C and C++). I downloaded the harbour source code and I tried looking for at the underlying source code for the Hb_gtinfo function Paul uses to change the color. Ii is a complicated function with what seems to be four different variations in src/rtl/gttrm, src/rtl/gtwin, src/rtl/gtwvt, and src/rtl/gtxwc. Each version does something different.

Are you running your test program under windows (DOS) or Linux?

Klas Engwall

unread,
Aug 31, 2017, 5:28:03 AM8/31/17
to harbou...@googlegroups.com
Hi mtmigs,

> My program, in its current form, (which is a modification of Paul's
> program) sets all colors, 0 throught 15, to black (0). Then it is to
> displays blocks of each color. When I run the program it just displays
> the default colors. I do know that the Hb_gtinfo( HB_GTI_WINTITLE, "Test
> Colours" ) I put at the beginning of my program does change the title on
> the program's window properly.
>
> I do not know the harbour language (I do some writing in C and C++). I
> downloaded the harbour source code and I tried looking for at the
> underlying source code for the Hb_gtinfo function Paul uses to change
> the color. Ii is a complicated function with what seems to be four
> different variations in src/rtl/gttrm, src/rtl/gtwin, src/rtl/gtwvt, and
> src/rtl/gtxwc. Each version does something different.
>
> Are you running your test program under windows (DOS) or Linux?

My environment is Windows 7. From your forward slashes above I suspect
you are running under Linux, right?

The screen/keyboard/mouse handling in Harbour is done by one of the
several GTs that exist (you can see each of their subdirectories in
src\rtl - there is a total of a dozen of them). Each GT generally
supports one OS, but some OSes have several alternatives. The default
under Windows is gtwin, although in my own real applications I use gtwvt.

The hb_GtInfo() function does around 75 different things using the
different first arguments that are listed in hbgtinfo.ch. Not all of
those things are supported by all GTs, it is a matter of what the
underlying OS allows plus what has actually been implemented. There are
some "Supported by" comments in hbgtinfo.ch to help understanding which
settings that do not work everywhere. There is no guarantee that
commenting in the file is complete, but it looks like the palette
setting should be universal.

In the doc directory there is a file gtapi.txt that might give you some
hints regarding GTs in general. It is possible that it is not fully
up-to-date as it has a 1999 date at the top.

Regards,
Klas
Reply all
Reply to author
Forward
0 new messages