DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Computer Graphics Dr. Kourosh Kiani

Slides:



Advertisements
Similar presentations
#include int line_width = 1; void Display( void ) { glEnable( GL_LINE_STIPPLE ); glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT);
Advertisements

Blending MAE152 Computer Graphics for Engineers and Scientists Fall 03.
Compositing and Blending - Chapter 8 modified by Ray Wisman Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Part 3: Three Dimensions.
© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
Computer Graphics (Fall 2008) COMS 4160, Lecture 9: OpenGL 1
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,
1 CSC461 Lecture 7: 3D Programming in OpenGL Objectives: Develop 2D and 3D examples -- Sierpinski gasket: a fractal Develop 2D and 3D examples -- Sierpinski.
Computer Graphics (Fall 2005) COMS 4160, Lecture 10: OpenGL 1
Programming with OpenGL and GLUT
Reference1. [OpenGL course slides by Rasmus Stenholt]
CS380 LAB I OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003.
Lecture 3 OpenGL.
Computer Graphics CS 385 January 31, Fractals Some definitions Object which is self-similar at all scales. Regardless of scale the same level of.
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
1 Chapter 6 Blending, Antialiasing, Fog, and Polygon Offset Guihua Yang Jan 14, 2004.
CD2012 Principles of Interactive Graphics Lecture 01 Introduction Abir Hussain (Rome: 6.33,Tel , Web:
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
Interactive Computer Graphics CS 418 MP1: Dancing I TA: Zhicheng Yan Sushma S Kini Mary Pietrowicz Slides Taken from: “An Interactive Introduction to OpenGL.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Introduction to OpenGL (part 2)
1 Programming with OpenGL Part 3: Three Dimensions Yuanfeng Zhou Shandong University.
Computer Graphics I, Fall 2010 Programming with OpenGL Part 3: Three Dimensions.
Introduction to OpenGL and GLUT. What’s OpenGL? An Application Programming Interface (API) A low-level graphics programming API – Contains over 250 functions.
OpenGL Architecture Display List Polynomial Evaluator Per Vertex Operations & Primitive Assembly Rasterization Per Fragment Operations Frame Buffer Texture.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Intro to OpenGL (Version 2) Geb Thomas. Setting Up GLUT You will need GLUT for opening windows We can use the version made by Nate Robins: –
CS559: Computer Graphics Lecture 12: Antialiasing & Visibility Li Zhang Spring 2008.
Color spaces. Draw Buffers Color models. Mathmatical Protocols for defining colors with numbers  RGB Red, Green, Blue  HSV Hue, Saturation, Value(Brightness)‏
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 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 3: Three Dimensions Ed Angel Professor of Computer Science,
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
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.
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
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.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 2: Complete Programs
Advanced Graphics Algorithms Ying Zhu Georgia State University
Programming with OpenGL Part 3: Three Dimensions
Rendering Geometric Primitives Reading: HB4, HB8-1 to HB8-6, HK9.7, 11
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
Lecture 16 and 17 Rasterization and Per-Fragment Operations
CSc4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Fog and Transparency.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Programming with OpenGL Part 3: Three Dimensions
Introduction to OpenGL
OpenGL program.
Programming with OpenGL Part 3: Three Dimensions
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Presentation transcript:

DREAM PLAN IDEA IMPLEMENTATION 1

2

3 Introduction to Computer Graphics Dr. Kourosh Kiani Web: Present to: Amirkabir University of Technology (Tehran Polytechnic) & Semnan University

Lecture 13 Amirkabir & Semnan University Computer & Electrical Faculty 4 OpenGL Blending

What are some types of transparent surfaces? Windows Plastic Stained Glass Water

Alpha: the 4 th Color Component Measure of Opacity –simulate translucent objects glass, water, etc. –composite images –antialiasing

Blend

Source and Destination Objects are blended together in a scene in the order in which they are drawn. An object being drawn it is the "source“. Any object, over which a source object is drawn is a “destination”. Blending functions, along with alpha values control how source and destination colors are mixed together.

9 Source and Destination Factors Blending colors – source color : (R s, G s, B s, A s ) – destination color : (R d, G d, B d, A d ) – source factor : (S r, S g, S b, S a ) – destination factor: (D r, D g, D b, D a ) – blended RGBA = (RsSr+RdDr, GsSg+GdDg, BsSb+BdDb, AsSa+AdDa)

10 Blending in OGL If a fragment makes it to FB, the pixel is read out and blended with the fragment’s color and then written back to FB The contributions of fragment and FB pixel is specified: glBlendFunc( src, dst )

11 We would like to combine the two colors Fragment or source - incoming color destination - existing color How should we combine them? We use the alpha channel to describe the combination of the source and destination. Color Final = A*Color Source + B*Color Destination Most APIs let you specify A and B What does A and B mean qualitatively?

12 Order Matters with Alpha!

13 Blending: Alpha Channel Alpha value can be specify by glColor*(R,G,B,A) When blending is enabled, the alpha value is often used to combine the color value of the fragment being processed with that of the pixel already stored in the framebuffer Note: – Alpha values aren't specified in color-index mode, so blending operations aren't performed in color-index mode.

14 Opacity and Blending Alpha channel to allow different levels of opacity amongst objects:  = 1  Perfectly opaque  = 0  Perfectly transparent 0  Different levels of translucency Blending is mixing colors of two sets of pixels: source and destination – source and destination each have relative weights or blending factors to control the operation

15 Once blending is enabled you should be able to create this scene by placing a transparent quad on an opaque one. Alpha 1.0Alpha 0.5 Opacity and Blending

16 Blending: The Source and Destination Factors let the source and destination blending factors be (Sr, Sg, Sb, Sa) and (Dr, Dg, Db, Da), respectively, and the RGBA values of the source and destination be indicated with a subscript of s or d. Then the final, 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]. – You can use glBlendFunc() to specify these two factors – glEnable( GL_BLEND );

17 Blending Example Additive  C = Cs + Cd = Cs*1 + Cd*1: glBlendFunc(GL_ONE, GL_ONE); Multiplicative  C = Cs * Cd = Cs*Cd + Cd*0: glBlendFunc(GL_DST_COLOR, GL_ZERO); Transparency  C = Cs*  + Cd*(1-  ) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

18 Using Alpha: glBlendFunc()

19 Using Alpha: glBlendFunc()

20 Blending Example: alpha.c #include static int leftFirst = GL_TRUE; // Initialize alpha blending function. static void init(void) { glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glShadeModel (GL_FLAT); glClearColor (0.0, 0.0, 0.0, 0.0); }

21 static void drawLeftTriangle(void) { // draw yellow triangle on LHS of screen glBegin (GL_TRIANGLES); glColor4f(1.0, 1.0, 0.0, 0.75); glVertex3f(0.1, 0.9, 0.0); glVertex3f(0.1, 0.1, 0.0); glVertex3f(0.7, 0.5, 0.0); glEnd();} Blending Example: alpha.c

22 Blending Example: alpha.c static void drawRightTriangle(void) { // draw cyan triangle on RHS of screen glBegin (GL_TRIANGLES); glColor4f(0.0, 1.0, 1.0, 0.75); glVertex3f(0.9, 0.9, 0.0); glVertex3f(0.3, 0.5, 0.0); glVertex3f(0.9, 0.1, 0.0); glEnd();}

23 Blending Example: alpha.c void keyboard(unsigned char key, int x, int y) { switch (key) { case `t': case `T': leftFirst = !leftFirst; glutPostRedisplay(); break; case 27: /* Escape key */ // 27 is ascii code for escape key. exit(0); break; default: break; } }

24 void display(void) { glClear(GL_COLOR_BUFFER_BIT); if (leftFirst) { drawLeftTriangle(); drawRightTriangle(); } else { drawRightTriangle(); drawLeftTriangle(); } glFlush(); } Blending Example: alpha.c

25 Blending Example: alpha.c void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h);. glMatrixMode(GL_PROJECTION); glLoadIdentity(); 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); }

26 Blending Example: alpha.c int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (200, 200); glutCreateWindow (argv[0]); init(); glutReshapeFunc (reshape); glutKeyboardFunc (keyboard); glutDisplayFunc (display); glutMainLoop(); return 0; }

27

28

29 Questions? Discussion? Suggestions ?

30