Advertisement

glViewPort()

Started by May 06, 2003 06:30 AM
1 comment, last by farzad13512000 21 years, 9 months ago
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
be succesful
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]
Advertisement
manzooret chije agha?

This topic is closed to new replies.

Advertisement