Monthly Archives: September, 2012

Let there be more lights!

Lately I’ve been messing around with OpenGL 3.3 core / GLSL lighting a bit more.

First I created a scene with a floor and the now used to boredom box of mine. Then I added a global light  source ( that is it doesn’t change with the camera like the one I posted about earlier ) with red color and started to experiment a little with light color and texture color mixing:

Obviously this one wasn’t a very successful experiment 😛

The next one was a little bit better already:

This time in addition to the color mixing changes, I also changed how ambient light is handled: The parts where the diffuse red light source cannot light the scene are only lit with the ambient light source, which basically only modifies the luminosity of the texels. The result is as it can be seen on the picture, the side of the box is not colored red.

After all this I worked on it a bit more and added another diffuse light source, with blue color and a direction that can hit the box where the red light can’t, therefore one side of the box becomes reddish the other side becomes blueish. The floor of course becomes a mix of the two.

Here’s video that shows it, enjoy!

Let there be light!

…and then I said, let there be light! …and there was light!

So after having studied OpenGL shaders a bit in my book, I’ve made another textured cube: this time the texture is a wooden box instead of the OpenGL logo. Also I’ve added lighting using vertex and fragment shaders.

Basically how it works is, there’s a diffuse light source in the scene at -100.0, 100.0, 100.0 and some ambient lighting too ( 30% ambient contribution ). The vertex shader interpolates the texture coordinates, and the diffuse lighting between the vertices for the fragment shader, and then the fragment shader samples the texture at the interpolated coordinates and multiplies the color with ( ambient + diffuse ).

Fairly simple, and yet looks pretty nice imho. So enjoy!

 

My first OpenGL demo

Since I’ve been playing around with OpenGL for a little while now, I could finally create a little demo.

It’s very very simple, but basically show the things I can already do. It has no shading/lighting, no music, or anything that fancy yet, but I’d think it’s a good start!

So, enjoy!

 

opengl texture mapping

Texture mapping makes 3D life just a little spicier.

My first OpengGL rendered cube!

So I’ve been reading OpenGL Superbible 5th edition a bit more, and playing around with some code, and eventually decided it’s time to try to render a cube. I also added support for rotating the cube with the up/down and left/right keys.

Here’s the result:


I think I am in love, with OpenGL! 😀