23
CGGM Lab. Tan-Chi Ho 2002 1 Introduction to OpenGL

Introduction to OpenGL

  • Upload
    loyal

  • View
    57

  • Download
    0

Embed Size (px)

DESCRIPTION

Introduction to OpenGL. Graphics API. A software interface for graphics hardware. Provide the low-level functions to access graphics hardware directly. OpenGL / Direct3D. API Hierarchy. Application. GDI. OpenGL. Hardware Driver. …. Display Device. What is OpenGL 1/2. - PowerPoint PPT Presentation

Citation preview

Page 1: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 1

Introduction to OpenGL

Page 2: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 2

Graphics API A software interface for graphics

hardware. Provide the low-level functions to

access graphics hardware directly. OpenGL / Direct3D

Page 3: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 3

API Hierarchy

Application

GDI

Display Device

OpenGL

Hardware Driver

Page 4: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 4

What is OpenGL1/2

Industry standard. Hardware independent. OS independent.

Page 5: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 5

What is OpenGL2/2

No commands for performing windowing tasks or obtaining user input are included.

No high-level commands for describing models of 3D objects are provided.

Page 6: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 6

What OpenGL provides Draw with points, lines, and polygons. Matrix(View) Transformation Hidden Surface Removal (Z-Buffer) Light effects Gouraud Shading Texture mapping Pixels operation

Page 7: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 7

The Buffers A buffer is a memory area in the

graphics hardware for some special purposes.

An OpenGL system can manipulate the four buffers: Color buffers Depth buffer (Z-Buffer) Stencil buffer Accumulation buffer

Page 8: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 8

OpenGL Rendering Pipeline1/2

OpenGL API Calls

OpenGL Command

Buffer

Transformation and Lighting

RasterizationFrame Buffer

Page 9: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 9

OpenGL Rendering Pipeline2/2

Vertex Data

Pixel Data

Display List

Evaluators

Per-Vertex Operations and Primitive Assembly

Pixel Operations

Rasterization

Texture Assembly

Per-Fragment Operations

Frame Buffer

Page 10: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 10

OpenGL Libraries OpenGL Library

The basic library to access the graphics hardware.

GLU Provide some useful utilities based on the

OpenGL library. GLX / WGL / AGL

OS dependent libraries to bind the OpenGL library with specific window system.

GLX for X-window, WGL for win32, AGL for Apple.

Page 11: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 11

OpenGL Utility Toolkit (GLUT) 1/3

A window system-independent toolkit to hide the complexities of differing window system APIs.

Use the prefix of glut. (ex: glutDisplayFunc())

Provide following operations: Initializing and creating window Handling window and input events Drawing basic three-dimensional objects Running the program

Page 12: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 12

OpenGL Utility Toolkit (GLUT) 2/3

Where can I get GLUT? Win32:

http://www.xmission.com/~nate/glut.html Linux:

http://www.mesa3d.org/

Page 13: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 13

OpenGL Utility Toolkit (GLUT) 3/3

On Microsoft Visual C++ 6: Put glut.h into <MSVC>/include/GL/ Put glut.lib into <MSVC>/lib/ Put glut32.dll into <window>/System32/

On Microsoft Visual C++ .NET: Put glut.h into <MSVC>/platformSDK/include/G

L/ Put glut.lib into <MSVC>/platformSDK/lib/ Put glut32.dll into <window>/System32/

Page 14: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 14

How to Compile1/4

On Microsoft Visual C++ 6: Create a new Project with Win32

Console Application Open Project Settings dialog and add

opengl32.lib glu32.lib glut32.lib into Link/Objects/library modules.

Writing your OpenGL code. Compile it.

Page 15: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 15

How to Compile2/4

On Microsoft Visual C++ .NET: 建立 Win32 專案 在應用程式設定,選擇主控台應用程式 開啟專案屬性,在連結器 / 輸入 / 其他相依

性中輸入 opengl32.lib glu32.lib glut32.lib 。

Writing your OpenGL code. Compile it.

Page 16: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 16

How to Compile3/4

Page 17: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 17

How to Compile4/4

On UNIX: Needed libraries:

libGL.so, libGLU.so, libglut.a, libX11.a, libX11.so…

Compile command: gcc [OpenGL code files] –o [output file] –lglut

–lGLU –lGL –lX11 –lm

Page 18: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 18

The Simplest Program1/3

#include <GL/glut.h>void GL_display(){

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0f, 1.0f, 1.0f);glutSolidCube(1.0);glFlush();

}void GL_reshape(GLsizei w, GLsizei h){

glViewport(0, 0, w, h);glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(-2.0f, 2.0f, -2.0f, 2.0f, -2.0f, 2.0f);glMatrixMode(GL_MODELVIEW);glLoadIdentity();

}

Page 19: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 19

The Simplest Program2/3

void main(void){

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);glutCreateWindow("Sample");glutDisplayFunc(GL_display);glutReshapeFunc(GL_reshape);glutMainLoop();

}

Page 20: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 20

The Simplest Program3/3

Page 21: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 21

Reference1/2

Official site of OpenGL http://www.opengl.org

Useful Sites NeHe’s OpenGL Tutorials The Developer’s Gallery

Page 22: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 22

Reference2/2

Further Reading OpenGL Programming Guide (Red Book) OpenGL Reference Manual (Blue Book) OpenGL Super Bible ( 中文版 ?)

Page 23: Introduction to OpenGL

CGGM Lab. Tan-Chi Ho 2002 23

Any Question?

?