OpenGL is not object-oriented, but more like "switches you turn on"?


list_id = glGenLists(1);
glNewList(list_id, GL_COMPILE);

It seems like one's turning on switches on some machine which is contained somewhere, but it isn't seen as an object in object-oriented sense?

Is there a name for this kind of programming or library paradigm?

I'm using it from C++, but perhaps the way it's used is "C-style"?

  • 5
    $\begingroup$ The code you're quoting there is really old OpenGL! If you're new to the API and just learning, do yourself a favor and learn modern-style OpenGL (at least version 3.3, core profile). The only time you should need to use display lists or glBegin is if you're maintaining or modding apps from 10+ years ago. $\endgroup$
    – russ
    Jul 26, 2018 at 17:04

2 Answers 2


It's generally referred to as a "state machine". It has, as you noticed, a bunch of switches and parameters. All of them are globally accessible to any code that has access to the current context. Your program sets them and then issues draw calls. Anything you don't change, will remain in that state until you do change it.

It is also a Hardware Abstraction. The same OpenGL routines should have roughly the same effect regardless of the hardware it's running on. If you upload 3 vertices for a triangle and then draw them, that should produce similar results on an ATI, Nvidia, or Intel GPU, for example. You don't need machine-specific instructions for each one.


The proper term for this style is called "imperative programming." You would be correct in thinking that it is similar to C because C is classified as an imperative programming language.

For more about the paradigm, you can read about it here: https://en.wikipedia.org/wiki/Imperative_programming

  • 1
    $\begingroup$ By definition, every API in C and C++ is Imperative, since those languages are Imperative. Even OOP is merely a subset of Imperative programming. $\endgroup$ Jul 27, 2018 at 2:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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