Creating a hud/gui with GLSL

Started by
3 comments, last by pilarsor 12 years ago
Hi, I am creating a game for my university project and now I am coming round to creating a hud, but I don't know how I should go about doing it with glsl. Can anyone help please?
Advertisement
Try the following steps:

1.) Switch to orthographic projection
2.) Prepare your hud geometry
3.) Apply a vertex and fragment shader to your hud geometry
4.) Draw your triangles describing or hud geometry


When you choose your vertex shader, think about, how you would like to transform your vertices... e.g. just as linear transform e.g. applying the mere modelviewproj transform, or as non-linear transform, e.g. where you treat each vertex with a different offset vector ( computed in the vertex shader ).
Prepare the fragment shader with values per vertex to be interpolated for each fragment.

For your fragment shader, think about how you would change your fragments of your rendered hud area on screen. E.g. use interploated uv values across the triangles as input for a function for pixel color distortion ( executing inside the fragment shader ), or anything else what comes into your mind...
ok I'll try and implement this, so I will have to rotate the vertices as the game is a first person shooter, so it rotates with the camera. Also, how can I create a dynamic text variable for the hud, such as the score?
Well, I mean how can I show it through the shader?
Dynamic text is something, that you might want to prepare in your c++ code.
Take a texture containing the letters of the alphabet, each letter in the texture equally spaced in width and height.
Write a C++ module, that inputs a string and you basically convert each character in the string to an u,v offset in the 2D alphabet texture.
For rendering this text as textured quads for example, you can just use a standard vertex and fragment shader, which has the functionality of a vertex/fragment shader pendant of a fixed function pipeline.

But sure, if you like, go ahead and do something fancy with that text, e.g. like displacing the quad vertices, distorting the uv coords, or applying some function for color generation...

This topic is closed to new replies.

Advertisement