Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Systems
Coordinate Systems
Glut
OpenGL
(0,0)
(2,2)
10 feet
20 feet
Another example:
plot a sinc function:
sinc(x) = sin(PI*x)/PI*x
x = -4 .. +4
World Window
W_T
W_B
W_R
gluOrtho2D(left,right,bottom,
top)
Viewport
V_T
V_B
V_L
V_R
A simple example
DrawQuad()
(300,200)
{
glViewport(0,0,300,200);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1,1,-1,1);
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex2f(-0.5,-0.5);
(0,0)
glVertex2f(+0.5,-0.5);
viewport
glVertex2f(+0.5,+0.5);
glVertex2f(-0.5,+0.5);
How big is the quad?
glEnd();
}
Window to viewport
mapping
(x,y)
World window
(Sx, Sy)
Window to viewport
mapping
(x,y)
(Sx, Sy)
Window to viewport
mapping
Window to viewport
mapping
Window to viewport
mapping
(x,y)
=
=
Window to viewport
mapping
(sx,sy)
(x,y)
=
=
min Y
min X
max X
Viewport
Non-distorted viewport
setup
World window
Aspect Ratio = R
W
Display window
Aspect Ratio = W / H
R> W/H
R
World window
Aspect Ratio = R
?
W
Display window
Aspect Ratio = W / H
R> W/H
R
World window
Aspect Ratio = R
R> W/H
W/R
W
Display window
Aspect Ratio = W / H
glViewport(0, 0, W, W/R)
World window
Aspect Ratio = R
W
Display window
Aspect Ratio = W / H
R< W/H
World window
Aspect Ratio = R
W
Display window
Aspect Ratio = W / H
R< W/H
World window
Aspect Ratio = R
R< W/H
W
Display window
Aspect Ratio = W / H
glViewport(0, 0, H*R, H)
Initialization
glutDisplayFunc(display);
glutReshapeFunc(resize);
glutKeyboardFunc(key);
main()
OpenGL Default:
{
glViewport: as large as
glBegin(GL_QUADS);
you display window
glColor3f(1,1,0);
glVertex2f(-0.5,-0.5);
gluOrtho2D:
glVertex2f(+0.5,0);
gluOrtho2D(-1,1,-1,1);
glVertex2f(+0.5,+0.5);
glVertex2f(-0.5,+0.5);
glEnd();
}
Every time you learn a new OpenGL
function, always try to know its defa
arguments
Why?