I
IvoShalev
Hi there,
I just want to give some sudgestions on how to draw some plain things
only using the header file <graphics.h> and of course the standart
files <stdio.h> <conio.h> <stdlib.h>.
First of All you have to load drivers for the graphic.
-You must have the file EGAVGA.BGI to be in the same directory where
your code is.
-with this driver you will have 640/480 resolution with 16 colors 1
page or you can choose 320/280 16col with 2 video pages.
- to load the graphic driver we use the function -> initgraph(int
gdriver, int gmode, const char *path);
gdriver is the type of driver we'll use ( VGA ) gmode is the mode
(VGAMID - 640/480) and path is a string with the path to the file
EGAVGA.BGI ("" usualy).
At the end : initgraph(VGA, VGAMID, "");
to check for errors you can use the function -> graphresult(); it
returns int; if its != from grOK then there is an error.
Now you can draw something:
-to choose color type: setcolor(colnum); where "colnum" is the number
of a color between 0 and 15
-background color setbkgcolor(colnum); - || - || -
-draw a line -> line(x1,y1,x2,y2); x1,x2, coordinates of the first and
second point of the line - how left or right to be (between 0 and 640),
y1,y2 how up or down to be (between 0 and 480)
EX: line(0,0,640,480); - diagonal line from the up left corner to the
down right corner.
-rectangle -> rectangle(x1,y1,x2,y2); like line but draws a rectangle
witch diagonal is the line(x1,y1,x2,y2)
-a dot(pixel) -> putpixel(int x,int y, unsigned col); x,y - the
coordinates of the pixel, col - the color
- text -> outtextxy(int x,int y,const char *Text); x,y - the
coordinates and Text-the string to be printed
At the end we close the graphic mode with the function closegraph();
-----------------------------------------------------------------------------------------------------------------------------------------------
a simple Program
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
int gdriver = VGA, gmode=VGAMID, errorcode;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
for(int i=0; i<100; i++)
{
setcolor((i % 15) +1);
line(i*6, 0, 640-i*3, 480);
}
/* clean up */
getch();
closegraph();
return 0;
}
www.pegashometour.com
yours Ivo
I just want to give some sudgestions on how to draw some plain things
only using the header file <graphics.h> and of course the standart
files <stdio.h> <conio.h> <stdlib.h>.
First of All you have to load drivers for the graphic.
-You must have the file EGAVGA.BGI to be in the same directory where
your code is.
-with this driver you will have 640/480 resolution with 16 colors 1
page or you can choose 320/280 16col with 2 video pages.
- to load the graphic driver we use the function -> initgraph(int
gdriver, int gmode, const char *path);
gdriver is the type of driver we'll use ( VGA ) gmode is the mode
(VGAMID - 640/480) and path is a string with the path to the file
EGAVGA.BGI ("" usualy).
At the end : initgraph(VGA, VGAMID, "");
to check for errors you can use the function -> graphresult(); it
returns int; if its != from grOK then there is an error.
Now you can draw something:
-to choose color type: setcolor(colnum); where "colnum" is the number
of a color between 0 and 15
-background color setbkgcolor(colnum); - || - || -
-draw a line -> line(x1,y1,x2,y2); x1,x2, coordinates of the first and
second point of the line - how left or right to be (between 0 and 640),
y1,y2 how up or down to be (between 0 and 480)
EX: line(0,0,640,480); - diagonal line from the up left corner to the
down right corner.
-rectangle -> rectangle(x1,y1,x2,y2); like line but draws a rectangle
witch diagonal is the line(x1,y1,x2,y2)
-a dot(pixel) -> putpixel(int x,int y, unsigned col); x,y - the
coordinates of the pixel, col - the color
- text -> outtextxy(int x,int y,const char *Text); x,y - the
coordinates and Text-the string to be printed
At the end we close the graphic mode with the function closegraph();
-----------------------------------------------------------------------------------------------------------------------------------------------
a simple Program
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
int gdriver = VGA, gmode=VGAMID, errorcode;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
/* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
for(int i=0; i<100; i++)
{
setcolor((i % 15) +1);
line(i*6, 0, 640-i*3, 480);
}
/* clean up */
getch();
closegraph();
return 0;
}
www.pegashometour.com
yours Ivo