Archived

This topic is now archived and is closed to further replies.

glViewport math

This topic is 5895 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

I wouldn''t mind knowing the math of it either (in world coordinates), so if a vertex I''m going to pass is off-screen, then I don''t even have to make a call (very helpful for particle engines).... It''d be nice to know.

------------------------------
Trent (ShiningKnight)
E-mail me
ShiningKnight Games

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What glViewport does is convert normalised device coordinates to window coordinates. The normalised coordinates are in the range [-1..1], and the window coordinates can be anything.

If your window is 640 pixels wide and 480 pixels high, then the conversion would be:

windowx = (normalisedx + 1) * 320
windowy = (normalisedy + 1) * 240

glViewport also defines an offset x,y, so the final formula is:

windowx = (normalisedx + 1) * (width/2) + x
windowy = (normalisedy + 1) * (height/2) + y

Share this post


Link to post
Share on other sites