Lecture 12: Mid-term test solution & project CITS 3003 Graphics & Animation Slides: E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012
Objectives Explain solution to the mid-term test Explain the project requirements etc Show demos of the project 2
MID TERM TEST
Q1. (6 Mks) What are attributes and primitives in OpenGL? Give two examples of each. Answer Attributes: Properties that describe how an object should be rendered are called attributes OR 2 Mark Attributes are properties associated with primitives that give them their different appearances. E.g., Color, Size and Width, Stipple Pattern, Polygonmode etc. 1 Mark Primitives: These are the simplest elements provided in OpenGL. e.g. OpenGL supports lines, points, loops, triangles, etc., denoted by GL LINES, GL POINTS, GL STRIP, GL LOOP, GL TRIANGLES, GL TRIANGLE FAN, GL TRIANGLE STRIP. 1 Mark 1 Mark 1 Mark
Q2(a) (2 marks) What is the difference between request input mode and event input mode? Answer A computer has a number of input devices such as keyboard and mouse. These devices contain a trigger which can be used to send a signal to the OS. For the request input mode, the input is provided to the program only when the user triggers the device (e.g. entering a number then pressing <enter>). The program that requests this input comes to a halt until the input is entered. Since most computer systems have more than one input device, each of these devices can be triggered at an arbitrary time by the user. Each trigger from these input devices generates an event that is put in an event queue which can be examined by the user program. For the event input mode, the program may be executing many other operations (i.e., it does not come to a halt) while waiting for an event to be triggered.
Q2(b) (2 marks) Give any two common applications of vertex shaders in OpenGL Answer (i) Geometric transformations change relative location, rotation, and scale of objects/camera 3D perspective transformation - make far objects smaller (ii) Moving vertices morphing wave motion and deformation due to physical forces particle effects - fire, smoke, rain,... (iii) Lighting calculate shading color using light and surface properties special effect
Q3(a)(6 marks) (2 Mks) Why do we need a frame of reference? (2 Mks) Explain how points and vectors in 3D are represented in homogeneous coordinates. (2 Mks) Why is the use of homogeneous coordinates important in computer graphics? Answer We need a frame of reference to relate points and objects to our physical world, for example where is a point? We cannot answer this without a reference system. In homogeneous coordinates points and vectors are denoted by 4 dimensional vectors If we define 0.P = 0 and 1.P = P, then we can obtain the four dimensional homogeneous coordinate representation as follows: v = [a 1,a 2,a 3,0] T In vector the fourth dimension is zero, while for a point the 4th dimension is 1. v = [b 1,b 2,b 3,0] T Importance: Homogeneous coordinates are key to all computer graphics systems. All standard transformations (rotation, translation, scaling) can be implemented with matrix multiplications using 4 x 4 matrices since hardware pipeline works with 4 dimensional representations.
Q3(b) (4 marks) Explain what the following variables/functions do in an OpenGL program: Answer (i) gl_fragcolor (ii) glutinitwindowsize(175,450) gl_fragcolor : Built in variable. Assigns color to each fragment. glutinitwindowsize(175,450): Creates/sets/initializes a window with width 175 pixels and height 450 pixels
Q4 (a) (6 marks) What do the following functions do in OpenGL: 1) main(), 2) init() and 3) display()? Answer main(): creates the window, calls the init() function, specifies callback functions relevant to the application, enters event loop (last executable statement) init(): defines the vertices, attributes, etc. of the objects to be rendered, specifies the shader programs display(): this is a callback function that defines what to draw whenever the window is refreshed.
Q4 (b) (4 marks) What is a varying variable? Describe when it would be suitable to use a varying variable. Answer The qualifier varying is used to declare variables that are shared between the vertex shader and the fragment shader. Varying variables are used to store data calculated in the vertex shader and to pass down to the fragment shader. Again, because of the sharing of name space of the two shaders, varying variables must be declared identically in both shaders. The varying qualifier can only be used with floating point scalar, floating point vectors and (floating point) matrices as well as arrays containing these types.
PROJECT
Two parts Part-1 has been released. Part-2 will be released soon Submission due date : 01-June-2018 Marks Part-1 : 60 Part-2 : 40 Weightage : 40 % As the additional functionalities in part 2 of the project are actually an extension of the same C++ code from part 1, you only need to submit the final C++ code at the end of part 2 of the project. Backup your code regularly. You should target to finish part 1 before the end of week 10 to leave yourself sufficient time to complete part 2. Groups: You should complete this project in groups of two (group size = 2), but you may work alone if you choose (group size = 1). Each individual is also required to separately design and implement their own small extension of the specified functionality (task J).
Submission Guidelines Submit all your files to cssubmit. To submit your files, you will need to login to the system using your Pheme account. You must submit all your files including header files and base code. To ensure that your program works when we test it, you should submit a zip file that retains the directory structure of the program. Note: your scene editor will be tested on computers that are compatible to those in the labs. The report should be in PDF format. Please mention your full names and student numbers on the first page of the report. Please name your report file as report_surname1_surname2.pdf where surname1 and surname2 are the surnames of the students. If you are the only group member surname2 would be 00. If your group size is 2, then one of the group members must be responsible for submitting the code and report. Only one code and one report is required to be submitted per group. Within the report, individual efforts of the students on the coding should be detailed e.g. which student implemented which functionality.
Part-1 You are required to complete an implementation of a simple scene editor that allows a collection of objects to be arranged in a scene and various properties of them to be changed, such as colour, shininess and texture. Download the project-2018.zip file. You will also need a zip file that contains many texture map files. These files are for educational purpose and cannot be publicly distributed. A zip file (password protected) containing the texture map files can be downloaded from project page. The zip file contains a subdirectory named models-textures which should be placed in the same directory as scenestart.cpp. You are strongly suggested to use the pre-compiled assimp library files provided to you. You should see the shared library libassimp.so.3.1.1 in the LINUX_VERSIONS subdirectory and the dynamic library libassimp.3.1.1.dylib in the MAC_VERSIONS subdirectory.
How to run start-up code OpenGL installation on Linux You need to install mesa on your computer for opengl to run. sudo apt-get install build-essential libgl1-mesa-dev sudo apt-get install libglew-dev libsdl2-dev libsdl2-image-dev libglm-dev libfreetype6- dev # Debian, Ubuntu https://en.wikibooks.org/wiki/opengl_programming/installation/linux Now setup some links as follows on the terminal: ln -s libassimp.so.3.1.1 libassimp.so.3 ln -s libassimp.so.3 libassimp.so ln -s /usr/lib64/libglew.so.1.10 libglew.so Type: ls -l You should see two small symbolic link files (created by Step 2 above) pointing to the actual dynamic library file. Type: make This should compile scene-start.cpp and create the executable program scene-start In case some package is missing then please install it for example: sudo apt-get install freeglut3 freeglut3-dev sudo apt-get install libxmu-dev libxmu-headers
Type: source./setup How to run start-up code You need to do this command every time you open a new terminal window. If this does not work then paste the following command in the terminal: export LD_LIBRARY_PATH=. Type:./scene-start to run the skeleton program scene-start generated from the compilation (step 4 above). Note: you need to make sure the models-textures directory is in the same directory as scene-start.cpp
Assessment Details Your project part 1 has 60 marks and will be assessed on correctness of the functionalities and coding (structure, clarity and appropriate use of OpenGL). Tasks A to I carry 5 marks each. Task J carries 5+5 marks for the two additional functionalities each student is required to implement. The last 5 marks are reserved for the report. You can get upto 5 bonus marks by optionally completing task K.
Further Reading See the project page 18