OPENGL Introduction: Question 3: Drawing in 3D

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Jean-Marc Vzien

International Masters in biometrics


3D modeling and Augmented Reality

OPENGL introduction
This is a hands-on session of OpenGL. Using the template project called graphicsTest,
you will progressively build your own OpenGL application.

Question 1: Getting started


Download the GraphicsTest projet. Make sure GLUT is installed on your computer. Open
the graphicsTest.cpp file. Identify :

The rendering routine


The initialization routine
The interaction routines (mouse, keyboard)

Why is the graphics window blue ? How do you quit the program ?

Question 2: 2D drawing (Orthographic mode)


Important : For 2D drawing, set the GL_PROJECTION with glOrtho() in GLUTResize()
func !
Using the proper calls in GL_LINES mode:

Draw a red triangle in the middle of the window


Draw a green spring:

Question 3: Drawing in 3D
The skeleton program contains everything to draw a cube but you need to change and edit a
few things!

Identify the routine that draws a cube and insert a call at the right location
The coordinates of the cube vertices need to be initialized !
1

Jean-Marc Vzien
International Masters in biometrics
3D modeling and Augmented Reality

The GLUTResize function needs to be changed. No calls to glOrtho() here !

Notice the lighting instructions and camera positioning. Try to comment out the calls to
glTranslatef() and glRotatef() and look at the result.

Question 4: modify the camera view


Starting from the result of question 3, change the GLUTMotion() routine to capture the mouse
motion, so that :
-

A horizontal motion with left button pressed rotates the object around vertical axis
A vertical motion with left button pressed rotates object around horizontal axis
Any mouse motion with Ctrl + button pressed zooms in and out (translation of
camera)

Question 5: Animation

Exploiting question 4, design an automatic animation where the cube rotates around
the Z axis at the speed of 10 degrees per second.
Animate the cube so that it rotates for 5 seconds around the Z axis, then around the X
axis for for 5 more seconds, then cycle again.

Note: You must make use of glutTimerFunc() to make sure the drawing takes place at the
correct time.

You might also like