Learning a Graphics API

Started by
8 comments, last by BBeck 7 years, 4 months ago

Hello forum!

I'm tending to learn a Graphics API/library. My experience is limited to SFML 2.

OpenGL and Vulcan come to mind. Direct3D is not really in my interest, as it is platform dependent.

Finding tutorials for OpenGL seems to be a struggle on its own, especially when looking for something fresh like 4.5.

There are so many things for OpenGL, some tutorials seem to use libraries that comprehend for features that got removed (GLM for some fixed functions?).

Additionally, there is GLSL that seems to be another language using OpenGL, GLEW and GLFW...

I know that GLSL is used for shaders. SFML's openGL context permits using GLSL to create effects and such.

Could somebody explain what the rest are? I probably need some way to invoke OpenGL into my code.
SFML seems to be able to do that but then again, I want to learn OpenGL and not how SFML uses OpenGL.

Many posts about how-to-learn OpenGL also state that there are no good books or tutorials. Did that change?

About Vulcan, read that it is more low-level than OpenGL. Some say, it might be the future but others say, as OpenGL will continued to be developed, both will co-exist.

I think, it is healthier to first learn OpenGL then? Would my knowledge carry over to Vulcan?

Thanks for taking your time to read my thread : )!

Advertisement

Have a look at my website on the graphic API section. http://www.gamedevpensieve.com/graphics/graphic-api

The OpenGl section contains some link to tutorials.

@spinningcubes | Blog: Spinningcubes.com | Gamedev notes: GameDev Pensieve | Spinningcubes on Youtube

Additionally, there is GLSL that seems to be another language using OpenGL, GLEW and GLFW...

GLSL is GL's shader language.
"Shaders" are the parts of your code that actually run on the GPU - GL2/D3D9 had "fixed function" GPU code, where you could tell it how to draw something. But GL3/4/D3D11 require the "how" of every operation to be described with shader code.
D3D/GL are a high level API that let you send data and "commands" to the GPU (such as "fill the pixels that are covered by these triangles"). Shaders contain the actual instructions that the GPU will perform within each high-level command (e.g. "colour each pixel by comparing its normal to the lighting direction"). Another way to think of a shader is that it's a callback that gets exectued for each pixel/vertex that the GPU processes. You can't write these callbacks in C/C++ -- GL requires you to write them in GLSL and D3D requires you to write them in HLSL.

some tutorials seem to use libraries that comprehend for features that got removed (GLM for some fixed functions?).

GL/D3D don't come with a math library, so GLM is a decent math library (that works in D3D and GL), which is designed to look like GLSL math code... so it's a good fit for a GL programmer.

SFML seems to be able to do that but then again, I want to learn OpenGL and not how SFML uses OpenGL.

SFML/SDL/GLFW help do a lot of the "boiler plate" work, such as initializing OpenGL, creating a Window (portably between OS's), handling mouse clicks/etc... SFML/SDL also have their own drawing functions (GLFW doesn't), but you don't have to use them. Once GL is initialized and you have a window, you can ignore SFML/SDL and just write your own GL code.
Alternatively you can avoid SFML/SDL/GLFW altogether and create your own window and initialize GL yourself manually.

Large parts of OpenGL don't actually exist in the gl.h header file. It's up to you to write the headers yourself by carefully reading the spec, then asking the OS to fetch function pointers from the driver for you and then casting them to the right types... which is insane to do manually. GLEW does that job for you.

About Vulcan, read that it is more low-level than OpenGL. Some say, it might be the future but others say, as OpenGL will continued to be developed, both will co-exist. I think, it is healthier to first learn OpenGL then? Would my knowledge carry over to Vulcan?

Yes. Vulkan/D3D12 are extremely low-level GPU API's, whereas OpenGL/D3D11 are "normal" GPU APIs. I would definately recommend learning OpenGL/D3D11 first, and yes, once you learn one GPU programming API, learning a second one will be much easier as all the concepts carry over.

OpenGL and Vulcan come to mind. Direct3D is not really in my interest, as it is platform dependent.

FWIW:

OpenGL is a single specification for Windows/Mac/Linux, but in reality it's at least 7 different libraries that all try to behave the same: NVidia Windows, NVidia Linux, AMD Windows, AMD Linux, Intel Windows, Intel Linux, Apple MacOS... In reality, they won't behave the same, so it's important to test your application on all 7 versions of "OpenGL". Apple is the only sane platform where a single party dictates the implementation, instead of it changing with each GPU vendor...

OpenGL|ES is the same thing for Android and iPhone... except there's hundreds of different android implementations of OpenGL|ES. There's also no alternative to GL|ES on Android, which is why doing graphics programming on Android is a circle of hell.

D3D is specified by and implemented by Microsoft - so like OpenGL on MacOS, it's actually stable and works the same across all vendors. It's also used on Windows and Xbox - so for a game developer targeting Windows+Xbox+PS4, it's actually more portable than OpenGL is :o

Other platforms (Playstation, Nintendo) use their own APIs that are neither GL or D3D - so a professional graphics programmer is forced to learn a lot of different graphics APIs.

MacOS / iPhone also have "Metal", which is better than GL/GLES, so most engines will use D3D on Windows, Metal on Mac/iPhone, GL on Linux, GLES on Android and other proprietary API's on consoles... so at the pro level, GL's portability benefit is negated :(

If you don't have the manpower to support umpteen API's and only care about Windows/Mac/Linux though, then GL's portability will be useful for you, as long as you're ok testing on multiple GPU's as mentioned above.

Wow, thanks a lot!

OpenGL is a single specification for Windows/Mac/Linux, but in reality it's at least 7 different libraries that all try to behave the same: NVidia Windows, NVidia Linux, AMD Windows, AMD Linux, Intel Windows, Intel Linux, Apple MacOS... In reality, they won't behave the same, so it's important to test your application on all 7 versions of "OpenGL". Apple is the only sane platform where a single party dictates the implementation, instead of it changing with each GPU vendor...

There is no abstraction that does this for me? Probably not, since the behaviour is not predictable?

I know there exists no "write once, run it everywhere", but the idea to manually test whether a GPU interprets my code the same... sounds really harsh. I just got very curious about shaders and all those interesting topics (reflections, lighting, ..) and thought learning a graphics API would be valuable.

I always thought that OpenGL is supported by most modern GPUs and therefore should work the same, haha. Supported seems to be a stretchy term.

Nonetheless, thanks for all these bits of information!

There is no abstraction that does this for me?

I always thought that OpenGL is supported by most modern GPUs and therefore should work the same, haha. Supported seems to be a stretchy term.

OpenGL is the abstraction!

I'm exaggerating a little because I like to beat up OpenGL :D If you make sure to follow the spec yourself, then you'll mostly be ok...

Most problems occur when you do something wrong in your code, and NVidia will tolerate your incorrect code and render what you want to see, while Intel will get confused by your incorrect code and render something else, and AMD will crash at the sight of your incorrect code.

Making sure to always check for failures/errors (after calling a GL function that can fail) will help you avoid most of these situations and find any problems in you code.

e.g. if you have a bug in your GLSL code, one GPU might accept your code and work anyway, while another GPU might crash.

To avoid this problem in GLSL, you should use the reference compiler to check your shaders for errors.

Unfortunately there's no reference / validation layer for OpenGL itself, so it's best to check on AMD/Intel/NVidia hardware manually :(

You can think of OpenGL kinda like HTML, and a GPU like a web-browser. Most of the time it doesn't matter which browser you are using, but occasionally you'll find that a website looks fine in Firefox and is broken in Internet Explorer :(

I'm a bit old fashioned, but in your case I'd buy a book and start from there. Here's the first hit I get on Amazon:
https://www.amazon.com/gp/aw/d/B01ITNCBU6/ref=mp_s_a_1_1?ie=UTF8&qid=1479216370&sr=8-1&pi=AC_SX236_SY340_QL65&keywords=opengl+4.5&dpPl=1&dpID=51%2BPU9SC-QL&ref=plSrch

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

I think you are going to find out eventually that 'learning' OpenGL doesn't really gain you anything, and that I mean, its just an API, learning OpenGL in the sense of the word meaning learning the API. The API by itself does not do anything beside provide a mean for HW accelerated rendering. The fundamentals is what you are after, or what I would suggest you learn as those are not tied to any specific API. 'Learning' OpengGL does not teach you lighting, tranforms, shaders and other graphic techniques. OpenGL is just one means to express those techniques, so if that is your goal then I suggest you rethink your approach. Learning the fundamentals will give you more breadth of knowledge, and then when it comes to the application/expression, you'll find that you have more choice in what API to use to achieve your goal, instead of pigeonholing yourself to say I'm just going to learn this one thing.

cgrant, yes, you are probably right! I rather want to understand how to express my graphical necessities in general instead of a certain API.
Which of course includes studying those areas.

Let me maybe rephrase my intention: Is there an easy way to display shaders, reflections/lighting, ... so I get that job done of sub-elements (window context, models to test lighting on, ...) and can concentrate on how the logic works?
Maybe as in working in a sandbox? Applying GLSL-ish effects on pre-generated dolls and being able to try myself at providing a rendering procedure of that doll?
An engine could suffice. Though they would deny myself the chance to go onto lower levels. What if I want to implement the rendering for such a generic doll just to learn on how to work with vertices and such in 3D?
Are there any such environments? I somewhat doubt it : /

What if I want to implement the rendering for such a generic doll just to learn on how to work with vertices and such in 3D? Are there any such environments? I somewhat doubt it : /
https://github.com/bkaradzic/bgfx

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Check out http://learnopengl.com/. It seems to be a really good place to start learning OGL.

This topic is closed to new replies.

Advertisement