Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics Practical Lesson 9

Similar presentations


Presentation on theme: "Computer Graphics Practical Lesson 9"— Presentation transcript:

1 Computer Graphics Practical Lesson 9
Stencil buffer and frame buffer

2 Stencil buffer Stencil buffer is similar to the depth buffer, and stored on the same memory ( 24 bits for depth, and 8 for stencil). Allow prevention of drawing of pixels of objects. With the depth buffer, it allows more complex rendering such as shadowing.

3 Setup stencil buffer Clear the buffer : glClearStencil(0);
Like anything in OpenGL, we need to enable stencil glEnable(GL_STENCIL_TEST); Setup the stencil function, which defines how to perform test between existing value(stencil) and new value on the buffer(ref) glStencilFunc(func, ref=1,mask=1); funcion that used for comparison. ref is value to be compared with, and mask is the mask that used to compare.

4 Setup stencil buffer(cont’)
glStencilOp(fail,zfail,zpass) – defines the what to do with stencil buffer on each case: fail – when stencil test fails zfail – when stencil fails but stencil pass. zpass – when both tests fails.

5 The reflected airplane
A reflected airplane is drawn in the stencil example. The reflected plane is drawn first, before the floor and the regular airplane. It Is drawn using clipping – from the button by frustom clipping and on the top using glClipping

6 The reflected airplane(cont’)
In the stencil example the reflected airplane appears only until the height of the floor. It is done using plain clipping. In openGL: double clipping_plain[]={X,Y,Z,D} – a plain represented by vector X,Y,Z and offset D glEnable(GL_CLIP_PLANE0); glClipPlane(GL_CLIP_PLANE0,clipping_plain); In OpenGL there are up to 6 plains. The plains are added to the plains of frustum(see practical lesson3).

7 The Frame buffer To read from frame buffer: glReadPixels(x,y,width,height,format,type,buffer); Format = GL_RGBA for example Type of values on source array = GL_UNSIGNED_INT

8 Frame buffer(cont’) glRasterPos2i(int,int) – define position for writing glDrawPixels(width,height,GL_RGBA, GL_UNSIGNED_INT,buffer) – writing buffer.


Download ppt "Computer Graphics Practical Lesson 9"

Similar presentations


Ads by Google