Archived

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

Null and Void

glViewport math

Recommended Posts

mittens    1323
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   
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