opengl programming guide (red book) state management and drawing geometric objects 고려대학교...

22
OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고고고고고 고고고고 고고고

Upload: denis-mccarthy

Post on 23-Dec-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

OpenGL Programming Guide

(Red Book)

State Management and Drawing Geometric Objects

고려대학교

그래픽스 연구실

강 신 진

Page 2: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Goal

Clear the window to an arbitrary color Force any pending drawing to complete Draw with any geometric primitive Turn states on and off any query states

variables Control the display of geometric primitives Specify normal vectors at appropriate

points

Page 3: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Contents

A Drawing Survival Kit Describing Points, Lines, and

Polygons Basic State Management Display Points, Lines, and Polygons Normal Vectors

Page 4: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

A Drawing Survival Kit

Page 5: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Clearing Window

Buffer Name

Color buffer GL_COLOR_BUFFER_BIT

Depth buffer GL_DEPTH_BUFFER_BIT

Accumulation buffer GL_ACCUM_BUFFER_BIT

Stencil buffer GL_STENCIL_BUFFER_BIT

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);glClear(GL_CLEAR_BUFFER_BIT);

Lesson27\Lesson 27.exe

Page 6: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Specifying a Color

Description of the shape of an object Independent of the description of its color

Order of Programming Setting the color or coloring scheme Drawing the objects

To set a color

glColor3f(1.0f, 1.0f, 1.0f); //black

glColor3f(0.0f, 1.0f, 1.0f); //cyan

Page 7: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Forcing Completion of Drawing

Void glFlush(void);

Forces previously issued OpenGL commands to begin execution, thus guaranteeing that they complete in finite time

Void glFinish(void);

Forces all previously issued OpenGL commands to complete. The command doesn’t return until all effects from previous commands are fully realized.

Page 8: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Coordinate System Survival Kit

glutReshapeFunc(reshape)

Void reshape(int w, int h)

{

glViewport(0, 0, (GLsizei) w, (GLsizei) h);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(45.0f,(GLfloat)w/(GLfloat)h,0.1f,100.0f);

}

Page 9: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Describing Points, Lines, and Polygons

점선폴리곤\lesson1.exe

Page 10: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

What are Points, Lines and Polygons?

Differences between mathematician and OpenGL1. Difference from the limitations of computer-based

calculations.

Floating-point calculations are of finite precision, and they have round-off errors

2. Difference from the limitations of a graphics display

The smallest displayable unit is a pixel, and pixel is not infinitely small

Page 11: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Specifying Vertices

glVertex2s(2, 3);glVertex3d(0.0, 0.0, 3.141592653898);glVertex4f(2.3, 1.0, -2.2, 2.0);

glDouble dvect[3] = {5.0, 9.0, 1992.0};

glVertex3dv(dvect);

glVertex() type

glVertex*() type

Between glBegin() and glEnd()

Page 12: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

OpenGL Geometric Drawing Primitives

Void glBegin(GLenum mode);

glBegin \모드Debug\lesson1.exe

Page 13: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Restriction on Using glBegin() and glEnd()

glVertex*() Set vertex coordinates

glColor*() Set current color

glIndex*() Set current color index

glNormal*() Set normal vector coordinates

glTexCoord*() Set texture coordinates

glMultiTexCoord*ARB()

Set texture coordinates for multitexturing

glEdgeFlag*() Control drawing of edges

glMaterial*() Set material properties

glArrayElement() Extract vertex array data

glEvalCoord*(), ~Point*()

Generate coordinates

glCallList(), glCallLists()

Execute display list(s)

Page 14: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Basic State Management

Page 15: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Basic State Management

Method

Void glEnable(GLenum cap);Void glDisable(GLenum cap);

Checking & Debugging method

GLboolean glIsEnabled(GLenum capability);

Capability Example

GL_BLEND, GL_DEPTH_TEST, GL_LINE_STIPPLE, GL_LIGHTING etc.

Page 16: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Display Points, Lines, and Polygons

Page 17: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Point Detail

Controlling size of a rendered point

Void glPointSize(GLfloat size);

Whether antialiasing is enabled or disabled

Disabled widths are rounded to integer widths

Enabled noninteger widths aren’t rounded, variation of intensity

Antilaliasing\Debug\Antilaliasing.exe

Page 18: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Line Details

Controlling width of a rendered line

Void glLineWidth(GLfloat size);

Stippled Lines

glLineStipple(1, 0x3F07);glEnable(GL_LINE_STIPPLE);

Page 19: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Polygon Details - 1

Polygons as Points, Outlines or Solids

Void glPolygonMode(GLenum face, GLenum mode);

glPolygonMode(GL_FRONT, GL_FILL);glPolygonMode(GL_BACK, GL_LINE);glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);

Reserving and Culling Polygon Faces

Void glFrontFace(GLenum mode); //GL_CW, GL_CCW

glBegin \모드 Debug\lesson1.exe

Page 20: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Polygon Details - 2

Void glCullFace(GLenum mode);

mode GL_FRONT, GL_BACK, GL_FRONT_AND_BACK

Stippling Polygons

glEnable(GL_POLYGON_STIPPLE);Void glPolygonStipple(const GLubyte *mask);

Boundary Edges

Void glEdgeFlags(GLboolean flag);Void glEdgeFlagv(const GLboolean *flag);

Page 21: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Normal Vectors

Page 22: OpenGL Programming Guide (Red Book) State Management and Drawing Geometric Objects 고려대학교 그래픽스 연구실 강 신 진

Normal Vectors

Normal Vector

A normal vector is a vector that points in a direction that’s perpendicular to surface

OpenGL Method

Void glNormal3{bsidf}(TYPE nx, TYPE ny, TYPE nz);Void glNormal3{bsidf}v(const TYPE *v);

Normalization

glEnable(GL_NORMALIZE);