1 Chapter 6 Blending, Antialiasing, Fog, and Polygon Offset Guihua Yang Jan 14, 2004.

Slides:



Advertisements
Similar presentations
Blending MAE152 Computer Graphics for Engineers and Scientists Fall 03.
Advertisements

© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
OpenGL Basics Donghui Han. Assignment Grading Visual Studio Glut Files of four types needed: – Source code:.cpp,.h – Executable file:.exe (build in release.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
Draw a Simple Object. Example 1/4 #include “ glut.h ” void display(); void reshape(GLsizei w, GLsizei h); void main(int argc, char** argv){ glutInit(&argc,
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
Hidden Surfaces and Shading CS BSP Tree T1T1 T2T2 E if (f 1 (E) < 0) then draw T 1 draw T 2 else draw T 2 draw T 1 f 1 (p) = 0 is the.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
Lighting & Material. Example 1/5 #include ” glut.h ” void display(); void reshape(int, int); void lighting(); int main(int argc, char** argv) { glutInit(&argc,
Color in OpenGL (Chapter 4) Presented by: Stacy C. Lovell.
Introduction to OpenGL Jian Huang This set of slides are extracted from the Interactive OpenGL Programming course given by Dave Shreine, Ed Angel and Vicki.
OpenGL A Brief Overview. What is OpenGL?  It is NOT a programming language.  It is a Graphics Rendering API consisting of a set of function with a well.
Reference1. [OpenGL course slides by Rasmus Stenholt]
JOGL in MS Windows GDI – Graphics Device Interface (Windows-specific) OpenGL Lib JOGL Commands GDI Processor Graphics Hardware JOGL Lib.
MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003.
Lecture 12 Blending, Anti-aliasing, Fog, Display Lists.
Lecture 14 Shading models 1.Shading Constant Shading (to be implemented) Gouraud Shading Phong Shading 2.Light and shading with OpenGL 1.
1. OpenGL/GLU/GLUT  OpenGL v4.0 (latest) is the “core” library that is platform independent  GLUT v3.7 is an auxiliary library that handles window creation,
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
DREAM PLAN IDEA IMPLEMENTATION Introduction to Computer Graphics Dr. Kourosh Kiani
Introduction to OpenGL (part 2)
OpenGL Color and Lighting 2003 Spring Keng Shih-Ling.
OpenGL Lighting Jian-Liang Lin 2002 Hidden-Surface Removal -1 Original Code: while (1) { get_viewing_point_from_mouse_position(); glClear(GL_COLOR_BUFFER_BIT);
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
NoufNaief.net 1 TA: Nouf Al-Harbi.
UniS CS297 Graphics with Java and OpenGL Blending.
OpenGL Special Effects Jian-Liang Lin 2002 Blending: Alpha Channel Alpha value can be specify by glColor* When blending is enabled, the alpha value is.
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
Chap 3 Viewing and Transformation
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
CS552: Computer Graphics Lecture 6: Viewing in 2D.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Chapter 4 -- Color1 Color Open GL Chapter 4. Chapter 4 -- Color2 n The goal of almost all OpenGL applications is to draw color pictures in a window on.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
31/1/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 2: Introduction.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
Introduction to Graphics Programming. Graphics API.
Introduction to Graphics Programming. Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Chapter 6. Blending, Antialiasing, Fog, and Polygon Offset Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
Advanced Graphics Algorithms Ying Zhu Georgia State University
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
I = a I + ( ) 1 – a I BLENDING, ANTIALIASING, AND FOG l l 1 l 2 Earth
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Lecture 16 and 17 Rasterization and Per-Fragment Operations
CSc4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Fog and Transparency.
Starting to draw dealing with Windows which libraries? clipping
גרפיקה ממוחשבת: מבוא ל-OpenGL
Lighting and Shading Lab 8:.
Introduction to OpenGL
Lecture 12: OpenGL Li Zhang Spring 2008
OpenGL program.
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Starting to draw dealing with Windows which libraries? clipping
Lighting and Shading Lab 8:.
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

1 Chapter 6 Blending, Antialiasing, Fog, and Polygon Offset Guihua Yang Jan 14, 2004

2 Blending: concepts and the example “alpha.c” Antialiasing: concepts and the example “aargb.c” Fog: concepts and the example “fog.c” Polygon: concepts and the example “polyoff.c” What we are going to learn in this lecture

3 Blending Blending: combines color values from a source and a destination. The final effect is that parts of your scene appear translucent. Source: color values of the incoming fragment Destination: color values of the corresponding currently stored pixel

4 Alpha(opacity): alpha--, transparent or translucent surfaces alpha++, opaque surfaces glColor*(R,G,B,A) Blending-cont

5 The Source and Destination Factors: blended RGBA values are given by (RsSr+RdDr, GsSg+GdDg, BsSb+BdDb, AsSa+AdDa) Each component of this quadruplet is eventually clamped to [0,1]. Blending-cont

6 Blending Example: alpha.c(a) ……………….. static int leftFirst = GL_TRUE; /* Initialize alpha blending function. */ static void init(void) {glEnable (GL_BLEND); //to have blending take effect; use glDisable() to disable blending. glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // void glBlendFunc(GLenum sfactor, GLenum dfactor); glShadeModel (GL_FLAT); //select flat or smooth shading glClearColor (0.0, 0.0, 0.0, 0.0); // specify clear values for the color buffers: black

7 alpha.c(b) static void drawLeftTriangle(void) { /* draw yellow triangle on LHS of screen */ glBegin (GL_TRIANGLES); glColor4f(1.0, 1.0, 0.0, 0.75); //to set the color to yellow, alpha to 0.75 glVertex3f(0.1, 0.9, 0.0); //3 points of the triangle ….. glVertex3f(0.1, 0.1, 0.0); glVertex3f(0.7, 0.5, 0.0); glEnd(); }

8 alpha.c(c) static void drawRightTriangle(void) { /* draw cyan triangle on RHS of screen */ glBegin (GL_TRIANGLES); glColor4f(0.0, 1.0, 1.0, 0.75); //to set the color to cyan, alpha to 0.75 glVertex3f(0.9, 0.9, 0.0); //3 points of the triangle ….. glVertex3f(0.3, 0.5, 0.0); glVertex3f(0.9, 0.1, 0.0); glEnd(); }

9 alpha.c(d) void keyboard(unsigned char key, int x, int y) { switch (key) { case `t': case `T': leftFirst = !leftFirst; glutPostRedisplay(); //marks the current or specified window as needing to be redisplayed. break; case 27: /* Escape key */ // 27 is ascii code for escape key. exit(0); break; default: break; } }

10 alpha.c(e) void display(void) { glClear(GL_COLOR_BUFFER_BIT); // clear buffers within the viewport. GL_COLOR_BUFFER_BIT : Indicates the buffers currently enabled for color writing. if (leftFirst) { drawLeftTriangle(); drawRightTriangle(); } else { drawRightTriangle(); drawLeftTriangle(); } glFlush(); //force execution of GL commands in finite time }

11 alpha.c(f) void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); //set the viewport, lower left corner(0,0), viewport’s width and height. glMatrixMode(GL_PROJECTION); //specify which matrix is the current matrix. GL_PROJECTION: Applies subsequent matrix operations to the projection matrix stack. glLoadIdentity(); // replace the current matrix with the identity matrix if (w <= h) gluOrtho2D (0.0, 1.0, 0.0, 1.0*(GLfloat)h/(GLfloat)w); else gluOrtho2D (0.0, 1.0*(GLfloat)w/(GLfloat)h, 0.0, 1.0); }

12 alpha.c(g) int main(int argc, char** argv) { // 5 routines perform tasks necessary to initialize a window. glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (200, 200); // plus glutInitWindwoPosition(…). glutCreateWindow (argv[0]); // until glutMainLoop() is called, the window is not yet displayed. init(); glutReshapeFunc (reshape); glutKeyboardFunc (keyboard); glutDisplayFunc (display); glutMainLoop(); return 0; }

13 Antialiasing aliasing causes images to have a jagged staircase look to their edges while anti-aliasing smoothes out these jagged edges.

14 Antialiasing-cont anti-aliasing is more than just making something slightly fuzzy so that you can't see the jagged edges: it's a way of fooling the eye into seeing straight lines and smooth curves where there are none.

15 Antialiasing in RGBA Mode 2 color modes: RGBA mode, Color index mode Blending is enabled The blending factors are: GL_SRC_ALPHA (source) and GL_ONE_MINUS_SRC_ALPHA (destination).

16 Antialiasing Example: aargb.c(a) static float rotAngle = 0.; /* Initialize antialiasing for RGBA mode, including alpha blending, hint, and line width. Print out implementation specific info on line width granularity and width.*/ void init(void) { GLfloat values[2]; glGetFloatv (GL_LINE_WIDTH_GRANULARITY, values); //returns one value, the width difference between adjacent supported widths for antialiased lines. printf ("GL_LINE_WIDTH_GRANULARITY value is %3.1f\n", values[0]); glGetFloatv (GL_LINE_WIDTH_RANGE, values); //returns two values: the smallest and largest supported widths for antialiased lines printf ("GL_LINE_WIDTH_RANGE values are %3.1f %3.1f\n", values[0], values[1]); glEnable (GL_LINE_SMOOTH); //indicates that antialiasing of lines is enabled glEnable (GL_BLEND); // enable blending glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE); glLineWidth (1.5); //specify the width of rasterized lines glClearColor(0.0, 0.0, 0.0, 0.0); }

17 aargb.c(b) /* Draw 2 diagonal lines to form an X */ void display(void) { glClear(GL_COLOR_BUFFER_BIT); glColor3f (0.0, 1.0, 0.0); //green color glPushMatrix(); //pushes the current matrix stack down by one, duplicating the current matrix. That is, after a glPushMatrix call, the matrix on the top of the stack is identical to the one below it. glRotatef(-rotAngle, 0.0, 0.0, 0.1); //multiply the current matrix by a rotation matrix glBegin (GL_LINES); glVertex2f (-0.5, 0.5); glVertex2f (0.5, -0.5); glEnd (); glPopMatrix(); //pop the current matrix stack glColor3f (0.0, 0.0, 1.0); //blue color glPushMatrix(); glRotatef(rotAngle, 0.0, 0.0, 0.1); glBegin (GL_LINES); glVertex2f (0.5, 0.5); glVertex2f (-0.5, -0.5); glEnd (); glPopMatrix(); glFlush(); }

18 aargb.c(c) void keyboard(unsigned char key, int x, int y) { switch (key) { case `r': case `R': rotAngle += 20.; if (rotAngle >= 360.) rotAngle = 0.; glutPostRedisplay(); break; case 27: /* Escape Key */ exit(0); break; default: break; }

19 Fog Fog: a general term that describes similar forms of atmospheric effects; it can be used to simulate haze, mist, smoke, or pollution. Make an entire image appear more natural by adding fog, which makes objects fade into the distance. When fog is enabled, objects that are farther from the viewpoint begin to fade into the fog color.

20 Fog Example

21 Fog equations Fog blends a fog color with an incoming fragment's color using a fog blending factor. This factor, f, is computed with one of these three equations and then clamped to the range [0,1]. The equation for GL_LINEAR fog is: The equation for GL_EXP fog is: The equation for GL_EXP2 fog is: Z: the distance in eye coordinates from the origin to the fragment being fogged

22 Fog example: fog.c(a) static GLint fogMode; static void init(void) { GLfloat position[] = { 0.5, 0.5, 3.0, 0.0 }; glEnable(GL_DEPTH_TEST); //do depth comparisons and update the depth buffer. glLightfv(GL_LIGHT0, GL_POSITION, position); glEnable(GL_LIGHTING); // use the current lighting parameters to compute the vertex color or index. glEnable(GL_LIGHT0); // include light i in the evaluation of the lighting equation. It is always the case that GL_LIGHTi = GL_LIGHT0 + i. { GLfloat mat[3] = {0.1745, , }; glMaterialfv (GL_FRONT, GL_AMBIENT, mat); //specify material parameters for the lighting model mat[0] = ; mat[1] = ; mat[2] = ; glMaterialfv (GL_FRONT, GL_DIFFUSE, mat); mat[0] = ; mat[1] = ; mat[2] = ; glMaterialfv (GL_FRONT, GL_SPECULAR, mat); glMaterialf (GL_FRONT, GL_SHININESS, 0.6*128.0); }

23 fog.c(b) glEnable(GL_FOG); { GLfloat fogColor[4] = {0.5, 0.5, 0.5, 1.0}; fogMode = GL_EXP; glFogi (GL_FOG_MODE, fogMode); //specify fog parameters. The equation for GL_EXP fog is f is blending factor glFogfv (GL_FOG_COLOR, fogColor); glFogf (GL_FOG_DENSITY, 0.35); //the fog density used in both exponential fog equations. Only nonnegative densities are accepted. The default fog density is 1.0. glHint (GL_FOG_HINT, GL_DONT_CARE); glFogf (GL_FOG_START, 1.0); //the near distance used in the linear fog equation. glFogf (GL_FOG_END, 5.0); //the far distance used in the linear fog equation. } glClearColor(0.5, 0.5, 0.5, 1.0); /* fog color */ }

24 fog.c( c) void keyboard(unsigned char key, int x, int y) { switch (key) { case `f': case `F': if (fogMode == GL_EXP) { fogMode = GL_EXP2; printf ("Fog mode is GL_EXP2\n"); } else if (fogMode == GL_EXP2) { fogMode = GL_LINEAR; printf ("Fog mode is GL_LINEAR\n"); } else if (fogMode == GL_LINEAR) { fogMode = GL_EXP; printf ("Fog mode is GL_EXP\n"); } glFogi (GL_FOG_MODE, fogMode); glutPostRedisplay(); break; ………………… }

25 Polygon Offset Raster(from merriam-webster dictionary):a scan pattern (as of the electron beam in a cathode-ray tube) in which an area is scanned from side to side in lines from top to bottom; also : a pattern of closely spaced rows of dots that form the image on a cathode-ray tube (as of a television or computer display) Rasterize: The process of converting a vector image into a bitmap image. This is the rasterize dialog box you will see when importing a vector-based image into Photoshop.

26 Rasterization: Rasterization is the process by which a primitive is converted to a two- dimensional image. Each point of this image contains such information as color and depth. on1.1/glspec1.1/node41.html Polygon Offset-cont.

27 Polygon Offset-cont. GL_LINE: Boundary edges of the polygon are drawn as line segments. GL_FILL: The interior of the polygon is filled. Polygon offset: adds an appropriate offset to force coincident z values apart to cleanly separate a polygon edge from its highlighting line.

28 Polygon offset example:polyoff.c Polygon Offset to Eliminate Visual Artifacts: polyoff.c glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0, 1.0); glCallList (list); glDisable(GL_POLYGON_OFFSET_FILL); glDisable(GL_LIGHTING); glDisable(GL_LIGHT0); glColor3f (1.0, 1.0, 1.0); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glCallList (list); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

29 References Red book, OpenGL Programming Guide (Addison-Wesley Publishing Company) Blue book, The OpenGL "Bluebook" HTML format /OpenGL_RM/sgi_html/bk02.htmlThe OpenGL "Bluebook" HTML format tml ode41.html