Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


OpenGL Screen Transformations


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Joshhua5   Members   -  Reputation: 475

Like
0Likes
Like

Posted 16 November 2013 - 11:01 PM

If I pass vertices to a shader between -1 and 1, with 0 being the middle of the screen.

would I be able to use those values without any modifications?



Sponsor:

#2 Kaptein   Prime Members   -  Reputation: 2180

Like
2Likes
Like

Posted 17 November 2013 - 04:27 AM

Yes

Those are the limits in the Normalized Device Coordinates system (NDC)

 

If you also want UV coordinates for this, simply do:

out_texcoord = (in_vertex + vec2(1.0)) * 0.5;

 

note that this is only for a fullscreen quad

for anything else you will want to provide UVs as well



#3 Samith   Members   -  Reputation: 2324

Like
0Likes
Like

Posted 17 November 2013 - 02:01 PM

Yes, but you must make sure that the w component of the vertex position is 1, because the perspective divide will still occur after the vertex shader. 



#4 Joshhua5   Members   -  Reputation: 475

Like
0Likes
Like

Posted 18 November 2013 - 10:39 PM

Thank you :)

 

What are the UV quads relative to?
If I provided a quad's verticies between -1 and 1 couldn't I use them again for the UV if it's relative to the screen

or -1 and 1 if it's relative to the quad.



#5 Kaptein   Prime Members   -  Reputation: 2180

Like
0Likes
Like

Posted 19 November 2013 - 12:21 AM

Thank you smile.png

 

What are the UV quads relative to?
If I provided a quad's verticies between -1 and 1 couldn't I use them again for the UV if it's relative to the screen

or -1 and 1 if it's relative to the quad.

UVs are texture coordinates, between 0 and 1, unless the texture repeats, always smile.png

Of course there are lots of variations on how people specify these coordinates due to eg. texture atlasing.

But, what I did in my example was simply scaling the vertex coordinates [-1, 1] to [0, 1] so that you could re-use the vertex coordinates for a fullscreen quad. Those UVs represent the entire texture.

 

To answer your question - yes, but you still need to rescale the UVs to match the [0, 1] scale of texture coordinates.


Edited by Kaptein, 19 November 2013 - 12:22 AM.


#6 Joshhua5   Members   -  Reputation: 475

Like
0Likes
Like

Posted 19 November 2013 - 12:49 AM

Great I see what you mean by a fullscreen quad, because the math would break otherwise.

That was the confusion.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS