Graphics in Borland C++ 5.02

Posted on 2005-04-23
Last Modified: 2012-06-27
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?
Question by:bijuabraham
    LVL 22

    Assisted Solution

    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.  

    LVL 3

    Accepted Solution

    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

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
    This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now