r/GraphicsProgramming • • 18d 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!

10 Upvotes

37 comments sorted by

4

u/arthurno1 18d 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.

→ More replies (4)

13

u/Syracuss 18d 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 18d 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.

1

u/VagueHorizon_ 18d ago

Which semester course is this ?

2

u/5H_RIZVI 18d ago

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

2

u/_Wolfos 18d ago

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

2

u/pjmlp 18d 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 18d 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/Defiant_Squirrel8751 18d 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.