OpenGL prototype #1

Done on May 5, 2018

This prototype features modern OpenGL and primitive tessellation. The generated vertices’ attributes are modified based on a moving point resulting in some interesting visual effects.


So far, on my main project I’ve only used the SDL rendering API to display sprites and basic geometry, with calls such as SDL_RenderCopyEx [1], SDL_RenderFillRect or SDL_RenderDrawLines. Now to get more control over the rendering and obtain more advanced effects I’ll have to switch to OpenGL.

This is where I realized that my 10-year-old OpenGL knowledge wouldn’t cut it. The last time I worked on OpenGL was during university which was the old immediate mode OpenGL 2. So, a few months ago I decided to grab the OpenGL SuperBible 7th Edition [2] to catch up on modern OpenGL, its fixed function pipeline and GLSL. I read most of the concepts covered in this book and it is now time to apply some of those.


All of those examples start with the Vertex shader which passes 3 hardcoded vertices to the tessellation part of the pipeline. The Tessellation Control and Evaluation shaders are very standard. Their output is passed on to the Geometry shader as patches of 3 vertices. This shader then applies modifications to those vertices’ attributes based on the position of the moving point, which is passed as a uniform, and finally outputs line strip primitives.

In the first example, the one with the green effect, the geometry shader applies an offset to all of the vertices’ positions based on their distance and direction to the moving point. It results in a fake 3D effect, since the vertices remain strictly on the X/Y plane (their Z-component being unchanged).

In the second example, the one with the blue effect, the geometry shader applies a pseudo random position to all of the vertices in a certain range around the moving point.

In the last example, the geometry shader simply removes all of the vertices in a certain range around this point.

As far as I understand it, only this last example requires the presence of a Geometry shader which removes vertices. In the other examples I could have moved the vertices modifications directly in the Tessellation Evaluation shader.


[1] SDL_RenderCopyEx documentation
[2] OpenGL SuperBible main page

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s