Sign in to follow this  
amerigo14

Creating a hud/gui with GLSL

Recommended Posts

amerigo14    107
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?

Share this post


Link to post
Share on other sites
pilarsor    130
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...

Share this post


Link to post
Share on other sites
amerigo14    107
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?

Share this post


Link to post
Share on other sites
pilarsor    130
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...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this