Skip to main content
GameDev.net gamedev.net
🔒 Locked

Making a gui shader

Started by Saya Mar 1, 2008 at 11:39 AM 2 replies 2.3k views
Original Post
Saya
Saya
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..?
dpadam450
dpadam450
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.
NBA2K, Madden, Maneater, Killing Floor, Sims 
Yann L
Yann L
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.
dpadam450
dpadam450
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.
NBA2K, Madden, Maneater, Killing Floor, Sims 

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.