Update tgidemo.c - fix misunderstanding about TGI colors
This commit is contained in:
@@ -13,10 +13,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* TGI colors are indices into the default palette. So keep in mind that, if
|
/* Color values passed to TGI functions are indices into the default palette. */
|
||||||
you redefine the palette, those names may no more match the actual colors. */
|
#define COLOR_BACK 0
|
||||||
#define COLOR_BACK TGI_COLOR_BLACK
|
#define COLOR_FORE 1
|
||||||
#define COLOR_FORE TGI_COLOR_WHITE
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@@ -69,35 +68,30 @@ static void DoWarning (void)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note that everywhere else in the TGI API, colors are referred to via TGI_COLOR_
|
* Note that everywhere else in the TGI API, colors are referred to via an index
|
||||||
* color indices, which in turn refer to the default TGI palette.
|
* to the current palette.
|
||||||
*
|
*
|
||||||
* Redefining the colors (changing the palette) is a target dependend operation,
|
* TGI_COLOR_ values can be used (ONLY!) for setting the palette, using them
|
||||||
* and the colors/values in the palette itself are not portable.
|
* with other TGI functions only works by chance, on some targets.
|
||||||
*
|
|
||||||
* That said, for some (perhaps most?) targets, the COLOR_ values may work here.
|
|
||||||
*/
|
*/
|
||||||
static void DoPalette (int n)
|
static void DoPalette (int n)
|
||||||
{
|
{
|
||||||
static const unsigned char Palette[4][2] = {
|
static const unsigned char Palette[4][2] = {
|
||||||
/* FIXME: add some ifdefs with proper values for targets that need it */
|
/* FIXME: add some ifdefs with proper values for targets that need it */
|
||||||
#if !defined(__APPLE2__)
|
#if !defined(__APPLE2__)
|
||||||
{ COLOR_BLACK, COLOR_BLUE },
|
{ TGI_COLOR_BLACK, TGI_COLOR_BLUE },
|
||||||
{ COLOR_WHITE, COLOR_BLACK },
|
{ TGI_COLOR_WHITE, TGI_COLOR_BLACK },
|
||||||
{ COLOR_RED, COLOR_BLACK },
|
{ TGI_COLOR_RED, TGI_COLOR_BLACK },
|
||||||
{ COLOR_BLACK, COLOR_WHITE }
|
|
||||||
#else
|
#else
|
||||||
{ COLOR_WHITE, COLOR_BLACK },
|
{ TGI_COLOR_WHITE, TGI_COLOR_BLACK },
|
||||||
{ COLOR_BLACK, COLOR_WHITE },
|
{ TGI_COLOR_BLACK, TGI_COLOR_WHITE },
|
||||||
{ COLOR_WHITE, COLOR_BLACK },
|
{ TGI_COLOR_WHITE, TGI_COLOR_BLACK },
|
||||||
{ COLOR_BLACK, COLOR_WHITE }
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
tgi_setpalette (Palette[n]);
|
tgi_setpalette (Palette[n]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void DoCircles (void)
|
static void DoCircles (void)
|
||||||
{
|
{
|
||||||
unsigned char I;
|
unsigned char I;
|
||||||
@@ -117,7 +111,9 @@ static void DoCircles (void)
|
|||||||
tgi_ellipse (X, Y, I, tgi_imulround (I, AspectRatio));
|
tgi_ellipse (X, Y, I, tgi_imulround (I, AspectRatio));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
while (kbhit ()) {
|
||||||
|
cgetc ();
|
||||||
|
}
|
||||||
cgetc ();
|
cgetc ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,6 +182,9 @@ static void DoDiagram (void)
|
|||||||
tgi_lineto (XOrigin + X, YOrigin + Y);
|
tgi_lineto (XOrigin + X, YOrigin + Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (kbhit ()) {
|
||||||
|
cgetc ();
|
||||||
|
}
|
||||||
cgetc ();
|
cgetc ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,6 +205,9 @@ static void DoLines (void)
|
|||||||
tgi_line (Min, Min, Min-X, 0);
|
tgi_line (Min, Min, Min-X, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (kbhit ()) {
|
||||||
|
cgetc ();
|
||||||
|
}
|
||||||
cgetc ();
|
cgetc ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,8 +243,7 @@ int main (void)
|
|||||||
|
|
||||||
/* Do graphics stuff */
|
/* Do graphics stuff */
|
||||||
|
|
||||||
/* first uses the default palette */
|
/* use default palette */ DoCircles ();
|
||||||
DoCircles ();
|
|
||||||
DoPalette (0); DoCheckerboard ();
|
DoPalette (0); DoCheckerboard ();
|
||||||
DoPalette (1); DoDiagram ();
|
DoPalette (1); DoDiagram ();
|
||||||
DoPalette (2); DoLines ();
|
DoPalette (2); DoLines ();
|
||||||
|
|||||||
Reference in New Issue
Block a user