2
\$\begingroup\$

How do I draw a white crosshair in the middle of screen in openGL, it's all well and good knowing how to render objects in 3d space, but I have literally no idea on how to draw something that sticks on the screen no matter what

Would this require a shader? one that does not take into account model view projection matrix? at what point would i draw the cross? after everything to coincide with the painters algorithm? Or do I give it a z value?

\$\endgroup\$
2
\$\begingroup\$

To render a cross-hair, all you would need to do is render a piece of geometry using just a screen-space transformation, followed by the projection matrix. Mapping the identity matrix as your view will do this for you. A view matrix allows us to transform vertices into view space; removing this step allows us to go directly from model-space to screen-space. This will make it so that no matter how you turn, the reticle will stay in the same position.

\$\endgroup\$
  • \$\begingroup\$ One thing you should be careful with is that, when the View matrix is applied, we usually tend to define XY-plane as the "ground", but when the View matrix is removed, the XY-plane now becomes "the screen", and so no lines that are parallel to the Z-axis are displayed. I defined my crosshair as a line parallel to the Z-axis, and it didn't display itself. \$\endgroup\$ – Aleksandar Stefanović Nov 18 '18 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.