I realized today, reading the forums, that many people are very discouraged because they can’t get some basic shape to render to the screen. I’m telling you now, that you can do it.
You can and you will
and I’m going to help you (hopefully)
- Pick a compiler and learn how to use it. I don’t recommend using an IDE, I personally use notepad++ and nppexec to call my compiler when i smash f6. Recommended compiler for windows is MinGW-w64 (There are very good reasons not to use Visual Studio, not the least of which is poor optimization). This is the most important step. Learn how to install libraries, learn what a library is, toy with them. Experiment with your compiler enough so that you won’t have trouble downloading a C++ library such as bullet physics (which is extremely easy to install) and compiling a test program. DO IT FROM THE COMMANDLINE.
I recommend you do NOT use Cmake for your custom projects. A lot of people use that stuff, I personally cannot stand it. Cmake is a really complicated system that bogs you down and I have never figured out how to use it well enough to be confident. 99% of the time, you can easily, trivially even, reconfigure any CMake project that you know the codebase of to be compiled in the commandline through g++ or gcc
- Read up on the OpenGL libraries, third party tools and such. Figure out which version of OpenGL you are going to target and which third party libraries you will be using to, for instance, handle the window, OpenGL context, and of course mathematics.
A very brief, oversimplified description of what I know about:
- GLEW. Automatically checks the availability of all extensions, binds relevant names and functions. I don’t actually use this, because I have never gotten it to work, but other people report very positive experiences.
- GL3W. Same thing, but the header is written by a python script instead of a human. I use this in conjunction with GL3.h. Note that you need the companion C file.
- GLFW. Handles window and context creation. Also does keyboard inputs, joystick, mouse, and weird obscure stuff like dragging and dropping files onto the window. I recommend this.
- GLM. Allows you to do GLSL-esque vector ops and matrix math easily. YOU DO NOT NEED THIS but it makes things a LOT EASIER. Note that you can actually use this without OpenGL… so is it really an opengl third party library?
- GLUT. Handles window and context creation, along with some basic text rendering and even context menus. Note that if you want to use glut, you probably don’t actually want real glut. You want Freeglut. The reason: it is outdated and buggy on modern machines. If you are compiling for an SGI machine, I suppose you’d find this useful?
- Freeglut. Same thing, but for modern machines
- GL.h. Header for compatibility with OpenGL 1.1.
- GLext. Supplies compatibility with more recent OpenGL versions, specifically opengl extensions.
- Glcorearb.h. Supplies Compatibility with more recent OpenGL versions. GL3W depends on this.
- GLX. Works with the X-window system. If you’re on windows, you probably won’t be working with this.
- Mesa3D. Software emulation of OpenGL. Note that on linux, the OpenGL code is ACTUALLY mesa code, and drivers for gpus are written to interface as Mesa3D. Basically, on linux, there is not actually any OpenGL, but there is, and it is hardware accelerated, but if there isn’t, then it isn’t hardware accelerated.
You will find variants of ALL of these libraries varied by platform.
Learn the math. You need a solid grasp of matrix, vector math before you can even approach OpenGL without struggling.
Read the redbook’s first couple chapters. I recommend compiling them too. If you want a free copy of the book, it is available… “LEGIT”… on the… unfriendly… end of the internet. The examples can be found here:
They should compile just fine if you have learned how to use your compiler and how to install trivial libs.
Toy around with the redbook’s samples. Someone has unfortunately vandalized the repository by introducing the vermillion app class, which I feel is unfriendly to newcomers to programming.
Watch a tutorial series on OpenGL and try to implement what they do. Use the same commandline args that you used for redbook samples. DO NOT WATCH ANY TUTORIALS TALKING ABOUT OPENGL 3.2 OR EARLIER. I would recommend sticking to 3.3 and later, to guarantee you don’t start using shudders immediate mode
Study the OpenGL reference
TIPS AND THINGS THAT WILL TRIP YOU UP:
- In an ordinary setup, you will have multiple VBOs per VAO, not the other way around
- A fragment is, for all intensive purposes, a pixel. It isn’t actually a pixel, but if you think of it as a pixel, you will most likely be correct
- Extensions != libraries. Extensions in OpenGL are actual capabilities of your driver that are exposed to you. Lots of the stuff you would consider basic opengl is actually a buttload of 1st and 2nd party extensions.
- Clip space != Normalized Device Coordinates
- Hardware instancing is fast, software instancing is slow, often slower than just seperate draw calls.
- Optimizing OpenGL code is mainly about reducing the number of times you have to synchronize the CPU and GPU, and reducing the number of API interactions.
- Debugging OpenGL can be done with libraries such as GLintercept
- Examining how objects are drawn in existing games may teach you important tricks about rendering which simply reading a book will not. Yes, playing a video game can be part of computer graphics study
- Transparency is a very complicated effect and you will not be able to achieve it with one press of a key, nor 3, nor 5. Degrees and careers are often kickstarted or advanced significantly by new and improved transparency algorithms
- if you want correct colors you need to convert to an sRGB color space and do some gamma correction.
ON A FINAL NOTE
You should evaluate whether or not you really want to use OpenGL for your project. Most projects can and should be developed using existing middleware which is available with a permissive license online.
Final final Note: if you are targeting immediate mode systems, you should learn modern opengl first. I found modern opengl more intuitive.