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

#4963082 So I started writing Example Programs

Posted by on 25 July 2012 - 04:19 PM

I just added the first OpenGL 4 example. It shows tessellation: https://github.com/p...tesselation.cpp

It also has a simple phong lighting implementation and is funny in that it doesn't use a vbo at all. It generates the sample points by "abusing" instanced rendering and only uses gl_VertexID and gl_InstanceID and the texture as inputs so to speak.

Here is a video:

#4961281 make games using eclipse?

Posted by on 20 July 2012 - 05:56 AM


#4961185 Particle System...

Posted by on 19 July 2012 - 11:14 PM

I have some very bare bones code here: https://github.com/p...OpenGL-Examples
examples 07-09 are particle system to some extent. There isn't a whole lot to it actually... just just draw lots of billboarded quads at the particle positions. Everything else like how you want the particles to move, be shaded etc. is up to you. In that code up there I use a geometry shader for the rendering, you could just as well use instancing or even explicit quads.

#4961182 Hardware Occlusion Queries, why use them next frame?

Posted by on 19 July 2012 - 11:09 PM

At least OpenGL has conditional render which in theory would allow the occlusion queries also to stay on the GPU. I found this to work reasonably well on new hardware (gtx560ti) but very badly on my gtx260m. On the new hardware using the conditional render in the same pass as the queries gave me a speed up of factor 1.5-5 depending on the amount of occlusion. But it would actually reduce performance on the older GPU.

I have an example of this here: https://github.com/p...onal_render.cpp

Edit: DX seems to have this functionality as well I just wasn't sure at the point of writing the post since I'm not really experienced with DX

#4960966 Any way Render to VBO directly?

Posted by on 19 July 2012 - 09:15 AM

I have a transform feedback example in my examples: https://github.com/progschj/OpenGL-Examples/blob/master/09transform_feedback.cpp

#4959576 Need tips on collision response for a 2D ball hitting another 2D ball that is...

Posted by on 16 July 2012 - 07:03 AM

Not sure why everyone is so fascinated by working with angles. It usually makes things more complicated.

Anyway a simple collision resolution for this case is to simply offset each ball by half the penetration.
void resolveCollision(Ball &a, Ball &b)
	 vec2 diff = a.position-b.position;
	 double dist = length(diff);
	 double penetration = max(0, a.radius + b.radius - dist);
	 a.position += 0.5*penetration*diff/length;
	 b.position -= 0.5*penetration*diff/length;
Then you just apply that iteratively to all colliding pairs of balls and either have "multi collision" being sorted out over multiple time steps, or iterate this until there is no collisions anymore.
This doesn't handle velocity yet but I didn't really get how you want that resolved anyway? just cancel out relative movement? elastic collision

#4957987 Screen space , World space issue ?

Posted by on 11 July 2012 - 05:20 AM

In the first case input.Depth contains the values that resulted from matrix multiplication and then interpolation which still have not been perspective divided. I don't see why Depth.y would equal 1 there?

The second line simply does what it says there? Convert [-1,1] to [0,1]. Most likely because the "Normal" render target clamps values to [0,1].

#4957454 So I started writing Example Programs

Posted by on 09 July 2012 - 05:49 PM

I got the suggestion to use gl3w more than once Posted Image. For the moment I'll keep on this track, but since the examples are already partially "generated" (they are run through a simple program to create the index at the beginning) i guess i could also have that generate a gl3w version...

Somewhat related, after having completed the occlusion culling example I kept playing with it and after some amount of copy pasting from my own code and adding a deferred pipeline I ended up with this:


#4955802 So I started writing Example Programs

Posted by on 04 July 2012 - 06:15 PM

Timer/Occlusion queries + conditional render: https://github.com/progschj/OpenGL-Examples/blob/master/10queries_conditional_render.cpp
Slightly bloaty since for occlusion queries to make sense you need enough stuff to... well occlude each other. I ended up doing a voxel/cube renderer for that. On the one hand 700 lines for an example is a little long. But at the same time 700 lines for a voxel renderer with occlusion queries is fairly short I would say ;)

#4955116 So I started writing Example Programs

Posted by on 02 July 2012 - 06:19 PM

How about a deferred shader?

My problem there is that it doesn't rally show anything new in terms of OpenGL. The FBO FXAA already does that sort of. On the other hand I could use that to explicitly show multiple render targets.

In the meantime, I added two examples that both show a particle system. One implemented by moving the particles on CPU side and copying them to the vram via multiple mapped buffers and the other doing the same but staying on the gpu and moving the particles via transform feedback.

#4954849 Object oriented programming issue

Posted by on 02 July 2012 - 04:09 AM

They don't to the exact same thing. Simply put they allow to "coalesce" loops. So when you write:
Vector a(1024), b(1024), c(1024);
a = b*3.14+c;
then a naive implementation gets compiled to something like:
Vector tmp(1024);
for(int i = 0;i<1024;++i)
   tmp[i] = b[i] * 3.14;
for(int i = 0;i<1024;++i)
   a = tmp[i] + c[i];
but expression templates can give you:
for(int i = 0;i<1024;++i)
   a[i] = b[i] * 3.14 + c[i];

#4954409 So I started writing Example Programs

Posted by on 30 June 2012 - 06:34 PM

Small update: The examples now use layout qualifiers for the attribute locations (except for a variation of example 1 that is there to show the explicit binding). More importantly the examples now have a short index at the beginning that points out the line numbers of the newly introduced features.

The shader encapsulation is of course something that one would do in actual code (and I of course have wrappers that do exactly that). But as far as the examples are concerned I will not do that since I want to keep them self contained and free of my own "encapsulation design".

#4953939 So I started writing Example Programs

Posted by on 29 June 2012 - 06:34 AM

Maybe add a common module for the (common) shader stuff ? Posted Image

You mean as in a separate file or just separate functions? I'm aware that the examples aren't exactly best coding practice in terms of structuring etc. But I wanted to avoid introducing to much of my structure since that is one of the things that I often don't like in tutorials. That the author structures the code in some way that is intuitive to him but not me. Which in the end makes it harder to find what I'm actually looking for. Also I wanted the examples to be self contained without external includes other than the libs. I was considering putting something like a index on the top of the examples like:
 * lines x-y: shader setup
 * lines z-w: vbo setup
 * ...
to make it easier to find the relevant parts.
Can you elaborate on what you mean with modules?

Possibly, the attribute locations could be specified using shader layout commands instead of using glBindAttribLocation(). But I suppose using glBindAttribLocation() can be an advantage for some use-cases.

I guess I could add a variation of example 1 to show that possibility. Maybe I will move the other example also to use the layout version instead of BindAttribLocation. It indeed looks cleaner somehow.

Thank you for the feedback guys :) keep it coming.

The next examples I'm considering to add are sync queries and buffer mapping (for texture streaming), timer queries, occlusion queries and conditional render as well as transform feedback. For the moment I'm going through OpenGL3.3 features and after having covered those I'll also look into 4+ stuff (tessellation most notably). There might be other features I'm currently not thinkingof?

#4953771 So I started writing Example Programs

Posted by on 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).

#4953636 Object oriented programming issue

Posted by on 28 June 2012 - 06:09 AM

Also look at expression templates. Those are used to avoid creation of temporary objects to begin with and also help the compiler to optimize operations.