Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 25 Aug 2009
Offline Last Active Oct 02 2013 05:18 AM

Topics I've Started

OpenGL 4.3 - compute shaders and much more

06 August 2012 - 11:59 AM

OpenGL 4.3 is here:


Beta drivers from Nvidia:

And I obviously had to quickly try out compute shaders:

Yay! Posted Image

How do I post comments on articles?

03 August 2012 - 01:43 PM

I wanted to comment on this article: http://www.gamedev.net/page/resources/_/technical/game-programming/2d-rotated-rectangle-collision-r2604
But when I click on comments I don't see a text box or so to write one. If I do the same for articles that already have comments I see a textbox?

So I started writing Example Programs

28 June 2012 - 03:46 PM


so about two years back I again got into OpenGL (the first time was a failure being way back at the beginning of my programming career). Specifically I was only interested in learning "modern OpenGL" so 3 and later. Since at that time I already was pretty competent with C++ and math I figured it would be relatively easy. But then I got quickly frustrated with the online resources that are available. The majority is outdated and littered with deprecated functionality and most or the tutorials are more graphics programming tutorials that happen to use OpenGL instead of actually focusing on OpenGL. You know the ones that go: "how to open a empty window", "how to draw a triangle", "how to load a model"... wait? what has loading a model to do with OpenGL?
So I often ended up reading reference pages and specs but that is somewhat frustrating without examples to go along with them. And searching for examples again resulted in lots of deprecated code and otherwise frustrating stuff like OpenGL functionality wrapped away under custom frameworks. I want to learn about OpenGL after all and not about how the author likes to wrap it.

So I finally started to write examples like I would have wanted them myself. Partly so I have code lying around that I can refer to myself but also because I think there might be other people like me out there. The current state is available on github:


The basic Idea is that each example is self contained (not reliant on some base code or obscure libraries) in a single file and is meant to provide a clean usage of one or multiple OpenGL 3+ features. Sadly I still have to rely on some libraries for context creation etc. so the examples depend on glfw, glew and glm.

The reason why I post this here is that I want more feedback and suggestions. So please let me know what you think. Also tell me if there is something wrong with my English in the comments, I'm not a native speaker after all. And since I'm already shamelessly plugging my stuff I usually announce new examples on my twitter (see signature).

Unreasonable frame times in XNA

04 February 2012 - 02:45 PM

So I figured I'd look into XNA/C# to widen my horizon. Now everything went smoothly until I changed the resolution of my Program. At the time I was only displaying 3 sprites and it went all choppy. Full screen on the other hand seems ok'ish again. Even an "empty" program has bad performance. I just checked that by creating a XNA project and inserting:
            graphics.PreferredBackBufferWidth = 1024;
            graphics.PreferredBackBufferHeight = 768;
            graphics.IsFullScreen = false;
            this.IsFixedTimeStep = false;
into the Initialize function and
into the Update function.
This outputs wildly varying times in the range 20-50ms.
Hardware shouldn't be an issue since a i5-580m and a GTX260m should be plenty.

Not changing resolution or going fullscreen gives ok performance. Weirdly it still seems to be vsynced even with IsFixedTimestep = false.

Spherical "fog"

26 January 2012 - 07:22 AM


so normally I feel pretty competent about anything math related and can figure it out, but this issue is driving me nuts. I want a landscape to blend into the background at a given distance. Now simply using the linearized z values results in larger view distance in the corners than in the center (since the z value is the distance from the projection plane an not the actual camera position). So I figured I can apply that distance falloff in my deferred step. But it seems I'm incapable of calculating the correct "spherical distance". First I figured I'd do the brute force approach and reconstruct the world position of my fragment and calculate the distance that way. So this is how I calculate the world space coordinates in the shader:

vec3 worldspace(vec3 x) {

   vec4 pos = invprojection*vec4(x, 1);

   return pos.xyz / pos.w;


where x is vec3(screen.xy, depth) (depth as read from the depth buffer)

It almost seems to work but it's always slightly off and the coordinates "creep" around when moving the camera. I did check that invprojection is actually the inverse (proj*invproj = identity). Also it seems to work when I transform a vector back and forth on the cpu side. As a result I now got the reverse effect that the view distance in the corners was lower...

After spending hours on trying to figure out what was wrong I started over and tried to do it without the explicit reverse transform:

float spherical(float z, float f) {

   return f*(near_far.x + (near_far.y-near_far.x)*2.*near_far.x/(near_far.x + near_far.y - z * (near_far.y-near_far.x)))/near_far.y;


where f is a correction factor that is calculated as sqrt(1+dot(screen.xy, screen.xy)), which should be the cosine between view and fragment direction.
Interestingly this gives the exact same result as my former approach... ARGH

1. is there something Obviously wrong with the way i calculate the world space coordinates?
2. Am I missing something else that prevents this from working that is not related to my actual distance calculation?
3. Is there a better (canonical) way to do this?