Jump to content
  • Advertisement
Sign in to follow this  
Saya

Making a gui shader

This topic is 3791 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, currently to draw my gui i use glOrtho etc... to enable and disable 2D mode during rendering. I am learning GLSL and was wondering if this could be done with a shader instead. So basically i said to myself, for a hud the vertex coordinates (x,z) should correspond to screen coordinates (x,y). So the vertex shader should be: void main() { gl_Position = gl_Vertex; gl_FrontColor = gl_Color; } I also tried: void main(void) { gl_Position.xy = gl_Vertex.xz; gl_Position.z = 0.0f; gl_FrontColor = gl_Color; } And the fragment shader (no lighting): void main() { glFragColor = gl_Color; } Thats just with colors and no texturing so far but it doesnt work, any idea why? should i still use glOrtho etc..?

Share this post


Link to post
Share on other sites
Advertisement
Typically, I just call glVertex3f(0,0, #) where # is the nearPlane +1. This way it doesn't get culled out.

Your first vertex shader looks fine. Again your shit is probably getting culled out because of it z value.

Share this post


Link to post
Share on other sites
Doing it like this will work, but you should be aware of a few things. First, since you don't call ftransform (or do the transformation manually), you entirely bypass projection. That means that you have to supply your vertex coordinates in clipspace instead of screenspace. Second, you have to supply a valid .w component. Normally, the projection matrix will do all this for you. So I would suggest just calling ftransform in combination with a standard glOrtho projection matrix. It's much easier.

Share this post


Link to post
Share on other sites
Oh yea, thats your problem. You still want to multiply by the projection matrix. Because even though your not doing perspective projection, your doing ortho projection, which still maps into a new coordinate system. Whats happening is all your vertices for the gui are getting clipped.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!