0

I want to learn graphics.h to do some graphics (I know it's outdated and everything). I'm currently working on WSL (Windows Subsystem for Linux) with Ubuntu, and cannot use Linux or create a virtual machine for various reasons.

The problem I'm facing is that after installing correctly (supposedly) graphics.h on my WSL using the instructions here, when I try to execute sample code, it compiles without errors or warnings.

However, when I execute it, it quickly shows these characters:

Screenshot

... before going black until it ends and closes itself regularly. The problem is that it should create a new window with the animation, but it just writes these characters and goes black for a few seconds, without giving any sort of error.

I realize it could be that since I'm working on WSL, the terminal can't open a new window. Is that the case, or what is the problem? How can I make it show the new window? For reference this is the code I'm running:

#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
int main()
{
    int gd = DETECT, gm;
    initgraph(&gd, &gm, NULL);
 
    circle(50, 50, 30);
 
    delay(500000);
    closegraph();
    return 0;
}
NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
sonod4
  • 9
  • 2
  • 2
    Graphics.h is the front end for a DOS graphics library. Since you are running on a Windows Machine with, at this point minimal, ties to old DOS, why are you trying to pull Linux into this instead of using one of the more common Windows Ports of the library? You're making life harder on yourself. – user4581301 Apr 06 '22 at 19:23
  • 1
    That said, here's something reasonably well supported and should run on Modern Windows and Linux alike: http://libxbgi.sourceforge.net/ – user4581301 Apr 06 '22 at 19:24
  • @user4581301 that is true, but I'd prefer to polish my skills on linux, since it also allows things like terminal commands like 'make', or separate compilation, that on windows would be a hassle to do on the terminal. Thanks for the link! I'll check it right away. – sonod4 Apr 06 '22 at 19:34
  • Understood. For later though, [look into msys2](https://stackoverflow.com/questions/30069830/how-to-install-mingw-w64-and-msys2). They've unhassled the command line build process and provide a very impressive collection of tools and libraries. – user4581301 Apr 06 '22 at 20:24
  • I concur, use MSYS2. It gives you the best of both worlds: you'll learn how to use linux terminal, AND you'll be able to produce windows executables. – HolyBlackCat Apr 08 '22 at 17:16
  • Forget about `graphics.h` though. If you know it's outdated, why use it? Use something like SDL, which is just as simple, but is modern enough. – HolyBlackCat Apr 08 '22 at 17:17
  • It's `wsl` (Windows subsystem for Linux), not `wls` (windows linux subsystem) as you continuously use wrongly – phuclv Apr 08 '22 at 18:12
  • @sonod4 Apologies for my horrible answer (now deleted). I should have read your question more closely. Are you using Windows 10 or Windows 11? I just ran through the steps on the link you mentioned and have been able to run the code successfully on WSL2/WSLg on Windows 11. I'm using Ubuntu 20.04, 20.04 and I did have to (a) install `libesd0-dev` from the Xenial repos, and (b) configure with `--disable-guile`. I'm assuming that you had to do the same? – NotTheDr01ds Apr 11 '22 at 03:32

0 Answers0