1. Trang chủ
  2. » Giáo Dục - Đào Tạo

OpenGL overview (đồ họa máy TÍNH SLIDE)

40 22 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 40
Dung lượng 603,65 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

OpenGL and GLUT Overview• What is OpenGL & what can it do for me?... What Is OpenGL?– a cross-platform API – high-quality color images composed of geometric and image primitives • widely

Trang 1

OpenGL Overview

Trang 2

OpenGL and GLUT Overview

• What is OpenGL & what can it do for me?

Trang 3

What Is OpenGL?

– a cross-platform API

– high-quality color images composed of geometric and image primitives

• widely used in CAD, virtual reality, scientific visualization, information visualization and video game development

Trang 4

OpenGL Architecture

Trang 5

OpenGL as a Renderer

– points, lines and polygons

– images and bitmaps

– separate pipeline for images and geometry

• linked through texture mapping

– colors, materials, light sources, etc.

Trang 6

Related APIs

– glue between OpenGL and windowing systems

– part of OpenGL

– NURBS, tessellators, quadric shapes, etc.

– portable windowing API

– keyboard and mouse input

– Geometric primitives: cubes, spheres, and teapot

– not officially part of OpenGL

Trang 7

OpenGL and Related APIs

X, Win32, Mac O/S

software and/or hardware

application program

OpenGL Motif widget or similar

Trang 8

What is JOGL?

that allow OpenGL to be used in Java

Trang 9

Setting Up JOGL 2.0x

• Download the latest "stable" release from JogAMP

http://jogamp.org/deployment/jogamp-current/archive Select "jogamp-all-platforms.7z"

– Copy the necessary jar-file, native libraries of your operating platform, and source-files into the appropriate sub-directories

– for Win32, copy

• "jar\gluegen-rt.jar", "jar\jogl.all.jar" into "jar";

• all files in "lib\windows-i586" into "lib";

• "gluegen-java-src.zip", "jogl-java-src.zip" into "src"

• Unzip the javadocs downloaded into "javadoc".

Trang 12

Sample Template Program

pu blic class JO G L2Tem plate extends G LJPanel

im plem ents G LEventListener {

// Setup O penG L G raphics Renderer

private G LU glu ; // for the G L U tility

private G LU T glut ; // O penG L U tility Toolkit

/** Constructor to setup the G U I for this Com ponent */

pu blic JO G L2Tem plate() {

this.addG LEventListener( this );

}

Trang 13

Sample Program: init event

/**

* Called back im m ediately after the O penG L context is initialized

* Can be used to perform one - tim e initialization Run only once.

*/

pu blic void init(G LAutoD raw able draw able) {

G L2 gl = draw able.getG L().getG L2(); // get the O penG L graphics context glu = new G LU (); // get G L U tilities

gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background color

gl.glClearD epth(1.0f); // set clear depth value to farthest

gl.glEnable(G L_D EPTH _TEST); // enables depth testing

gl.glD epthFunc(G L_LEQ U AL); // the type of depth test to do

// best perspective correction

gl.glH int(G L_PERSPECTIVE_CO RRECTIO N _H IN T , G L_N ICEST );

// blends colors nicely, and sm oothes out lighting

gl.glShadeM odel(G L_SM O O TH );

// Your O penG L initialization code here

-}

Trang 14

Sample Program: reshape event

/* Call - back handler for w indow re - size event Also called w hen the

draw able is fi rst set to visible */

pu blic void reshape(G LAutoD raw able draw able,

int x, int y, int w idth, int height) {

G L2 gl = draw able.getG L().getG L2();

if (height = = 0) height = 1; // prevent divide by zero

f l oat aspect = (f l oat) w idth / height;

// Set the view port (display area) to cover the entire w indow

gl.glView port(0, 0, w idth, height);

// Setup perspective projection,

// w ith aspect ratio m atches view port

gl.glM atrixM ode(G L_PRO JECTIO N ); // choose projection m atrix

gl.glLoadIdentity(); // reset projection m atrix

glu gluPerspective(45.0, aspect, 0.1, 100.0); // fovy, aspect, zN ear, zFar // Enable the m odel-view transform

gl.glM atrixM ode(G L_M O D ELVIEW );

gl.glLoadIdentity(); // reset

}

Trang 15

Sample Program: display event

/* Called back by the anim ator to perform rendering */

pu blic void display(G LAutoD raw able draw able) {

// get the O penG L 2 graphics context

G L2 gl = draw able.getG L().getG L2();

// clear color and depth buff ers

gl.glClear(G L_CO LO R_BU FFER_BIT | G L_D EPTH _BU FFER_BIT );

gl.glLoadIdentity(); // reset the m odel-view m atrix

// Your O penG L rendering code here

// (Render a w hite triangle for testing)

gl.glTranslatef(0.0f, 0.0f, -6.0f); // translate into the screen

gl.glBegin(G L_TRIAN G LES ); // draw using triangles

Trang 16

Sample Program: dispose event

**

* Called back before the O penG L context is destroyed

* Release resource such as buff ers.

*/

p ublic void dispose(G LAutoD raw able draw able) {

}

Trang 17

pu blic static void m ain(String[] args) {

Sw ingU tilities.invokeLater( new Runnable() {

pu blic void run() {

// Create the O penG L rendering canvas

G LJPanel panel = new JO G L2Tem plate();

panel.setPreferredSize( new D im ension(640 , 480 ));

// Create a anim ator

FPSAnim ator anim ator = new FPSAnim ator(panel, 60 , true );

JFram e fram e = new JFram e();

fram e.getContentPane().add(panel);

fram e.addW indow Listener( new W indow Adapter() {

p u blic void w indow Closing(W indow Event e) {

// stop the anim ator stops before program exits.

new Thread() {

pu blic void run() {

if (anim ator.isStarted()) anim ator.stop();

fram e.setTitle( "JO G L2 Tem plate");

fram e.pack(); fram e.setVisible( true );

anim ator.start(); // start the anim ation loop

}

});

Trang 18

Elementary Rendering

Trang 19

Elementary Rendering

Trang 20

OpenGL Geometric Primitives

• All geometric primitives are specified by vertices

GL_QUAD_STRIP GL_POLYGON

GL_TRIANGLE_STRIP GL_TRIANGLE_FAN

GL_POINTS

GL_LINES

GL_LINE_LOOP GL_LINE_STRIP

GL_TRIANGLES

GL_QUADS

Trang 22

OpenGL Command Formats

Trang 23

Enumerated Types

Trang 24

Specifying Geometric Primitives

glBegin(primType);

glEnd();

primType determines how vertices are combined

void drawRhombus(GL2 gl, float[] color) { gl.glColor3fv(color);

Trang 25

OpenGL Color Models

color index mode

Display 1

24 25 26

ww

ww

RGBA mode

Trang 26

Shapes Tutorial

Trang 27

Controlling Rendering Appearance

Trang 28

OpenGL’s State Machine

– rendering styles

– shading

– lighting

– texture mapping

Trang 29

Manipulating OpenGL State

update OpenGL state

Trang 30

Controlling current state

– cap is a feature like:

GL_LIGHTING, GL_TEXTURE_2D, GL_CULL_FACE, GL_BLEND,

Trang 31

OpenGL State Variables

• You can query the State Machine to determine the state of any variable

• Any feature you enable or disable with glEnable / glDisable as well as numeric settings set with glSet can be queried with the many variations of glGet

Trang 32

Animation and Depth Buffering

Trang 33

Depth Buffering and Animation

Trang 34

Animation using Double Buffering

1

2 4 8 16

1

2 4 8 16

Front Buffer

Back Buffer

Display

Trang 35

Animation and Double Buffering

– Default for JOGL

Trang 36

Depth Buffering

and Hidden Surface Removal

1

2 4 8 16

1

2 4 8 16

Color Buffer

Depth Buffer

Display

Trang 37

Hidden Surface Removal

Trang 38

Depth Buffering Using OpenGL

Trang 39

An Updated Program Template

public void display(G LAutoD raw able draw able) {

G L2 gl = draw able.getG L().getG L2();

gl.glClear(G L_CO LO R_BU FFER_BIT | G L_D EPTH _BU FFER_BIT );

gl.glLoadIdentity();

gl.glTranslatef(0.0f, 0.0f, -5.0f);

}

Trang 40

An Updated Program Template (cont)

Ngày đăng: 29/03/2021, 08:19

TỪ KHÓA LIÊN QUAN

w