Sign in to follow this  
Saya

Making a gui shader

Recommended Posts

Saya    112
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
dpadam450    2357
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
Yann L    1802
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
dpadam450    2357
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

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