#### Archived

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

# glViewport math

This topic is 6179 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
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

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632595
• Total Posts
3007266

×