#### Archived

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

# glViewPort()

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

## 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 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 on other sites
manzooret chije agha?

1. 1
Rutin
26
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 14
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631757
• Total Posts
3002135
×