Thanks for the example, but it wasn't quite _exactly_ what I was looking
for. I've attached a file with what I was trying to do (well, for the
most part). I haven't quite got a smooth transition to and from
green: it uses 6 bits while red and blue use 5, so I increment and
decrement green by 1.5, since its max value is 0x2f, (~1.5 * 0x1f)...but
is' not smooth...
On Tue, 11 Jul 2000, Sergio Masci wrote:
> > This is another generic graphics programming question, but hopefully
> > someone will know the answer.
> >
> > How do I iteratate through the colors? It seems like it should be simple,
> > but it's not behaving as expected. I'm writing a little something that
> > draws a color wheel on the screen at 800x600x64K. Just for kicks, suppose
> > that it's just drawing vertical lines, so the code looks like this:
> >
> > ...
> > color = 0;
> > for (xnow = 0; xnow < xmax; xnow++)
> > gl_line(xnow,0,xnow,ymax,color++);
> > ...
> >
> > I come up with about 13 identical sections of color fading.
> > the same happens if I do
> >
> > vga_setcolor(color++);
> > vga_drawline(xnow,0,xnow,ymax);
> >
> >
> > Is there a way that I can do what I am trying simply?
> >
> > Regards,
> >
> > -patrick
>
>
> I don't use the gl libraries or the vga_setcolor or vga_drawline
> functions so I cannot give a concrete answer BUT it looks to me as
> though the colour is a direct copy of the hardware pixel used in the
> 800x600x64K mode. In this mode the colours are packed into a 16 bit word
> something like 6:5:5 or 6:6:4 I cannot remember exactly.
>
> Try experimenting with the following:
>
> float fx, fy, fz;
> int x, y
> red, green, blue, pixel;
>
> for (x=0; x<800; x++)
> {
> for (y=0; y<600; y++)
> {
> fx = (float)x / 799;
> fy = (float)y / 599;
> fz = sqrt(x * x + y * y) / sqrt(799*799 + 599*599);
>
> red = 0x2f * fx;
> blue = 0x1f * fy;
> green = 0x1f * fz;
>
> pixel = (red << 10) | (green << 5) | blue;
>
> vga_setcolor(pixel);
> vga_drawline(x,y,x,y);
> }
> }
>
> You should end up with a box, one corner of which should be black,
> diagnally opposit will be white, one other corner should be blue and the
> last should be red (no pure green since this component is generated from
> blue and red and so does not exist in this square without them).
>
> Regards
> Sergio
>
#include <stdlib.h>
#include <stdio.h>
#include <vga.h>
#include <vgagl.h>
#define RGB(r,g,b) ((((int)(r) & 0x1f) << 11) | (((int)(g) & 0x2f) << 5) | ((int)(b) &
0x1f))
int main(int argc, char *argv[])
{
GraphicsContext *context;
int mode = G800x600x64K;
int x,y;
int xmax,ymax;
int midx,midy;
float r,g,b;
float color;
vga_init();
vga_setmode(mode);
gl_setcontextvga(mode);
context = gl_allocatecontext();
gl_getcontext(context);
xmax = vga_getxdim();
ymax = vga_getydim();
midx = xmax / 2;
midy = ymax / 2;
r = (float)0x1f;
g = b = 0.0;
x = y = 0;
for (b = 0.0; b < (float)0x1f; b += 1.0) {
color = RGB(r,g,b);
gl_line(midx,midy,x,0,color);
x += 3;
}
for (; g < 0x2f; g += 1.5) {
color = RGB(r,g,b);
gl_line(midx,midy,x,0,color);
x += 3;
}
for (; r > 0.0; r -= 1.0) {
color = RGB(r,g,b);
gl_line(midx,midy,x,0,color);
x += 3;
}
for (; b > 0.0; b -= 1.0) {
color = RGB(r,g,b);
gl_line(midx,midy,x,0,color);
x += 3;
}
for (; r < (float)0x1f; r += 1.0) {
color = RGB(r,g,b);
gl_line(midx,midy,x,0,color);
x += 3;
}
for (; b < (float)0x1f; b += 1.0) {
color = RGB(r,g,b);
gl_line(midx,midy,x,0,color);
x += 3;
}
for (; b > 0.0; b -= 1.0) {
color = RGB(r,g,b);
gl_line(midx,midy,x,0,color);
x += 3;
}
for (; g > 0.0; g -= 1.5) {
color = RGB(r,g,b);
gl_line(midx,midy,x,0,color);
x += 3;
}
getchar();
printf("\n");
vga_setmode(TEXT);
return 0;
}