0

Regarding this thread How do I use graphics.h in Ubuntu? , I executed the following program(shown below the block), but the program unfortunately ends automatically after a few seconds with the following message :

$ gcc -o DDA.o DDA.c -lgraph
$ DDA.o
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
DDA.o: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.

#include <graphics.h>
#include <stdio.h>
#define ROUND(a) ((int) (a+0.5))
#include <X11/Xlib.h>

main()
{
    int gd = DETECT,gm,left=100,top=100,right=200,bottom=200,x=300,y=150,radius=50;
    initgraph(&gd,&gm,NULL);
    rectangle(left, top, right, bottom);
    circle(x, y, radius);
    bar(left + 300, top, right + 300, bottom);
    line(left - 10, top + 150, left + 410, top + 150);
    ellipse(x, y + 200, 0, 360, 100, 50);
    outtextxy(left + 100, top + 325, "C Graphics Program");
    delay(5000);
    closegraph();
    return 0;
}

PS: I HATE PROGRAMMING IN TC++(USING DOSBOX). IF YOU DON'T KNOW THE SOLUTION THEN PLEASE RECOMMEND ME SOMETHING WHERE I CAN SAFELY RUN MY GRAPHICS PROGRAMS IN C ON :)

0

As I studied the programming language C/C++ we did use a library called Allegro, which seemed to be a good & easy library to do graphics programming in.

http://liballeg.org/

0

You have to call initgraph function inside your C graphics program by passing the path of your BGI library(Borland graphics interface) to initialize graphics driver. It initializes the graphics system by loading the passed graphics driver then changing the system into graphics mode. It also resets or initializes all graphics settings like color, palette, current position etc, to their default values.

driverDirectoryPath : It specifies the directory path where graphics driver files (BGI files) are located. If directory path is not provided, then it will seach for driver files in current working directory directory. Check this sample program http://www.techcrashcourse.com/2015/08/c-program-draw-circle-graphics.html

-1

You can add the following function before closing the graph to see the stable output. It worked for me!

void wait_for_char() {

//Wait for a key press
int in = 0;

while (in == 0) {
    in = getchar();
}

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.