Independent running of C/C ++ graphics programs

Source: Internet
Author: User

The C/C ++ language provides a wealth of graphic functions. The graphic function file is graphics. h. Before using graphical functions, you must set the screen to the graphical mode. The C/C ++ language provides the following functions:
Void far initgraph (INT far * GD, int far * GM, char * P );

GD and GM represent the graphic drivers respectively.ProgramAnd graphical mode. P indicates the directory path where the graphic driver is located.

The graphic driver is provided by Borland Corporation (for Turbo C and Borland C ++), and the C/C ++ language also provides the function closegraph () for exiting the graph state. The format is:
Void far closegraph (void );

Maybe you often write some graphics programs in C/C ++ language, but you cannot run them independently from the C/C ++ language environment. How can we solve this problem? The following describes how to run a graphical program independently:

1. Convert the driver egavga. BGI to the target file egavga. OBJ:
C:/TC> bgiobj egavga

In the same way, convert the font file *. CHR to the target file *. OBJ:

C:/TC> bgiobj trip
C:/TC> bgiobj Litt
C:/TC> bgiobj sans
C:/TC> bgiobj goth

2. Add the OBJ file created above to the graphics. Lib library file. The specific method is as follows:

C:/TC> tlink C:/TC/lib/graphics. Lib + egavga
C:/TC> tlink C:/TC/lib/graphics. Lib + trip
C:/TC> tlink C:/TC/lib/graphics. Lib + Litt
C:/TC> tlink C:/TC/lib/graphics. Lib + sans
C:/TC> tlink C:/TC/lib/graphics. Lib + goth

You can also use tlib and prj programs to replace tlink.

3. before calling the initgraph () function in a program, add the following statement:
Registerbgidriver (egavga-driver );

It notifies the Connection Program to load the egavga driver into the user's execution program, and also adds the following statement before loading the font file:
Registerbgifont (font file name );

4. After the above processing, the compiled connected execution program can run in any directory. In this case, the function that initializes the screen to the graphic mode can be rewritten:

Void initgra (void)
{Int GD = detect, GM;
Registerbgidriver (egavga_driver );
Registerbgifont (triplex_font );
Registerbgifont (small_font );
Registerbgifont (sansserif_font );
Registerbgifont (gothic_font );
Initgraph (& GD, & GM ,"");
}

Follow these steps to run the graphics program independently.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.