SUN YAT-SEN UNIVERSITY
Homework 2: Hello, OpenGL!
Computer Graphics
2017-02-027
1. Introduction
Welcome to the first programming homework of CG course! I believe most of you started your programming careers by writing a simple program called ‘Hello, world!’. Let’s do the same thing with OpenGL! In this HW, you are required to draw some basic primitives with OpenGL and to know about some inner operating mechanisms of OpenGL.
Warning: We encourage discussions among students, but codes and documents should be written and submitted individually, without copying existed answers (Neither from other student nor from the Internet). Plagiarism = Fail. Besides, there may be at least 30% penalty for late homework.
2. Tasks
2.1 Pre-requirement
-
Language: Since OpenGL is more like a standard/API than a language, it has many bindings/wrappers/versions such as PyOpenGL/WebGL/JOGL/OpenTK/LWJGL(which is used in Minecraft)… But only C/C++ is accepted in this homework. See references to know why.
-
Libraries: Since OpenGL itself do not contain any windows management or Keyboard/Mouse controlling APIs, we still need extra library to do the job. Only freeglut.h and glfw.h is accepted. See references for more information.
-
IDE: Any IDE can be used. We recommend Code::Blocks and Visual Studios. You can even do it without any IDE! (Make sure you submit a makefile along with your sources.)
2.2 Hello, triangle!
Write a program to draw some basic primitives in one window.
-
Draw a triangle. The result may be this:
- Change the color of 3 vertices into Red, Green and Blue. What does the result look like? Explain why this happen in your report.
- Write down your main algorithm and post your results in your report.
- Bonus: Draw other primitives, such as quads, points, lines, polygons… Draw as many as you can in one window. You can even create your own art with these primitives.
3. Submitting Format
Please submit your homework to sysucg2017@163.com. You subject of the email should be as same as your attachment(aka. your .zip file)
Only a .zip file should be submitted. Under the .zip file, the content should look like this:
classTpye_studentID_Name_hw?_version?/
|— src/
|— doc/
|— bin/
- classType: R for required class(必修班); E for elective class(选修班).
- studentID: 1xxxxxxx
- Name: Your Chinese Name.
- hw?: Specific which homework you are submitting.
- version?: Specific if you modify your submitted homework, only the last version would be graded. Started with version0.
- src/: The folder holds your project, including source files.(Make sure you execute the clean command, we don’t need those temporary files)
- doc/: Only one PDF should be included.
- bin/: Executable program and a ReadMe.txt to tell us how to run your program.
For example, a student in required class want to submit homework2 for the second time, his .zip file should be:
R_16214382_杨耀兴_hw2_version1.zip
|—R_16214382_杨耀兴_hw2_version1/
|—src/ ——放整个工程
|—doc/ ——放report.pdf
|—bin/ ——放可执行文件和readme
4. References
[1] Why C/C++?
C/C++ is the only common language you guys know. All of classic books and websites used C/C++ as a language for code samples. C/C++ seems to be the most popular choice in this area.
It is worth noticing that no matter what programming language you chose, the graphics theory is the same. So if you know how to make a graphics effect in one language, then it should be relatively easy to do it similarly in some different language.
Anyway, you can try other language’s OpenGL at some time —— Not in this homework.
All supported languages: https://www.khronos.org/opengl/wiki/Language_bindings
[2] freeglut project: http://freeglut.sourceforge.net/
[3] glfw project: http://www.glfw.org/
[4] Enviorment configuration:
- freeglut: http://www.cnblogs.com/joyeecheung/p/4310487.html
- glfw: http://wiki.codeblocks.org/index.php?title=Using_GLFW_with_Code::Blocks