[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3500
  • Last Modified:

Graphics in Borland C++ 5.02

I'm using Borland C++ 5.02. I have no experience with graphics. And I checked out the help file, and got an example for graphics

#include <graphics.h>
#include <io.h>
#include <fcntl.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <process.h>
#include <alloc.h>

 void  *gothic_fontp; /* points to font buffer in memory */
 int handle;          /* file handle used for I/O */
   unsigned fsize;    /* size of file (and buffer) */

   int errorcode;
   int graphdriver;
   int graphmode;

     /* open font file */

   handle = open("GOTH.CHR", O_RDONLY|O_BINARY);
   if (handle == -1)
     printf("unable to open font file 'GOTH.CHR'\n");
     /* find out size of the file */
   fsize = filelength(handle);
     /* allocate buffer */
   gothic_fontp = malloc(fsize);
   if (gothic_fontp == NULL)
     printf("unable to allocate memory for font file 'GOTH.CHR'\n");
     /* read font into memory */
   if (read(handle, gothic_fontp, fsize) != fsize)

     printf("unable to read font file 'GOTH.CHR'\n");
     /* close font file */
     /* register font */
   if (registerfarbgifont(gothic_fontp) != GOTHIC_FONT)
     printf("unable to register font file 'GOTH.CHR'\n");
     /* detect and initialize graphix */
   graphdriver = DETECT;
   initgraph(&graphdriver, &graphmode, "..");
   errorcode = graphresult();
   if (errorcode != grOk)

     printf("graphics error: %s\n",grapherrormsg(errorcode));

   settextjustify(CENTER_TEXT, CENTER_TEXT);
   settextstyle(GOTHIC_FONT, HORIZ_DIR, 4);
   outtextxy(getmaxx()/2,getmaxy()/2, "Borland Graphics Interface (BGI)");
    /* press a key to terminate */
    /* shut down graphics system */

But i get an error :  BGI graphics not supported under windows
What should i do to make it work properly?
2 Solutions
I'd forget about using the old BGI graphics...  BGI was barely passable under DOS.   And if you're writing a real windows 32-bit application, in it you're not allowed to write directly to the screen buffer, so BGI is impossible.

Real windows graphics are about 10,000% spiffier.  

to make it work you should compile it as a console program with the -tC (target console) switch and then start in dos and see if it works.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now