r/GraphicsProgramming • • 24d ago

Question Is there an online C++ OpenGL compiler that shows graphics output?

Hi everyone!

I'm a beginner learning C++, OpenGL, and GLUT for my university course.

Setting everything up on Windows takes a lot of time, especially when switching PCs.

Is there any online compiler where I can write C++ OpenGL/GLUT code, run it, and see the graphics output directly in my browser?

I'd appreciate any suggestions. Thanks!

11 Upvotes

37 comments sorted by

4

u/arthurno1 23d ago

Setting everything up on Windows takes a lot of time

No, it does not, it takes literally like 5 minutes max.

Install msys2. Once you have run the installer, upen ucrt64 console and run:

pacman -S --needed mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-freeglut

That will install all you need.

You write your code in a text editor of your choice and type

gcc myprog.c && ./a.out

Than you can typically bring you through the entire course. You can automate with a shell script or a makefile in like 5 - 10 lines.

Test:

#include <GL/freeglut.h>

void display(void) {
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_TRIANGLES);
        glColor3f(1.0f, 0.0f, 0.0f); glVertex2f(-0.5f, -0.5f);
        glColor3f(0.0f, 1.0f, 0.0f); glVertex2f( 0.5f, -0.5f);
        glColor3f(0.0f, 0.0f, 1.0f); glVertex2f( 0.0f,  0.5f);
    glEnd();
    glFlush();
}

int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(500, 500);
    glutCreateWindow("Minimal OpenGL");
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}

Run:

gcc main.c -lfreeglut -lopengl32 -lglu32
./a.out

GLUT is fine for learning in a course, it is what it was basically invented for. Good decision by your teacher.

I'd appreciate any suggestions.

Something tells me you want, but there it is.

1

u/Antagonin 18d ago

I'm just going to say it. Fuck MSYS

1

u/arthurno1 18d ago

msys2 == pacman for Windows <3 :-).

1

u/Antagonin 18d ago

If only it were just a installer. It's a compability layer, adding tons of unnecessary runtime overhead, that mingw doesn't have.

1

u/arthurno1 18d ago

Yes, but mingw gives you just GCC, and GCC only. msys2 gives you Arch Linux on Windows, and the point was to have something easy and fast to install, since Op was complaining about slow, complex install. The above will give him working compiler and GLUT in less than 5 minutes, unless he is on a 56k modem.

There are easy to install mingw distributions too; just copy small bunch of binaries and off you go, no? You can go with this one for example.

But I don't see what is the problem; you can just add bin and lib folders to your PATH in Windows, and you don't have to use the provided compatibility layer in form of a working bash, coreutils and other *nix tools made easily available and usable. You don't need to install everything either. Just install ucrt64 and tools you need. Few megabytes on hard drive are literally nothing. The convenience you get: pacman -S someapp, just as in Arch is in my opinion worth few megabytes of software on the harddrive. Hard drive space is still cheap :).

13

u/Syracuss 24d ago

Set up a git project, have it fetch the dependencies in a cmake script (or whatever build system you prefer, cmake is just very common), and push it to github or some other place where you can store your project accessibly.

Everything else is a workaround to an environment problem you will need to learn to navigate anyway. If you're unwilling to learn this step right now prompt an LLM to do it for you, or preferentially ask a teacher at your uni, I'm fairly certain they are willing to guide you.

At work I jump between OS's and machines within the day depending on tasks, it's something you'll have to learn eventually and the suggestions here so far are trying to solve your problem with new processes that aren't useful long term.

3

u/Otherwise_Meat1161 23d ago

make a template and use that, all you need is a CMAKE, submodule GLFW/SDL and your very own GLAD.h with the extensions you need, make a main.cpp and upload it to your github.

btw its not that difficult to setup compared to lets say vulkan where you will just be spending a day or two just getting the device and queues and buffers etc.

5

u/Bellaedris 24d ago

...... WebGL?

1

u/EC36339 23d ago

C++?

2

u/pjmlp 23d ago

Emscripten?

2

u/EC36339 23d ago

OP's problem is that the toolchain is too complicated, so adding more tools is not the solution.

1

u/VagueHorizon_ 23d ago

Which semester course is this ?

2

u/5H_RIZVI 23d ago

The course name is Computer Graphics, and I am currently in the 8th semester

2

u/_Wolfos 24d ago

I doubt it. You can probably write a Powershell script that sets up the environment automatically though.

2

u/pjmlp 23d ago

Making a configuration with CMake and vcpkg , would make it relatively easy.

Here a random example,

https://github.com/jukehtinen/opengl-starter

2

u/VictoryMotel 23d ago

If you are learning opengl and c++ at the same time you will need to compile a program that runs opengl stuff eventually. Lots of people use glfw if you have a choice.

If you want to learn and experiment with opengl faster in a more forgiving way, it will be a lot easier to use webgl for trial and error then take that experience and use it with C++.

2

u/[deleted] 24d ago

Check a tool called "apitrace". It is a protocol analyzer that spies the connection between your running program and your GPU by intercepting library calls to OpenGL DLL.

You can capture a session and then reproduce the log frame by frame and call by call, like a debugger.

1

u/corysama 23d ago

So, you are moving around between shared Windows PCs at school. What is expected to be pre-installed on those PCs? Surely you are not expected to learn programming by downloading and installing a compiler every time you sit down at a computer?

-7

u/EC36339 23d ago

Claude Code can compile your C++ code and run it directly in the Linux container your session runs in. But it will only be able to use software rendering and show you screenshots of it.

Setting everything up on Windows is something an AI agent can either do for you or walk you through. I recommend the second alternative so you learn something. Then have it all written down in a text file, so in case you have to do it again, you can automate it the next time.

Ignore the haters who might tell you, you won't learn anything without pain and effort. Pain doesn't help you learn, it only slows you down and exhausts you.

1

u/5H_RIZVI 23d ago

Thanks! The issue is that our university PCs are shared, so logging into AI tools isn't ideal for security reasons. Also, our teacher won't accept AI tools for showing the output. I need something that directly runs my C++/GLUT code and displays the graphics.

0

u/EC36339 23d ago

You're learning GLUT at university? What year is it, 2006? If you have a choice, switch to GLFW for your mental sanity.

Also, I'm confused. I thought this was about setting things up on your own (Windows) PC. Are you sharing computers or also accounts?

1

u/5H_RIZVI 23d ago

Haha, I know GLUT is outdated, but unfortunately our teacher uses it for the entire course, including lectures and assignments, so we don't really have a choice.

And yes, we're sharing university PCs, not accounts. We don't have fixed seats, so we use different PCs almost every day. Even if I set everything up on one PC, the next time I use it, things might have been removed or uninstalled.

That's why I'm looking for a simple website where I can just paste my C++/GLUT code, hit Run, and show the graphical output without setting anything up.

1

u/EC36339 23d ago

If you log in with your own account and user profile, it shouldn't be a problem to access your own Github account. Store your files and scripts there, problem solved.

1

u/arthurno1 23d ago edited 23d ago

GLUT is fine for learning; that is what it is invented for. You school has probably already installed what you need. Ask your friends who take the course with you, I am quite sure you are not the only person taking the course, and the course is probably not given the first time. Your school probably also has some guide or a link to suitable guide if you want to install compiler and glut on your own computer. Ask the course assistant or your professor, it is their job to help you.

2

u/Typical-NonPC 23d ago

You fail to understand that the point of university is to learn, especially in engineering fields. So, having an AI tool do everything that you should be learning is incredibly bad advice. Tools doing everything for you is seriously damaging to learning.

1

u/arthurno1 23d ago

What you fail to understand is that asking people online is not different than asking LLM?

If Op wanted to learn he would have looked online, the same question was asked when I learned opengl at Uni in 90's with GLUT. I am sure their school have some guide they point students to so they can do the exercises on their own computers, since nowadays everyoneo has a laptop.

1

u/Typical-NonPC 23d ago

I don't understand the point of your reply in the slightest. I was replying to someone who basically told the OP to let AI do everything for them rather than learn what needs to be done. So, you vastly misinterpreted what I said.

My point was not that you shouldn't use AI in general, but the way that this person said to use it, is bypassing learning for favor of quick results. Getting a result without understanding is NOT learning.

1

u/arthurno1 23d ago

I don't understand the point of your reply in the slightest.

Because you don't want. I am sure the person could answer to you: "I don't understand the pointer of your replay in the slightest. My point was just to tell the person to setup the environment with AI. The course is about graphics, not installing tools."

Anyway, the guy was not directly interesting in learning anyway. He could have just typed into google "how do I install gcc and glut on windows" and gemini will wrote step by step instructions to learn from. Here is the answer he would got:

To install GCC and GLUT (via FreeGLUT) on Windows, the easiest and most modern method is to use MSYS2 for the GCC compiler and FreeGLUT for the OpenGL/GLUT libraries.

Step 1: Install GCC via MSYS2

  1. Download and run the installer from the MSYS2 Official Website.
  2. Open the MSYS2 UCRT64 terminal from your Windows Start menu.
  3. Run the following command to update the package database and core system files:bash pacman -Syu Använd koden med försiktighet. (If it asks you to close and reopen the terminal, do so and rerun the command).
  4. Install the GCC toolchain and make utilities by running:bash pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain Använd koden med försiktighet.
  5. Add the MSYS2 binary path to your Windows Environment Variables (PATH): • Default path to add: C:\msys64\ucrt64\bin
  6. Verify the installation by opening a new Command Prompt or PowerShell window and typing:cmd gcc --version g++ --version Använd koden med försiktighet.

Step 2: Install GLUT (FreeGLUT)

Because original GLUT is obsolete, modern Windows development uses FreeGLUT compatible with MinGW-w64:

  1. Download the precompiled FreeGLUT MinGW development package from TransmissionZero FreeGLUT or via MSYS2 directly.
  2. If using MSYS2, you can install FreeGLUT directly inside the UCRT64 terminal using pacman:bash pacman -S mingw-w64-ucrt-x86_64-freeglut Använd koden med försiktighet.
  3. If installing manually from a downloaded archive: • Copy the header files (.h files like glut.h) into your MinGW include directory: C:\msys64\ucrt64\include\GL
    • Copy the library files (.a or .lib files) into: C:\msys64\ucrt64\lib
    • Copy the DLL (freeglut.dll or glut32.dll) into C:\msys64\ucrt64\bin\ or directly next to your compiled .exe file.

Step 3: Compiling a Program with GCC and GLUT

When compiling a C/C++ file that uses GLUT and OpenGL via gcc, include the necessary linker flags: bash gcc source.c -o program.exe -lfreeglut -lopengl32 -lglu32 Använd koden med försiktighet. Are you setting this up inside a specific editor like Visual Studio Code, Code::Blocks, or just running it from the command line? Tell me your setup and I can give you the exact build configuration.

It took literally two seconds to do that, much shorter than creating a reddit post. It is attention seeking post. The Reddit has scramble it a bit, but in a browser he gets clickable links and nicely inlined step by step instructions.

-8

u/Major_Chocolate2441 24d ago

There's Emabarcadero which you can keep on a stick. I set it up with 7z rather than double clicking the installer though. Download Claude and say you need a drag and drop Settings file for Embarcadero on your stick. And you intend to keep libraries (OpenGL, GLUT, etc.) in a Libs folder under Embarcadero and you'll keep your projects there also under a Projects folder.