OpenGL簡介、視窗程式與相關環境設置

講者:羅右鈞

時間:2015.7.21

地點:交通大學

OpenGL 簡介

What is OpenGL ?

- Open Graphic Library

- Open Specification, not Open Source

- 2D & 3D Graphics rendering API

- Highly depend on graphic hardware

- Cross platform

- Focus on rendering. Not provide animations, timing, GUI ...

                                     

OpenGL 簡介

OpenGL Libraries 

- OpenGL Core Library (GL) 

- 用於常規、核心的圖形處理

- 函數以gl開頭,例如 glBegin, glColor3f, glVertex3f, glEnd 等

- OpenGL Utility Library (GLU)

- 建立於 core library 之上

- 函數以glu開頭,例如 gluPerspective, gluLookAt 等

- OpenGL Utility Toolkit (GLUT)

- 非OpenGL,完全獨立於GL, GLU

- 提供簡單的視窗介面,你也可以使用別的native的window toolkit

- 函數以glut開頭,例如 glutInitWindowSize, glutDisplayFunc, glutMouseFunc 等

- 目前都使用freeglut而不使用GLUT,它是GLUT的擴充版,較為穩定

OpenGL 簡介

OpenGL Libraries 

- OpenGL Extension Wrangler (GLEW) 

- Cross-platform open-source C/C++ extension loading library.

- In modern OpenGL, the API functions are determined at run time, not compile time. GLEW will handle the run time loading of the OpenGL API.

- Without GLEW, we will do many heavy works like this when using modern OpenGL API :

OpenGL 簡介

OpenGL Pipeline Types 

- Fixed function pipeline (Legacy OpenGL)

- Programmable pipeline (Modern OpenGL)

- Released in OpenGL 1.0

- Deprecated in OpenGL 3.0, but it's still available

- Unable to write your own effect. Operations are fixed by the implementation

- Released in OpenGL 2.0

- need to write shader programs by yourself. Using GLSL programming language

OpenGL 簡介

Before OpenGL programming, you need to know ...

- OpenGL is a state machine

- OpenGL is not object-oriented

- OpenGL function syntax : glVertex3fv

Prefix

gl

glu

glut

#Param

1

2

3

4

 

Data type

b (byte)

s (short) 

i (integer)

f (float)

d (double)

vector

OpenGL 簡介

How to draw an object ?

- Objects are composed of points, lines or polygons

- Specify vertices in counter-clockwise order

Environment Setup Demo

OS : Windows 7

IDE : Visual Studio 2013

(For mac OS X, please refer to here)

Step 1  : 下載 FreeGLUT and GLEW (已經幫大家打包好了)

Step 2 : 打開 Visual Studio 並新增專案,選擇「Visual C++」的「空專案」(取消勾選「為方案建立目錄」)。

Step 3 : 在「原始程式碼」中點選「新增項目」來新增 C++ 檔 (cpp)

Step 3 : 對專案點選右鍵,選擇「屬性」。

Step 4 : 確認組態選擇「所有組態」。

在左側選單展開「組態屬性」,再展開「C/C++」選擇「一般」。

點選「其他Include目錄」選擇「編輯」。

 

Step 5 : 彈出「其他Include目錄」視窗後,新增Include folder。

 

Step 6 : 打開剛下載好的檔案,找freeglut/include後點選「選擇資料夾」。

Step 7 : 同上一步驟,找glew-{版本號}/include後點選「選擇資料夾」。

Step 8 : 新增完 freeglut 跟 glew 的 include 資料夾後,選擇「確認」。

Step 9 : 在左側選單展開「連結器」並選擇「輸入」。

點選「其他相依性」並選擇「編輯」。

Step 10 : 輸入「glew32.lib」與「freeglut.lib」後點選「確認」。

Step 11 : 在左側選單「連結器」中選擇「一般」。

點選「其他程式庫目錄」並選擇「編輯」。

Step 12 : 同 Step6 的方式新增 freeglut 與 glew 的 lib 資料夾後點選「確認」。

Step 13 : 點選「確認」

Step 14 : 到「電腦/C:/Windows」,並把「freeglut.dll」與「glew32.dll」丟進去後,就可以開始寫OpenGL啦。

Let's get started with a sample OpenGL program

Copy of OpenGL Introduction

By Erickson Juang

Copy of OpenGL Introduction

  • 838