Going 3D with OpenGL

Going 3D with OpenGL
Corgi cubes. Corbies. Cubgis. Corgubes.

So far in my adventures with OpenGL I have more or less been kludging things together, albeit following some great resources to do the kludging. I decided to really start following and learning through one of these resources, as I have a project in mind that I want to build out and don't have the knowledge and OpenGL skills to do so right now. The resource I am following is the Learn OpenGL website which conveniently comes in a print edition as well as in a free PDF available on the Learn OpenGL website.

As always please refer to the resource for actual in depth explanations, this will be another loose jumble of my thoughts

Coordinate systems

I think everyone that is learning any type of graphics programming will eventually get to this part in their journey and realize oh yeah, the different coordinate systems are worth understanding (even if the level of understanding is shallow, like mine is). For me, the part that is most interesting right now is how the coordinate space we are working on is transformed at various stages within our own code as well as by OpenGL

So far I have only been working with normalized coordinates, hand editing points between -1.0 and +1.0 (the coordinate space OpenGL ultimately renders) to produce the desired results. Having to do that math by hand/per point or most importantly in the context of your whole scene which evolves as you're working on something is supremely cumbersome. Where I really hit the wall with this methodology was working on a scene with a few hundred objects and you immediately start seeing that working in normalized space starts to breakdown - at least it does for folks like me that don't want to do all the scene space to normalized space math in their head. I'm sure folks can do it, I'm sure you can even write your own utility methods to do the calculations and "make it work".

On the other hand, the Learn OpenGL book goes through - what I assume is the industry standard - methodology of working in your own space coordinates e.g. x,y = (100,250) could be a point in your scene, and using different linear algebra matrix calculations to get your (100,250) coordinates (which would normally be clipped out by OpenGL as they fall outside of the -1.0 and 1.0 normalized coordinate space) mapped to their normalized coordinate equivalents. The great thing about this is you really only need to worry about things like your scene boundaries and can rely on the transformation math to do the heavy lifting for you.

The result of working through the Model View Projection chapters to get Meeko on a rotating cube

Camera

The next thing I was most interested in the concept of a camera to change view points in the scene I'm rendering. Luckily that was one of the next chapters in the book and I was able to quickly follow the example to set up a camera that was rotating around a central point:

Remember: the cube's aren't moving, your perspective is

Once we conquered this "camera on a jig" movement it was natural to move to a more interesting use case of being able to move the camera around with the keyboard, and this operated on the same concept as the "camera on a jig" math, now using the keyboard inputs as a component for the math:

Boop!

This alone doesn't give us the full fidelity we're used to when navigating 3D scenes in the real world or digital worlds like Blender or Unity. The missing component now is the ability to look around in addition to move around, which ends up leading to a bunch more math in a new direction compared to the math so far in the code we've been writing and following - trigonometry. While we're integrating mouse movement, might as well throw zoom in according to the chapter I'm following. Here's where that gets us:

Meeko in full movement fidelity

Conclusion

That's a nice bit of progress with OpenGL, I think that gives me enough tools to work through the first actual project I want to do with it. I'm also around 1/5th of the way through the book, so I'm hoping I can make my way through it and learn a lot more this year!