Archived

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

glViewPort()

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

excu me the english is not my first language. i have a problem in OpenGL i create a window by visual c++ 6.0 . then i initial the window for OpenGL . i use glViewPort(0,0,400,400) and draw a line like this glBegin(GL_LINES) glVertex3f(0,0,0) glVertex3f(1,1,0) glEnd but it draws a very tall diagonal line (why Tall)? after it when i decrease the viewport like this glViewport(0,0,100,100) i think that it draws the line taller than ago but new line is drawn smaller than old line (why) ? please help me : what glViewport really do ? thanks

Share this post


Link to post
Share on other sites
Assuming you haven't modified your GL_PROJECTION matrix, glViewport simply scales the points you are drawing:

glViewport(x,y,w,h)

screen_x = (point_x * (w/2)) + x
screen_y = (point_y * (h/2)) + y

(here point_x,point_y are the positions you've specified with glVertex, screen_x,screen_y are the pixel positions on the window)

Now it's not exactly those equations (see the OpenGL spec or some other OpenGL book for details of what they actually are).

So you can see:

glViewPort(0,0,400,400)

(0 * 200) + 0 = 0
(0 * 200) + 0 = 0

(1 * 200) + 0 = 200
(1 * 200) + 0 = 200

glViewport(0,0,100,100)

(0 * 50) + 0 = 0
(0 * 50) + 0 = 0

(1 * 50) + 0 = 50
(1 * 50) + 0 = 50


[edited by - JuNC on May 6, 2003 2:38:44 PM]

Share this post


Link to post
Share on other sites