Learning OpenGL. Log 1

This is the first, in what will be a series of posts on my journey in learning OpenGL (or as some say, modern OpenGL).


It’s been 2 weeks since Uni started. As I am doing an Interactive Computer Graphics this semester, which uses OpenGL. I have therefore, started it.

Besides learning to draw the basic primitives and the usual rainbow colored triangles. Plus a little bit of shader programming. I’ve spent a lot of the time in the past 2 weeks just playing and experimenting with a couple of utility tool kits and  graphics libraries for window creation and input handling. Namely Freeglut, GLFW, and SFML. Today, I will talk about my experience with them so far, and what not.

From a beginner point of view, getting started with learning how to setup a basic window and OpenGL context up was such a pain. Going from a C++ programmer to using libraries/API’s that are written in C also made me quite uncomfortable. To those who are a novice like me. Fear not, you will get used to it after a while. The hardest part is actually just getting the few concepts down.  Specifically window and context initialization and the way OpenGL’s API is defined. This is not a tutorial, so I won’t go into the details, but I will provide a list of the online tutorials I’ve been using that are very good.

Freeglut (Wiki link)

Freeglut is an API compatible clone of the now obsolete Glut. It is under active development, where as work on Glut halted back in 2005. All it does is providing means to create a window which an OpenGL context will be attached to. The reason I took a dip into Freeglut is because the Interactive Computer Graphics unit uses it (because the text book uses it…). It has been the de facto choice for tutorials and teaching materials, even though it should just die after the original project halted. now Just a quick rank: the lecturer seems like a nice guy, but he is just NOT lecturer materials. The textbook that he chose is also horrible. From what I’ve gathered, the same textbook has been used for the last couple years for this unit, which is sad. The text attempts to teach theories and concepts in computer graphics and tries to mix OpenGL into it.

The way Freeglut/Glut works is by providing a couple callbacks for different things while keeping completely control over it’s own main loop. This is good for making applications like interactive graphics render and model viewers, application which it was designed for developing.  If you intend to develop applications such as games, that are much more interactive and resource intensive, then Freeglut is not for you. At first I wasn’t too sure why, but control over the main loop is very important.

To use Freeglut, you initialize the library and set your call backs, and then you begin Freeglut’s mainloop. At this point, Freeglut takes over control until it exits.

GLFW (link)

The next tool kit I tried is GLFW. It is a very minimal tool kit and does not do as much as what Freeglut give you, but it does give you control over your mainloop. Instead of entering Freeglut’s mainloop, you have something along the line of “pollevents()”, which it internally calls callbacks that can you set, just like Freeglut. GLFW and Freeglut are quite similar with their functions, in terms of initialization and configurating the window. I spent about a week on Freeglut. By the time I moved to GLFW, it wasn’t too hard picking it up.

What I did was I ended up wrapping the GLFW stuff into a RenderWindow class, and wrote a simple event queue and wrote custom callbacks to translate most of the call backs into my own events, which I then handled by polling my own event queue. I modeled it after SFML because I’ve been using it for a while now and the OOP aspect of it made it very elegant.

One thing that I do miss that Freeglut has and GLFW doesn’t is menu creation. Pop-up menus will be used extensively for this unit so I spent a lot of time investigating what alternative there is for GLFW besides writting my own. The problem is, there isn’t really any. I did managed to discover CEGUI, nui3, glui2 and AntTweakBar.  The AntTweakBar library seems like the easiest to implement with the others looking quite complicated. I did not give any of them a try so I could be wrong. What bothered me is that they were GUI/widget tool kits and do not provide the ‘traditional’ menu.

SFML (link)

Finally. I remember that  SFML uses OpenGL internally. SFML (short for simple, fast, multi-media library). It’s popular for creating 2D games and applications. Bit of a rival to SDL. Best of all, it’s written in C++, and under active development. The library provides a lot to developers with 5 different modules. Providing classes for not just handling 2D graphics, but there are also classes for handling audio, network and other things. SFML allows you to use the OpenGL API directly, and it’s very simple to do some. What’s nice is that you can use it’s 2D graphics module along side of it. There are quite a few GUI libraries built for SFML but I havn’t look too deep into yet. The best thing yet is that I’ve been using SFML for the last couple dozen weeks on my 2D game engine project.

I spent the afternoon today and extended the engine enough to get some basic OpenGL primitive drawn. The engine is no where near completion. If I could use SFML for the interactive computer graphics unit then I will have the opportunity to develop and grow the engine along side the course project, instead of pausing work on my game project.


This blog has turned out to be a lot more formal and a bit more longer than I expected, but that’s cool. In closing, the libraries I mentioned today are not all there is out there. They are simply the ones that I’ve discovered and explored so far. There are many more out there that can be used for creating window and OpenGL context. The ones that I could think of on top of my head are Qt and SDL. I’ve used Qt before and it’s awesome for lots of things.

The next thing I will do is work a bit more on OpenGL with SFML for a bit more, and do so by extending my engine. I will also have to contatct my unit coordinator to accquire permission on developing on VS2012 with SFML on Windows (the project is meant to be done on a POSIX system with Freeglut). Lastly, I will continue learning OpenGL.

Stay tuned for the next log. Peace out!

List of tutorials

(in order of most favored):

List of libraries mentioned

(no particular order):

  • Freeglut
  • GLFW
  • SFML
  • SDL
  • Qt
  • nui3
  • glui2
  • AntTweakBar

8 Replies to “Learning OpenGL. Log 1”

  1. Ah, I just stumbled on this when looking (again) for good ways to support development under OS X for this unit. (Specifically I was looking at building a simple menu system with GLFW.)

    It looks like you’ve repeated and updated most of the work I did when reviewing the use of GLUT/FreeGLUT for teaching for the current Graphics & Animation unit, as had been used for the previous Graphics unit (starting before I taught it). I agree that staying with FreeGLUT isn’t ideal,and nor is the recommended text.

    However, I looked quite thoroughly at the alternatives, and each of them had some aspects that made them unsuitable for this unit. E.g.

    – requiring more than very simple C++ would be too much for students no previous C++
    – supporting an OpenGL 3 core context.
    – having a text book that uses the same code and environment
    – supporting simple menus without writing much code
    – generally open and supporting all major platforms

    That said, I’d gladly consider any alternatives you want to suggest. When SFML supports core contexts, that may become my preferred choice.

    Oh, and part of my teaching philosophy is that students learn more from hands-on practical work than what is said in lectures. So, I spend really quite a lot of time on developing labs and projects that are designed so you learn a lot, without being excessively difficult or long. To me the lectures and text cover the fundamental concepts, but to fully understand them you need to use these concepts for something practical.

    1. Hi Rowan, looks like you found me out 😛

      I think I will first address my comment regarding you as a lecturer. You are very right with the practical materials that you’ve been providing and I agree with you on that. What I found lacking are the actual lectures. I think there are room for improvements. It would be awesome if you could apply the same philosophy to your lectures. I feel that some things could have been explained a bit better, and the thought processes shouldn’t be tied to the textbook’s authors’ only.

      With SFML, as you are aware of, context flag is not exposed in the API. This comes down to the graphics module of the library (sf::RenderWindow and anything that relies on it. The graphic module uses deprecated gl functions internally. However, sf::Window (parent of sf::RenderWindow) does not, and it can be used for windowing and context creation. Which is what I’m using. There is also another issues where things will break down if you use OpenGL vertex buffer objects and the SFML graphics module in the same time, which I suspect is also related to the use of deprecated functions. At the end of the day. Not being able to specify context flag is a problem, but one that we can work around. The developer of SFML replied in feb last year that the “functions should be replaced soon”. This obviously hasn’t happened yet. Someone will have to create a ticket on Github to remind him that. Regardless, SFML is a great library.

      I am very puzzled when you say “requiring more than very simple C++ would be too much for students no previous C++”. At what point does C++ become too much? Using something as simple as C++ classes can provide encapsulation making it clear to the student the purpose of specific OpenGL codes and the lifetime of objects. Personally I think the design of the course is flawed currently. In terms of the programming language taught and the order it is taught in. C++ should have been used instead of java, and I imagine that’d be the case in the future. It is a lot more powerful and simplicity can still be achieved, especially with C++11 (and C++14x). Complexity can be reduced easily by restricting language features used in teaching materials, while still allowing the options for the student to use those features if they choose so.

      UPDATE: i forgot to add that. In terms of text materials. The OpenGL superbible and the orange/red book would have been a much better choice. pdf version of one of the books is also freely available for download. I regret buying the textbook..

  2. Oh, and AntTweakBar looks partly like what I was looking for to work with GLFW with OpenGL Core 3.2, and it even works with SFML. Thanks for that – it’s a good find, I’m considering it for the project and/or the later labs or for next year, and I may even create a simple menu system based on it to replace the FreeGLUT menus.

    One of the reasons it’s so tough right now to find a good learning environment for OpenGL is because of the move to “modern” forward compatible core contexts – I’m expecting next year there will be much more choice, it seems like many environments have just nearly caught up with this transition.

    1. I was gonna post this in my other reply before you made this one, but I will put it here now because it’s more relevant.

      I have not give AntTweakBar a try yet, though I’ve played with some of it’s samples and had a look at the source codes. I’ve been experimenting with another GUI library call SFGUI. It’s developed on top of SFML, but it’s now on a transition to be SFML independent. It’s look is a reminiscence of Valve’s older in game GUI’s and I really like it. It also reminds me of Qt. The support is great and the developers are very active on their forums. I will most likely use it to create a menu system with it.
      Compare to AntTweakBar, it’s not as mature and might lack some features(i’m just guessing here), but I prefer the OO aspect of it over AntTweakBar.

      Before this unit, I had plans to learn DirectX only, because of the vast amount of good books, documentation and materials available online…

  3. (We can move this discussion to email, it could be more appropriate, but if you prefer here that’s fine.)

    For including more C++ : some students taking the unit have only minimal programming experience, sometimes only half a unit/semester of either Java or C which is all the prerequisites require. I realise some students may benefit from an fuller environment, but my experience is that some students will end up lost with more serious C++ just due to lack of previous programming experience. This is one reason why I give permission to use other environments for students who seem ready to use them (the other reason is that it helps me keep up to date on the alternatives in detail). But, for this unit, everyone must learn the fundamental models and concepts behind modern 3D real-time graphics, and for that using FreeGLUT actually works very well – the lifetime of objects never becomes an issue even in the project, and is beside the point for this unit. So, this is a very deliberate choice.

    For the other issues, overall the units I teach do well on SURF surveys, above the CSSE, FECM and UWA averages, including last year for the original version of CITS3003. Indeed my SURF scores are generally quite a bit above average, so, I feel that overall I’m allocating my available time well. I could spend more on lectures and stop what I’m doing to improve the project,but I don’t agree that will overall improve the unit.

    The recommended text has it’s flaws, certainly in terms of the exact coding, but it fits this unit particularly well in the way it covers the high level aspects, and I design the practical work to focus on the details not well covered by the text and lectures. And if it helps it ranks higher or similar in terms of customer ratings on Amazon than the alternatives you mentioned. Also, the main author of the red book is a co-author of the recommended text. And, the red, orange and blue books gained a bad reputation for the editions from a couple of years ago. The most recent edition of the blue book only came out two weeks ago, and the previous edition really wasn’t suitable – and the editions prior were really not suitable. Next, year I’ll consider swapping to the blue book or the red book, but they both have the flaw that they do not attempt to cover computer graphics beyond OpenGL – this unit is not only about OpenGL, and the recommended text does a better job of covering other related topics so is academically more appropriate.

    1. My apologies. I was on the presumption that, by 2nd/3rd year students should have basic fluency in at least 1 general programming language. Indeed, I agreed that from personal experience the amount of knowledge on a programming language or programming in general that you gain from a unit or two is very sparse. Personally I spent the majority of my spare time either in front of a computer programming or reading about programming. I expect anyone who has a decent amount of interest in computer science or just programming to do something similar. That is study out of your own time. Of course. I am not in your position and therefore can only speak from what I know.

      On learning 3D interactive graphics. I find it very difficult to learn the theory/concept of 3D graphics by learning the theory first and then force an API on top of it. I found it a lot easier when i switched to just learning the API first and then make out the concepts from it.

      Its nice to hear that your units are well received. I sincerely hope you take no offense from what I said as I don’t mean any. As the professor, you obviously know what to do best to improve the unit. I just feel compelled to express my views and personal opinions. On a plus side. I do very much appreciate the communication that we have had so far.

      I am aware of the co-author being the author of one of the official books. That same author is also appear to be renown for still haven’t released the full so source codes for the new book. I found that the authors waste a lot of time explaining and complicating things that are also explained in the tutorials I’ve been following so far in lot less and easily understand we words.
      I have heard that the previous edition for the official book were poorly written because of the use of a wrapper library facilitating the shift to modern OpenGL, and that it is supposedly fixed in the new one?

      I remember reading recommendations on a book which is solely on computer graphics without using specific API’s. I can’t remember the title unfortunately. I think a book like that plus an official book would be the best combo. Spending > $100 on the current text did not work for me 🙁

      UPDATE: It’s fine with me if you prefer e-mail.

Leave a Reply

Your email address will not be published. Required fields are marked *