Presentation is loading. Please wait.

Presentation is loading. Please wait.

Class 1: First Program.

Similar presentations


Presentation on theme: "Class 1: First Program."— Presentation transcript:

1 Class 1: First Program

2 // Draw a polygon with specified vertices.
square.cpp // Draw a polygon with specified vertices. glBegin(GL_POLYGON); glVertex3f(20.0, 20.0, 0.0); glVertex3f(80.0, 20.0, 0.0); glVertex3f(80.0, 80.0, 0.0); glVertex3f(20.0, 80.0, 0.0); glEnd();

3 Some experiments - change some values of vertices
Make the square smaller. Move it around. Make it really big. Try some negative numbers. Change the z-values.

4 // Set OpenGL window size. glutInitWindowSize(500, 500);
square.cpp // Set OpenGL window size. glutInitWindowSize(500, 500); // Set position of OpenGL window upper-left corner. glutInitWindowPosition(100, 100);

5 Try changing values glutInitWindowPosition(0, 100);
glutInitWindowSize(300, 300); glutInitWindowSize(500, 250);

6 // Specify the orthographic (or perpendicular) projection,
square.cpp // Specify the orthographic (or perpendicular) projection, // i.e., define the viewing box. glOrtho(0.0, 100.0, 0.0, 100.0, -1.0, 1.0);

7 glOrtho( left, right, bottom, top, near, far )
Viewing box Notice the "-" in front of near and far

8 glOrtho( left, right, bottom, top, near, far )
Remember the "-" in front of near and far when creating the viewing box

9 Construct a scene using world coordinates.
Rendering Set up a viewing box – what part of the world scene do we want to look at. World coordinates. Construct a scene using world coordinates. Project the scene onto the front of the viewing box Shoot Set up a window using screen coordinates Set up a viewport within the window, using screen coordinates. Print Map the front of the viewing box to the viewport.

10 Project the scene onto the front of the viewing box
Rendering glOrtho(0.0, 100.0, 0.0, 100.0, -1.0, 1.0); glBegin(GL_POLYGON); glVertex3f(20.0, 20.0, 0.0); glVertex3f(80.0, 20.0, 0.0); ... glEnd(); Shoot Project the scene onto the front of the viewing box glutInitWindowSize(500, 500); glutInitWindowPosition(100, 100); glViewport(0, 0, (GLsizei)w, (GLsizei)h); Print Map the front of the viewing box to the viewport.

11 Rendering process Shoot: Project objects onto the front face of the viewing box Print: Proportionately scale the viewing face to the OpenGl window on the screen.

12

13 Coordinates In the viewing box we use world or object coordinates.
On the screen we use screen coordinates.

14 Experiment with the viewing box
Make some changes to the coordinates in glOrtho and see what happens. Make the square appear in the upper right hand corner. Pick a viewing box where you won't see the square at all. Pick a viewing box where you see part of the square.

15 Screen coordinates


Download ppt "Class 1: First Program."

Similar presentations


Ads by Google