Drawing a simple crosshair?

I’m having a lot of trouble drawing a crosshair to the centre of the screen with modern OpenGL. Most other tutorials or posts use outdated methods, or another library. How can I simply draw a crosshair shape (or a simple dot, small circle etc.) in the centre of the screen?

I’ve tried following tutorials like this: https://guidedhacking.com/showthread.php?6588-OpenGL-Draw-a-crosshair, but with no luck.

Right now, the only way I can see how to do this is by having a crosshair model and moving it in relation to the camera, but that seems a bit unnecessary. How would I do this with OpenGL lines for example?

Thanks.

Don’t use the same matrices for the crosshair (or any other HUD elements) that you’d use for objects which are part of the world.

Do you use your own shaders? If you do write a new shader for the crosshair which uses no modelview matrices and an orthogonal projection. After that it should be very easy to draw the actual crosshair. Either draw a VBO containing primitive shapes (lines, triangles or whatnot) or draw the texture of a crosshair as a quad.

If you dont use custom shaders just set the model and view matrices to identity and the projection matrix to orthogonal.

[QUOTE=Cornix;1286252]Do you use your own shaders? If you do write a new shader for the crosshair which uses no modelview matrices and an orthogonal projection. After that it should be very easy to draw the actual crosshair. Either draw a VBO containing primitive shapes (lines, triangles or whatnot) or draw the texture of a crosshair as a quad.

If you dont use custom shaders just set the model and view matrices to identity and the projection matrix to orthogonal.[/QUOTE]

I do have some simple texture shaders, but I’m not really confident with using them, so I don’t know how I’d do it with a shader exactly. If I were to do the second thing you mentioned, how would I then draw the lines with orthogonal? Every tutorial or code snippet I look at doesn’t seem to work with me since they’re all outdated :confused:

try this example:

read more about textures here:
https://alfonse.bitbucket.io/oldtut/Texturing/Tutorial%2014.html

basically you need to:
– create a texture object
– set some texture parameters
– allocate memory / fill the memory with your data (e.g. an image or calculated values of a complicated function)
– bind that texture object to a certain texture unit
– tell the “uniform sampler2D tex;” in your shader from what texture unit to sample

then you can read the texture data via “vec4 texture(tex, …some coords…);” in your shader, “vec2 somecoords” is the location from where to read the data, you have to provide that value somehow, e.g. via passing it from the vertexshader where it could be a “vertex attribute”