Learning modern OpenGL
Asked Answered
C

6

39

I am aware that there were similar questions in past few years, but after doing some researches I still can't decide where from and what should I learn. I would also like to see your current, actual view on modern OpenGL programming with more C++ OOP and shader approach. And get sure that my actual understanding on some things is valid.

So... currently we have OpenGL 4.2 out, which as I read somewhere requires dx11 hardware (what does it mean?) and set of 'side' libraries, to for example create window.

There is the most common GLUT, which I extremely hate. One of main reason are function calls, which doesn't allow freedom in the way how we create main loop. As some people were telling, it was not meant for games.

There is also GLFW, which actually is quite nice and straight-forward to me. For some reason people use it with GLUT. ( which provides not only window initialisation, but also other utilities? )

And there is also SFML and SDL ( SDL < SFML imo ), whereas both of them sometimes need strange approach to work with OGL and in some cases are not really fast.

And we have also GLEW, which is extension loading utility... wait... isn't GLUT/GLFW already an extension? Is there any reason to use it, like are there any really important extensions to get interested with?

Untill now we have window creation (and some utilities), but... OGL doesn't take care of loading textures, neither 3D models. How many other libs do I need?

Let's mention education part now. There is (in)famous NeHe tutorial. Written in C with use of WinApi, with extremely unclear code and outdated solutions, yet still the most popular one. Some stuff like Red Book can be found, which are related to versions like 2.x or 3.x, however there are just few (and unfinished) tutorials mentioning 4.x.

What to go with?

Cella answered 4/1, 2012 at 20:38 Comment(7)
Your "question" is very unfocused and confused, citing many things which aren't true or are misunderstandings of how things work. Could you try to clarify what it is that you are trying to accomplish and what you need to find out?Undertake
I've wrote that I want to "get sure that my actual understanding on some things is valid"Cella
"isn't GLUT/GLFW already an extension?" – no, they're not. GLUT is a independent library, as is GLFW. Extensions are part of the system's OpenGL implementation itself, not some library. GLEW is a library for easy access to extensions.Carniola
OpenGL is Raw, Modern opengl is Super-Raw; After getting my head around OGL 4.x to upgrade my existing OGL 2.1 project and read bunch of half-baked tutorials, and download 200mb samples [with poor coding style], and my brain exhausted twice a day by stupid Matrices and reading datenwolf comments here and there about what Modern OGL is and what is not(anymore)... I'm frustrated! ...What makes me frustrated is Khronos's massive-feature-removal policy, without bring anything new on the table.Forte
@Ndv I've moved to C# and OpenTK (opengl/openal/utils 'wrapper' for c#), makes life bit easier, check it! :) [supports all opengl versions]Cella
OpenTK is awesome but I preferred to stick with C++, not to say C# is bad or something, surly have it's own place, but that's only my personal flavor, anyway thank you.Forte
Learning modern OpenGL, or any 3D graphics for that matter, requires a decent understanding of linear algebra. Vector math tutorial for 3D Computer Graphics is by far the best resource for learning vectors and matrices. It is also interactive that each section has a test question to verify and seal the understanding of that topic.Horaciohorae
E
19

If you are writing a game, I would avoid things like GLUT, and write your own wrappers that will make the most sense for your game rendering architecture.

I would also avoid OpenGL 4.2 at this point, unless you only want to target specific hardware on specific platforms, because support is minimal. i.e., the latest version of Mac OSX Lion just added support for OpenGL 3.2.

For the most comprehensive coverage of machines made in the last few years, build your framework around OpenGL 2.1 and add additional support for newer OpenGL features where they make sense. The overall design should be the same. If you're only interested in targeting "current" machines, i.e. machines from late 2011 and forward, build your framework around OpenGL 3. Only the newest hardware supports 4.2, and only on Windows and some Linux. If you're interested in targeting mobile devices and consoles, use OpenGL ES 2.0.

GLEW loads and manages OpenGL Extensions, which are hardware extensions from different vendors, as opposed to GLUT which is a toolkit for building OpenGL applications, completely different things. I would highly recommend using GLEW, as it will provide a clean mechanism for determining which features are available on the hardware it is being run on, and will free you from the task of having to manually assign function pointers to the appropriate functions.

OpenGL SuperBible is a pretty good book, also check OpenGL Shading Language. Everything you do with modern OpenGL is going to involve the use of shaders - no more fixed functionality - so your biggest challenge is going to be understanding GLSL and how the shader pipelines work.

Exurb answered 4/1, 2012 at 21:6 Comment(1)
+1 At last, someone has mentioned the SuperBible! The best introduction to modern OpenGL I've seen.Kinglet
U
37

So... currently we have OpenGL 4.2 out, which as I read somewhere requires dx11 hardware (what does it mean?) and set of 'side' libraries, to for example create window.

DX11 hardware is... hardware that has "supports DirectX 11" written on the side of the box. I'm not sure what it is you're asking here; are you unclear on what Direct3D is, what D3D 11 is, or what separates D3D 11 from prior versions?

FYI: D3D is a Windows-only alternative to using OpenGL to access rendering hardware. Version 11 is just the most recent version of the API. And D3D11 adds a few new things compared to D3D10, but nothing much that a beginner would need.

OpenGL is a specification that describes a certain interface for graphics operations. How this interface is created is not part of OpenGL. Therefore, every platform has its own way for creating an OpenGL context. Windows uses the Win32 API with WGL. X-Windows uses the X-Windows API with GLX functions. And so forth.

Libraries like GLUT, GLFW, etc are libraries that abstract all of these differences. They create and manage an OpenGL window for you, so that you don't have to dirty your code with platform-specific details. You do not have to use any of them.

Granted, if you're interested in learning OpenGL, it's best to avoid dealing with platform-specific minutae like how to take care of a HWND and such.

And we have also GLEW, which is extension loading utility... wait... isn't GLUT/GLFW already an extension? Is there any reason to use it, like are there any really important extensions to get interested with?

This is another misunderstanding. GLUT is a library, not an extension. An OpenGL extension is part of OpenGL. See, OpenGL is just a specification, a document. The implementation of OpenGL that you're currently using implements the OpenGL graphics system, but it may also implement a number of extensions to that graphics system.

GLUT is not part of OpenGL; it's just a library. The job of GLUT is to create and manage an OpenGL window. GLEW is also a library, which is used for loading OpenGL functions. It's not the only alternative, but it is a popular one.

Untill now we have window creation (and some utilities), but... OGL doesn't take care of loading textures, neither 3D models. How many other libs do I need?

OpenGL is not a game engine. It is a graphics system, designed for interfacing with dedicated graphics hardware. This job has nothing to do with things like loading anything from any kind of file. Yes, making a game requires this, but as previously stated, OpenGL is not a game engine.

If you need to load a file format to do something you wish to do, then you will need to either write code to do the loading (and format adjustment needed to interface with GL) or download a library that does it for you. The OpenGL Wiki maintains a pretty good list of tools for different tasks.

There is (in)famous NeHe tutorial. Written in C with use of WinApi, with extremely unclear code and outdated solutions, yet still the most popular one. Some stuff like Red Book can be found, which are related to versions like 2.x or 3.x, however there are just few (and unfinished) tutorials mentioning 4.x.

What to go with?

The OpenGL Wiki maintains a list of online materials for learning OpenGL stuff, both old-school and more modern.

WARNING: Shameless Self-Promotion Follows!

My tutorials on learning graphics are pretty good, with many sections and is still actively being worked on. It doesn't teach any OpenGL 4.x-specific functionality, but OpenGL 3.3 is completely compatible with 4.2. All of those programs will run just fine on 4.x hardware.

Undertake answered 4/1, 2012 at 21:21 Comment(5)
definitely a +1 for the tutorialsCompatible
De facto the best tutorial for modern OpenGL online.Sibie
For Mac OS X users there's an adaption, that saved me a lot of time and nerves: github.com/rsanchezsaez/gltut-glfwTug
The last link works, but the other three don't.Laux
Incidentally, since you wrote your tutorials in 2012... do you deem it still valuable? I'm not joking, I'm asking seriously; I've gone through the first 2 chapters and half of the 3rd, and I find it well made, and that I am learning stuff. But the hell of globals and void functions all around (yes, not your choice, but this or that opengl's impl's) makes understanding so much harder! So I' wondering whether I'm looking at something old, and maybe in the modern world some project has abstracted away madness under some modern API.Laux
E
19

If you are writing a game, I would avoid things like GLUT, and write your own wrappers that will make the most sense for your game rendering architecture.

I would also avoid OpenGL 4.2 at this point, unless you only want to target specific hardware on specific platforms, because support is minimal. i.e., the latest version of Mac OSX Lion just added support for OpenGL 3.2.

For the most comprehensive coverage of machines made in the last few years, build your framework around OpenGL 2.1 and add additional support for newer OpenGL features where they make sense. The overall design should be the same. If you're only interested in targeting "current" machines, i.e. machines from late 2011 and forward, build your framework around OpenGL 3. Only the newest hardware supports 4.2, and only on Windows and some Linux. If you're interested in targeting mobile devices and consoles, use OpenGL ES 2.0.

GLEW loads and manages OpenGL Extensions, which are hardware extensions from different vendors, as opposed to GLUT which is a toolkit for building OpenGL applications, completely different things. I would highly recommend using GLEW, as it will provide a clean mechanism for determining which features are available on the hardware it is being run on, and will free you from the task of having to manually assign function pointers to the appropriate functions.

OpenGL SuperBible is a pretty good book, also check OpenGL Shading Language. Everything you do with modern OpenGL is going to involve the use of shaders - no more fixed functionality - so your biggest challenge is going to be understanding GLSL and how the shader pipelines work.

Exurb answered 4/1, 2012 at 21:6 Comment(1)
+1 At last, someone has mentioned the SuperBible! The best introduction to modern OpenGL I've seen.Kinglet
M
6

I'm currently learning modern OpenGL as well. I've also had hard time finding good resources, but here's what I've discovered so far.

I searched for a good book and ended up with OpenGL ES 2.0 Programming Guide, which I think is the best choice for learning modern OpenGL right now. Yes, the book is about OpenGL ES, but don't let that scare you. The good thing about OpenGL ES 2.0 is that all the slow parts of the API have been removed so you don't get any bad habits from learning it while it's still very close to desktop OpenGL otherwise, with only a few features missing, which I think you can learn rather easily after you've mastered OpenGL ES 2.0.

On the other hand, you don't have the mess with windowing libraries etc. that you have with desktop OpenGL and so the book on OpenGL ES won't help you there. I think it's very subjective which libraries to use, but so far I've managed fine with SDL, ImageMagick and Open Asset Import Library.

Now, the book has been a good help, but apart from that, there's also a nice collection of tutorials teaching modern OpenGL from ground up at OpenGL development on Linux. (I think it's valid on other OSes the name nevertheless.) The book, the tutorials and a glance or two every now and then to the Orange Book have been enough in getting me understand the basics of modern OpenGL. Note that I'm still not a master in the area, but it's definitely got me started.

Marmoset answered 4/1, 2012 at 21:7 Comment(1)
I highly recommend SDL if you want a simple framework for creating a window and drawing with OpenGL. I think NeHe is still a good guide, some of the APIs have been removed with more appropriate ones in which case it's your adventure to update it :).Peculium
T
3

I agree that it's king of hard to get in to OpenGL these days when all the tutorials and examples use outdated project files, boken links etc, and if you ask for help you are just directed to those same old tutorials.

I was really confused with the NeHe tutorials at first, but when I got a little better understanding of C, compiling libraries on UNIX and other basic stuff, it all fell into place.

As far as texture loading, I can recommend SOIL: http://www.lonesock.net/soil.html

I'm not sure but I recall I had trouble compiling it correctly, but that may have been my low experience at the time. Give me a shout if you run into trouble!

Another usefull tip is to get a Linux VM running and then you can download the NeHe Linux example code and compile it out of the box. I think you just need GLUT for it to work.

I also prefer GLFW before GLUT, mainly because GLUT isn't maintained actively.

Good luck!

Tangelatangelo answered 4/1, 2012 at 21:20 Comment(4)
FreeGLUT is still being worked on. Nobody should be using the old GLUT at this point, since FreeGLUT is compatible with it.Undertake
I haven't tried that one but if you're used to GLUT it sound like a good alternative. I prefer the syntax of GLFW though :)Tangelatangelo
I prefer being able to create SRGB framebuffers, which FreeGLUT can but GLFW for some reason cannot. It's a deal-breaker for me; I refuse to work in a non-linear colorspace.Undertake
@NicolBolas: I guess you might already know this; GLFW 3 has support for sRGB framebuffers.Horaciohorae
I
2

The major point of modern OpenGL is tesselation and new type of shader programs so i would like to recommend to start from a standalone tutorial on OpenGL 4 tesselation, i.e: http://prideout.net/blog/?p=48

After manuals and tutorials a good follow-up is to take a look at the open-source engines out there that are based on top of "new" OpenGL 3/4. As one of the developers, I would point at Linderdaum Engine.

Intertwist answered 14/5, 2012 at 20:16 Comment(0)
M
-1

"Modern OpenGL programming with more C++ OOP and shader approach" makes me mention Qt. It hasn't been mentioned yet but Qt is a library that is worth learning and is the easiest way to write cross platform C++ apps. I also found it the easiest way to learn OpenGL in general since it easily handles the initialization and hardware specific code for you. Qt has it's own math libraries as well so all you need to get started with OpenGL is Qt. VPlay is a library that uses Qt to help people make games easily so there are obviously some people using Qt to make games as well.

For a short introduction to Qt and OpenGL see my post here.

I will mention that since Qt abstracts some OpenGL code, if you are trying to use the Qt wrappers, the API is slightly different than just OpenGL (although arguably simpler).

As for my vote for good tutorials or book check out Anton's OpenGL tutorials and Swiftless tutorials. Anton's ebook on Amazon is also rated higher than any other OpenGL published resource I have seen so far (and far cheaper).

Macswan answered 7/1, 2016 at 21:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.