33
Computer graphic --OpenGL Tutorial

Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

Embed Size (px)

Citation preview

Page 1: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

Computer graphic

--OpenGL Tutorial

Page 2: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

2

About me

• Who: Jie Chen

• What: Teaching assistant, Lab exercises

• How: TS329

• Email: [email protected]

Page 3: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

3

• Website:http://www.ee.oulu.fi/~jiechen/Course.htm

• Prerequisiteprogramming skills using C/C++

Page 4: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

4

• Tools: OpenGL

• Task: what OpenGL is and how it enables us to program in 3D.

• GL: graphic library

Page 5: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

5

What is OpenGL?• It's a way to draw stuff in 3D.

– It can also be used for 2D drawing, but this course doesn't focus on that. There are better tools for straight 2D drawing, such asSDL and Allegro.

• The purpose of OpenGL is to communicate with the graphics card about our 3D scene. – The graphics card is where the 3D computation happens. – So why not talk to the graphics card directly?

• Each graphics card is a little different.• In a sense, they all speak different "languages". To talk to them all,

we can either learn all of their languages, or find a "translator" that knows all of their languages and talk to the translator, so that we only have to know one language.

• OpenGL serves as a "translator" for graphics cards.

Page 6: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

6

Some Terminologies• OpenGL

– GL: graphic library

– a software interface to graphics hardware.

– This interface consists of about 150 distinct commands.

Page 7: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

7

Some Terminologies• GLU (OpenGL Utility Library)

– GLU is a standard part of every OpenGL implementation.

– A sophisticated library that provides the features could be built on top of OpenGL.

– Provides many of the modeling features, such as • quadric surfaces and • NURBS (Non-Uniform Rational B-Spline) curves and

surfaces.

Page 8: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

8

Some Terminologies• GLUT (OpenGL Utility Toolkit)

– a window system independent toolkit for writing OpenGL programs.

– It implements a simple windowing application programming interface (API) for OpenGL.

– GLUT makes it much easier to learn about and explore OpenGL Programming.

– Controlling the IO layer • input: mouse and keyboard • output: visual windows

Page 9: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

9

Include Files

• For all OpenGL applications, we need to include the gl.h header file in every file.

• Almost all OpenGL applications use GLU, which requires inclusion of the glu.h header file. So almost every OpenGL source file begins with– #include <GL/gl.h>– #include <GL/glu.h>

• If we are using GLUT for managing our window manager tasks, we should include– #include <GL/glut.h>

• Note that glut.h includes gl.h and glu.hautomatically

Page 10: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

10

Getting OpenGL Set Up• In following part, we will show how to get

OpenGL and GLUT set up on Windows, so that we can get started making 3D programs.

• we can use OpenGL on other operating systems, but this part doesn't cover how to get it set up on those OSes.– Mac OS X

http://www.videotutorialsrock.com/opengl_tutorial/get_opengl_setup_mac_osx/home.php

– Linuxhttp://www.videotutorialsrock.com/opengl_tutorial/get_opengl_setup_linux/home.php

Page 11: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

11

Getting OpenGL Set Up on Windows

• Explain how to get OpenGL and GLUT set up on Windows (e.g., windows XP).

• Use the Visual C++ 6.0. • You can also use other version, such as Visual

C++ 2003, 2005, 2008. – CSE: Computer science and engineering laboratory

• You can find it in our server– Other department:

• you can downloade here:• http://msdn.microsoft.com/zh-cn/express/default.aspx• You have to register, which is free, within 30 days.

Page 12: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

12

OpenGL

• Download – OpenGL installer – GLUT binary

• http://www.ee.oulu.fi/~jiechen/Course.htm• Lecture notes ->Lecture 3

Page 13: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

13

OpenGL setup

• Run the OpenGL installer.

Page 14: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

14

GLUT setup• Extract GLUT to the directory of your choice. • We can do this by creating a new directory,

locating and opening the ZIP file using Windows Explorer, and copying the files to the new directory using copy-paste.

• Alternatively, We can use a free program like WinZip to extract GLUT.

Page 15: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

15

GLUT setup

• In the directory GLUT, make two folders – one called "include" and – one called "lib".

• File assignment:– In the "include" folder, create another folder

called "GL", and move glut.h to that folder (..\Include\GL).

– Move all of the other extracted files for GLUT into the "lib" folder.

Page 16: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

16

Setup for Visual C++• Run Visual C++ • Go to Tools -> Options-> Directories • Adding " GLUT \include", and " GLUT \lib"

Page 17: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

17

Setup for Visual C++

• glut32.dll (dll: Dynamic-link library)

Page 18: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

18

Compiling and Running the Test Program

• To make sure that everything was set up correctly, we're going to see if we can get a test program to work.

• Download test program and extract it somewhere on your computer.– http://www.ee.oulu.fi/~jiechen/Course.htm– Lecture notes ->Lecture 3

Page 19: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

19

Compiling and Running the Test Program

• Run Visual C++. • Go to File -> New ->

Project• Select Win32 Console

applications• Set the project file

location. • Enter in a name for

your project (such as “CG") and click ok.

Page 20: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

20

Compiling and Running the Test Program

• Select “a ‘hello world’ applications”• click “Finish” to finish creating the project.

Page 21: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

21

Compiling and Running the Test Program

• File copy– extracted the downloaded test program– Copy the following files to the current folder

Page 22: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

22

Compiling and Running the Test Program

• File content modification– Copy the code in main.cpp to replace those in

CG.cpp

– Add #include "stdafx.h” at the beginning of CG.cpp

Page 23: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

23

Compiling and Running the Test Program

• Change from "Debug" to "Release".

Page 24: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

24

Compiling and Running the Test Program

• File adding– Two files: imageloader.h and imageloader.cpp– Press ok

Page 25: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

25

Compiling and Running the Test Program

• File adding– Lib file: glut32.lib– Press ok

Page 26: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

26

Compiling and Running the Test Program

• Workspace view

Page 27: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

27

Compiling and Running the Test Program

• Go to Build -> Build project_name (e.g., Build CG.cpp) to build our project.

Page 28: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

28

Compiling and Running the Test Program

• Run it!

Page 29: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

29

Compiling and Running the Test Program

• Take a look at main.cpp. – Notice that the include directives

for OpenGL appear after the #include directives for the normal C++ include files.

– If we had them in the opposite order, you'd get a compiler error. So make sure that the include files for the standard C++ stuff appear before the include files for OpenGL. ERROR

Correct

Page 30: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

30

Compiling and Running the Test Program

• Whew! We've finished setting up OpenGL.

• Now we're ready to learn how to program in 3D.

Page 31: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

31

Demo

Page 32: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

32

• OpenGL Programming Guide or ‘The Red Book’– http://unreal.srk.fer.hr/theredbook/

Page 33: Computer graphic --OpenGL Tutorialjiechen/Course/Lecture 3- howto OpenGL/HowTo.pdf · 10 Getting OpenGL Set Up • In following part, we will show how to get OpenGL and GLUT set up

33

• The end of this lecture!