Archive for the ‘ Coding ’ Category

Fiat lux

Unlike God in Genesis, I had to sort out my own chaos before summoning light.

Tutorials are not meant to do 100% of the job for you. But there are some aspects of OpenGL that remain puzzling even when they are are presented to you for the umpteenth time. In this tutorial, the “answer code” is filled with buffer creations and variables assignments that either

  • mimic more or less the flow of the tutorial.
  • are simply patched on the legacy code of previous tutorials.
  • have their own little section (in some sort of library) away for the main flow .

While the work is cut out for me in order to understand the math of lighting, it’s another business to actually create something that will be re-usable and useful in other circonstances without someone taking you by the hand every time. As I said before, since I’m not using most authors’ windowing system, I had built my own patched up version of their tutorials that fit my own window creation with mouse and keyboard control.  As I was failing this tutorial (and others for reason I’ll have to investigate)  I spent a couple of days just sorting out things in proper places for understanding how OpenGL ticks. And that bring me more satisfaction that an individual rendering (well, the rendering part is nice, too. 🙂 )

The code now looks more like the narratives I like to put in code when I create some class for future reading for myself or others.

  1. Generate all the necessary buffers for a given program.
  2. Set all needed Uniforms for this program.
  3. Collect data, bind it.
  4. Set the program as current and render.

The fact of creating buffer and setting all uniforms so early at this stage helps me understand the purpose of this program: what I need as resources, what to set, what to calculate and abstract that knowledge in a general point of view.

(FYI: programs, in OpenGL, are not individual binaries – like a program that you run on your computer – but a set of pipeline rules that objects – i.e. their vertices, normals and uv texturing coordinates  – go through before showing the final results on the screen.)

Enjoy the results featuring Suzanne, the famous Blender monkey.

no_lighting_thumb

no_lighting_wf_thumb

with_lighting_thumb

with_lighting_wf_thumb

Interfacing in 3D space

Nothingsdl_interface_thumb much today other that working on the interfacing.  Having mouse control (mouse move, wheel and button click) and windowing is not only necessary for a working game but the sooner you get it set up, the better the creative and debugging sessions go. SDL provides all this and more so that once you get the hang of it, you can’t live without it.  Lots of tutorials and demo rely of FreeGlut or GLFW, but it’s not hard to port them to SDL.  Even the OpenGL Superbible is using a custom event-driven application framework based on different tools, but I’m porting everything back.

Speaking of which, this book has a great tutorial on rendering thousands of  objects (say, a field of grass or a corona of asteroids) with few OpenGL calls.  Go check the video at their site to see the results.  Shaders are so über-powerful.  Today’s example is a similar lesson involving 4 quads (meh!) but it also demonstrates a simple Model-View-Projection with mouse control on both X and Y directions and mouse wheel for field of view (FOV) variation.

Baby steps.

I should be working on lighting soon.  Let’s just see where this leads to, first.

November 16th is “Tutorials day”

No it’s not.  But maybe I should do so declare it!

“Tutorials Day” is when everyone is invited to read / watch / listen to tutorials of their choice and do something useful or artistic with what they learned today.

I was pretty busy (as usual) neglecting the usual housework and laundry chores  (no surprise) in watching and reading many tutorials on OpenGL and Blender.  The goal for today was achieving texturing.  While I disclosed my boredom with spinning cubes in my last post, truth be told that texturing a cube is hard enough for the amateur artist that I am.  And so I ached over numerous tutorials on Blender texturing.  None of them really hit gold, but CGCookie had one that I particularly liked although I found that learning half of it was enough for my goal.

opengl_textured_cube_thumb     blender_cube_thumb

The real challenge isn’t about successfully following tutorials, it’s making sure this knowledge will scale up as the number of cubes (or characters or houses or cars) will start to grow if I want to make anything useful.  I think I’ll be up to the challenge on the OpenGL side of things.  But for Blender ?  Getting a good artist on board might be a smarter move.

return top