Starting OpenGL

Hello all,

I’ve some good knowledge on C++ console coding and am reading Chapter 5 of the book C+±GUI-Programming-with-Qt-4-2nd Edition. For a reason I’d like to be familiar with OpenGL.

Using this link, I went for learning it and downloaded a portable type of cmake-3.9.3-win64-x64 and ran the executable file of it and using the tutorial built the solution using VS 2017 win x64 successfully.

In the tutorial, it says: “A black window should appear”.
But when I run playground.exe, two windows appear: one console black window and one dark blue larger window with the title of Playground. And the same outcome when running the project using VS.

I have some questions:

1- Is what I’ve done until now OK?
2- Is it right if I start learning OpenGL with the knowledge I have for now?
3- Is that tutorial a good resource for starting learning OpenGL from the basic for the first time, or should I choose a book instead?

Tanks you so much.

It seems yes. I haven’t seen any glClearColor or glClear. So the color of the window is not relevant.

What about your mathematics knowledge ? Is linear algebra something you know ? What about geometry or trigonometry ?
For the other computer-oriented knowledge, that will come progressively.

If I remember well, there is a very recent post about it in the beginner section of this forum.

thanks for the answer.

I have some knowledge of Qt. What’s the difference between using OpenGL with Qt and OpenGL independently (without Qt), please?

Here’s my thoughts on it:

  1. That sounds right. That tutorial uses GLFW for window management, and it normally opens a console window alongside your main window. It’s useful for printing out debugging info., with std::cout, std::cerr, etc…

I didn’t build the solution from the site, but I still have a solution for VS 2015 I made from that tutorial back in January, according to Windows Explorer. In my solution, “glClearColor(0.0f,0.0f,0.4f,0.0f)” was used to make the background dark blue, like you describe. Looks like the tutorial hasn’t changed since then, so I’m sure you did it correctly.

  1. If you’re comfortable with C++ as you say, I’d say you can try out OpenGL. The learning curve with OpenGL is more about understanding the library itself. It was designed mainly for C, and because of that, you aren’t required to understand things like C++ templates and OOP to use it. With regards to C/C++, in source files, being comfortable with function calls and pointers is good enough.

Math-wise, Silence mentioned linear algebra, geometry, and trigonometry. I’d say for linear algebra, if you’re comfortable with matrices, matrix multiplication, the dot product, and the cross product, you know a good chunk of the math already to do 3D graphics in OpenGL. Linear algebra is quite a big topic in itself, with eigenvectors and diagonalization (and proofs too). You don’t need that if you just want to map 3D points you define into OpenGL’s 2D screen coordinates. In the tutorial website you mentioned, there’s even a “Basic Tutorials -> Matrices” section if you’re new to the whole concept.

Other than that, for geometry and trigonometry, knowing the difference between degrees and radians and your trigonometric functions is good.

  1. That tutorial looks good. It’s up to you and your learning style. Personally, I thought that tutorial was a bit overwhelming when I first started looking into OpenGL because it didn’t explain much about the functions it used.

I prefer LearnOpenGL’s tutorials because they explain more about opengl concepts and functions. Even then, I was just super happy getting 3D graphics working and getting camera and lighting code to work. But I liked how the author of those tutorials added background information on graphics concepts like stencil buffering. Although I got code to work in that tutorial, I don’t understand it fully right now, but I’ll keep it in note to look back at in the future.

(As a side note, if you do decide to look into LearnOpenGL’s tutorials, make sure to check out the Code Repository link on that site. It already has complete source code available for you, if you just want to get samples working for the first time. I never saw that before, and as I hinted above, I put a lot of effort focuing on pasting/removing functions to get code examples to work. I never knew that repository was there. A little silly, I admit haha, so I mention it here just so you know about it now.)

Nonetheless, I respect both tutorials because the authors put the effort in to provide complete code examples, and they also both explained how to build them. It takes a lot of work to make content that like that.

As Silence mentioned, there was a recent thread asking about learning OpenGL called “Learning OpenGl”. People mentioned links, could be useful for you.


With your last message, you don’t really use OpenGL “independently”. OpenGL is solely a library for drawing graphics. In order to display its contents in a window, you need to first use a window management API that allows you to create/describe how you want to display OpenGL in that window. It’s known as creating an OpenGL context for a given window.

With Qt, I’m guessing you can put a child window within your main application window and set it so that all your OpenGL drawings render to that window. And you can also add buttons and scroll bars for example to your main window that can interact with that OpenGL child window. I think that’s pretty cool as an API. It’s nice you’re looking into it. It’s been a while since I ever tried it. It was too much for me then. I was new to C++ at the time. Qt Creator and the addition of signals and slots to the standard C++ language was too much for me.

Anyways, you can also consider GLFW to be a window management API. It’s used in the tutorial you linked to create the main window with the dark blue background. Unlike Qt, you can’t add scroll bars and buttons. GLFW is more for game development, not for developing GUI software to help you make games. But I still like it as a nice, lightweight, low-level API. It’s a good choice in my opinion if you’re learning OpenGL for the first time and don’t want to worry about window creation. Overall, both GLFW and Qt are powerful in the sense that they’re both cross-platform.

So my answer to your question about using OpenGL is that you can’t consider using OpenGL independently. You need to consider the API you use to create the window and OpenGL context that will display your OpenGL drawings. Qt and GLFW are examples of cross-platform, window management APIs that allow you to do that.

My last note is that on Windows, if you really want to go as low-level as possible with regards to a window management API, you use Windows API. As noted by its name, it’s only for Windows, but you have full control over window creation in your Windows OS for creating something like an OpenGL context. Cross-platform APIs like Qt and GLFW abstract the window creation process necessary with the Windows API and also the OpenGL context creation process. If you’re new to OpenGL, I’d say stick with Qt and GLFW for now, and if you want low-level control, just look up that.

I appreciate your good and nice talks that helped me and also made me pleasant by reading them. :slight_smile: Thank you very much.

My goal for my programming task is to be around C++ for the time being and also near future. I even chose Qt because it was based on C++.

My choices for now, I think:

1- Reading the chapter 20 of that book (C+±GUI-Programming-with-Qt-4-2nd Edition).
2- Try to find a good tut on Qt OpenGl. (*)
3- Start reading this tut which looks great!

In all three choices, I won’t leave going on studying the book above from where I’m now (chapter 5).

(*): If I try to find a good and new tutorial on Qt OpenGL, (the book is rather out dated), what I will find will lead me to reading the Qt Docs which are really useless, confusing and overwhelming! :frowning:

I’m also eager to read that tut and don’t think it is contrary to my goal.
Do you agree with my thought?

I would like to be connected with you. Here is me on LinkedIn: www.linkedin.com/in/abbasi-rahmat, and will be glad to find you there.

Sure. Glad it helped.

That sounds like a good idea. Hopefully you enjoy LearnOpenGL as much as I did. I’ve never done OpenGL on Qt, so good luck on that. Qt is pretty popular, from what I can tell. I think it goes beyond standard OSs into systems like cars and smart watches. I don’t have it anymore, I only used it to try out GUI dev. one time. And it takes up around 9-10 GBs of hard-drive space. That said, Qt’s powerful API is probably why it’s docs are so extensive. Though it’s reasonable to see that, considering what it’s designed for.

Sooner or later, like any API, you’ll have to use the Qt docs. Though as I said earlier, from my experience, I admit Qt is hard to learn from if you’re new to GUI development. You can probably ask around the Qt forums for help on finding/interpreting what you need. As a segue, the same thing goes for OpenGL. If you’ve tried OpenGL tutorials long enough and want to have complete information on how it works, you’ll have to check the OpenGL specification. You can find a list of specifications in the OpenGL Registry here. Each version of OpenGL has a different specification, but they’re designed to be read mostly indepedently of other OpenGL version specs. So like, you probably don’t have to know the OpenGL 1.1 spec if you want to understand the 3.3 core spec. From what I know about the spec so far, it’ll mention other versions if it needs to point out something (like OpenGL extensions). Nonetheless, there are similarities between specs. That’s probably why even though LearnOpenGL’s tutorial is based on 3.3 core when currently 4.6 is out, you can still consider the tutorial to be “modern” since they both use the concept of shaders.

What I’d also would like to note here if you’re looking for more complete information is the OpenGL Wiki and the OpenGL Reference Pages. 1.7.2 of the 3.3 core spec mentions that “OpenGL requires a companion API to create and manage graphics contexts, windows to render into, and other resources beyond the scope of this Specification”. So you won’t find info. on window management creation and how to load OpengGL functions to use in your program. If you’re working low level with the Windows API for example, you can check the OpenGL Wiki for information on creating a context and loading functions for that API. (Technically, you should check your window management API for more info. For Windows API, it’s the MSDN, but for some odd reason the wiki seems more descriptive. Not sure why haha.)

I’ve only used the wiki a little bit, but I find it pretty helpful so far to fill in the blanks that the spec is sometimes unclear about. I also mentioned the OpenGL Reference Pages. That’s more like documentation based on specs. If you google “OpenGL Reference Pages”, the current pages are for 4.5, but there’s plenty of info. that’s valid for 3.3 core spec for example, if you want to reference docs while doing the LearnOpenGL tutorials. Specs are pretty similar from what I can tell. They don’t come up with a totally brand new set of commands for each spec.

Overall, thought I’d point out some of the more “low-level” resources here if you plan to take OpenGL seriously. I don’t know what you plan to use it for. Since you’re new to it, I don’t think you have to stress the specs too much, I just wanted to pointed them out here as reference. Tutorials like LearnOpenGL will give you a lot of useful info. already, if you don’t plan to use it that much.


I don’t use LinkedIn. If you want to message me directly about something, you can probably pm me here in the forums. I’ve never done it before. But looks like you can click on my username and click “Private Message”. I’d probably get a notification in my email about it. Nonetheless, if you have a question about OpenGL, best to put a forum post like this one here so other people can see it/reply.


As a side note, with talking about learning OpenGL, I thought it’d be cool to post this StackOverflow post on how the OpenGL state machine works. See datenwolf’s reply. I think the biggest hurdle to learning OpenGL is understanding how that works. I think of it like a switchboard that makes fireworks appear (aka makes drawings appear on the screen). With OpenGL, you can toggle/look at how the current switches are set (aka you can set/query OpenGL state), and you can make different types of fireworks (drawings) appear. But you can’t keep track of all the information about the fireworks with just a switchboard (with OpenGL, you can’t focus/query on what’s drawn, only on the current state you’ve set so far). This is why you don’t normally see return values in OpenGL functions. They modify state, but they don’t for example give you back some “line object” for example that you can modify. Hope it helps.

Thank you very much.