Mail Archives: djgpp/1996/12/29/21:00:54
Once upon a time (on 28 Dec 96 at 20:38) Joshua Boyd said:
> I am having trouble with this program. It is supposed to draw an x
> in the middle of the screen. I am trying to write my own graphics
> library, witch is what is contained in the file graphics.h, then the
> small program is contained in temp.c. Any help would be
> apprecieated. This was written using djgpp.
You don't write what problems exactly you have, but I have spotted
three of them:
1. (depends on point of view):
void putpixel (int x, int y, int color) {
virt_screen[x*320+y]=color;
}
In this function you reverse the coordinate system of the PC GFX
screen: (0,0) is located at the top-left corner and X axis goes
right with Y axis going down. The calculation of the pixel's location
should be [x+320*y].
2. You probably want the "Hello world" strings
printf("Hello World");
while (getch() != 'a') {}
printf("Hello World");
while (getch() != 'a') {}
vga256 ();
to appear before entering the GFX mode. The reason why you can't see
them is that stdout (the standard output stream which 'printf()'
uses) is buffered (like all the 'standard' streams). You have two
ways to resolve the problem: either flush the stream by calling
'fflush(stdout)' or put it into unbufferred mode. The second method
is better:
setvbuf(stdout, NULL, _IONBF, 0);
printf("Hello World");
this resolves the problem.
3. The reason why you don't see anything on the GFX screen is that
you're putting the pixels with a color value of '0', which in PC
means 'background color'. No matter what is your background color you
will never see anything when putting pixel in that color on the
'bare' background.
putpixel (158,98,0);
should be. e.g.
putpixel (158,98,15);
After applying these changes you will see your gfx on screen (you
will have to recalculate the coordinates also ;-))
###########################################################
We're terminal cases that keep taking medicine pretending
the end isn't quite that near. We make futile gestures,
act to the cameras with our made up faces and a PR smiles.
And when the angel comes down to deliver us, we'll find out
after all we're only men of straw.
----
Visit http://ananke.amu.edu.pl/~grendel
- Raw text -