CH8 Frame Buffer Object 1. Introduction Name OpenGL :Frame Buffer Object DirectX:Render Target Usage Render to Texture 2.

Slides:



Advertisements
Similar presentations
OpenGL Texture Mapping
Advertisements

CH6 Texture. Before coding … 1/2 Prepare all texture images you need. BMP file is a good choice If you want to use TIFF file, maybe try this.
OpenGL Basics Donghui Han. Assignment Grading Visual Studio Glut Files of four types needed: – Source code:.cpp,.h – Executable file:.exe (build in release.
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,
OpenGL and Projections
CH7 Buffers and Blending. Blending Example 1/6 #include #include "glut.h" GLfloat alpha = 0.0; GLfloat pos[4] = {0, 10, 10, 0}; GLfloat dif_l[4] = {1.0,
Sierpinski Gasket Program
1 Lecture 12 Texture Mapping uploading of the texture to the video memory the application of the texture onto geometry.
Computer Graphics (Fall 2004) COMS 4160, Lecture 11: OpenGL 2
CS 4731: Computer Graphics Lecture 17: Texturing Emmanuel Agu.
Texture Mapping A way of adding surface details Two ways can achieve the goal:  Surface detail polygons: create extra polygons to model object details.
Texture Mapping. To add surface details… World of Warcraft, Blizzard Inc. More polygons (slow and hard to handle small details) Less polygons but with.
Computer Graphics Texture Mapping Eriq Muhammad Adams
2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e.
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny TA. Abhishek Gattani TA. Stephen
Write a Simple Program with OpenGL & GLUT. Books OpenGL Programming Guide (Red-book) OpenGL Reference Manual (Blue-book) OpenGL Super Bible
CS380 LAB IV OpenGL Jonghyeob Lee Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Lecture 27: Texture Mapping Li Zhang Spring 2008
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
Texture Mapping in OpenGL. Texture Mapping Imaging we are “pasting” a picture onto a model  Which part of the picture will be pasted onto which part.
Texture Mapping Drawing Pictures on Polygons. Texture Mapping.
Modeling with OpenGL Practice with OpenGL transformations.
TEXTURES & OTHER GOODIES Computer Graphics. glTexCoord2f(...); + =
111/17/ :24 UML Solution Involves Selection of Discrete Representation Values.
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.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Shader. Original Rendering Pipeline Vertex Shader Vertex transformation Normal transformation & normalization Texture coordinate generation & transformation.
OpenGL Programming Guide : Texture Mapping Yoo jin wook Korea Univ. Computer Graphics Lab.
CH6 Texture. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending Per Fragment.
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.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
CH7 Buffers and Blending. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Introduction to OpenGL & HW1 Announcement 劉軒銘, 網媒所 碩二 ICG 2012 Fall.
Color spaces. Draw Buffers Color models. Mathmatical Protocols for defining colors with numbers  RGB Red, Green, Blue  HSV Hue, Saturation, Value(Brightness)‏
Doç. Dr. Cemil Öz SAÜ Bilgisayar Mühendisliği Dr. Cemil Öz.
Chap 3 Viewing and Transformation
CH6 Texture.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Chap 2 Write a Simple OpenGL Program. Preparing 1/2 environment : Microsoft Visual C 、 Microsoft Visual C++.Net Also need : GLUT
CH6 Texture. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending Per Fragment.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 3: Three Dimensions Ed Angel Professor of Computer Science,
CH6 Texture. Before coding … 1/2 Prepare all texture images you need. BMP file is a good choice If you want to load other format, you can try the FreeImage.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
Wilf Comp Ambient Occlusion + Order Independent Transparency POST CONCLUSIONS.
Introduction to Graphics Programming. Graphics API.
CS425 © 2003 Ray S. Babcock Pixels and Bitmaps ● OpenGL allows us to work directly with bits and groups of bits, or pixels, which flow down a parallel.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Texture Mapping CEng 477 Introduction to Computer Graphics.
CSC Graphics Programming
Madhulika (18010), Assistant Professor, LPU.
Texture Mapping 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
OpenGL ARB Superbuffers
Introduction to Computer Graphics with WebGL
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
texturing a parametric surface
Advanced Graphics Algorithms Ying Zhu Georgia State University
Advanced Graphics Algorithms Ying Zhu Georgia State University
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Assignment 3b Q&A.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Lighting and Shading Lab 8:.
Introduction to OpenGL
OpenGL program.
Lighting and Shading Lab 8:.
Programming Textures Lecture 15 Fri, Sep 28, 2007.
Presentation transcript:

CH8 Frame Buffer Object 1

Introduction Name OpenGL :Frame Buffer Object DirectX:Render Target Usage Render to Texture 2

Replace the Screen Pixels Screen 0 User FBO 1 User FBO n …. (Default) Bind Color Color Attachment 0 Depth Attachment Depth Color Attachment 0 Color Attachment 1 gl_FragData[0] gl_FragData[1] 3

Functions Create and Destroy FBO void glGenFramebuffersEXT(GLsizei n, GLuint* ids) void glDeleteFramebuffersEXT(GLsizei n, const GLuint* ids) Bind FBO void glBindFramebufferEXT(GLenum target, GLuint id) 4

Attachment Texture Render Buffer You cant send it to shader It supports some format that texture doesn’t. 5

Render Buffer Create void glGenRenderbuffersEXT(GLsizei n, GLuint* ids); Destroy void glDeleteRenderbuffersEXT(GLsizei n, const Gluint* ids); Bind void glBindRenderbufferEXT(GLenum target, GLuint id); Storage void glRenderbufferStorageEXT(GLenum target, GLenum internalFormat, GLsizei width, GLsizei height) 6

Render Buffer Parameters Target GL_RENDERBUFFER_EXT Internal Format GL_RGB, GL_RGBA GL_DEPTH_COMPONENT16, 24, 32, 32F GL_DEPTH24_STENCIL8, GL_DEPTH32F_STENCIL8. GL_STENCIL_INDEX, GL_STENCIL_INDEX8_EXT (Does not recommend!) 7

Attachment Points 8

Attach Texture glFramebufferTexture2DEXT(GLenum target, GLenum attachmentPoint, GLenum textureTarget, GLuint textureId, GLint level) Target GL_FRAMEBUFFER_EXT Attachment Point GL_COLOR_ATTACHMENT0_EXT ~ GL_COLOR_ATTACHMENTn_EXT GL_DEPTH_ATTACHMENT_EXT GL_STENCIL_ATTACHMENT_EXT Texture Target GL_TEXTURE_2D or GL_TEXTURE_2D_ARRAY Texture Id Set 0 to detach texture Level The mipmap level of texture 9

Attach Render Buffer void glFramebufferRenderbufferEXT(GLenum target, GLenum attachmentPoint, GLenum renderbufferTarget, GLuint renderbufferId) Target GL_FRAMEBUFFER_EXT Attachment Point As same as texture Render Buffer Target GL_RENDERBUFFER_EXT Render Buffer Id Set 0 to detach render buffer 10

Multiple Render Target void glDrawBuffers( GLsizei n, const GLenum *bufs ); Call this function after binding anther FBO N The number for render targets Buffers The connection of gl_FragData[] to color attachment 11

The example of buffer array GLenum iDrawBuffer[16] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT,. GL_COLOR_ATTACHMENT15_EXT }; 12

Pixel Shader Color Attachment 0 Color Attachment 1 gl_FragData[0] gl_FragData[1] Pixel Shader Color Attachment 0 Color Attachment 1 gl_FragData[0] gl_FragData[1] If you want … Does Not Recommend! GLenum iDrawBuffer[2] = { GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT0_EXT, }; glDrawBuffers(2, iDrawBuffer); 13

Check FBO GLenum glCheckFramebufferStatusEXT(GLenum target) Return Value Case GL_FRAMEBUFFER_COMPLETE_EXT : OK GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT GL_FRAMEBUFFER_UNSUPPORTED_EXT 14

Additional Information Build Mipmap void glGenerateMipmap(GLenum target); Get Texture Content void glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type, GLvoid * img); 15

Example : Render To Texture 16

Code #include #include "glew.h" #include "glut.h“ int g_iViewport[4]; GLuint g_iFBO; GLuint g_iRB; GLuint g_iTexture; void init(); void display(); void reshape(GLsizei, GLsizei ); void init(); 17

void reshape(GLsizei w, GLsizei h){ g_iViewport[0] = 0; g_iViewport[1] = 0; g_iViewport[2] = w; g_iViewport[3] = h; } int main(int argc, char** argv){ glutInit(&argc, argv); glutInitWindowSize(512, 512); glutInitWindowPosition(0, 0); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutCreateWindow("FBO"); glewInit(); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0; } 18

void init() { //generate texture glEnable(GL_TEXTURE_2D); glGenTextures(1, &g_iTexture); glBindTexture(GL_TEXTURE_2D, g_iTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, 512, 512, 0, GL_RGBA, GL_FLOAT, NULL); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 19

//generate render buffer glGenRenderbuffers(1, &g_iRB); glBindRenderbuffer(GL_RENDERBUFFER, g_iRB); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, 512, 512); //generate FBO glGenFramebuffers(1, &g_iFBO); glBindFramebuffer(GL_FRAMEBUFFER, g_iFBO); //attach glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, g_iRB); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, g_iTexture, 0); } 20

void display() { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); //Pass1 { //render to texture glBindFramebuffer(GL_FRAMEBUFFER, g_iFBO); //clear texture and render buffer in FBO glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f); glViewport(g_iViewport[0], g_iViewport[1], g_iViewport[2], g_iViewport[3]); 21

glBindTexture(GL_TEXTURE_2D, 0); glBegin(GL_QUADS); glColor3d(1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 0.0f); glColor3d(1.0f, 0.0f, 0.0f); glVertex3f(1.0f, -1.0f, 0.0f); glColor3d(0.0f, 1.0f, 0.0f); glVertex3f(1.0f, 1.0f, 0.0f); glColor3d(0.0f, 0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glEnd(); glColor3f(1.0, 1.0, 1.0); glutSolidTeapot(0.5); } 22

//Pass2 { //render to screen glBindFramebuffer(GL_FRAMEBUFFER, 0); //clear screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, 1.0, 0.5, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0.0, 0.5, 0.0, 50.0, 0.0, 50.0, 0.0, 1.0, 0.0); 23

glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, g_iTexture); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(-50.0, 0.0, 0.0); glTexCoord2f(0.0, 100.0); glVertex3f(-50.0, 0.0, 100.0); glTexCoord2f(100.0, 100.0); glVertex3f(50.0, 0.0, 100.0); glTexCoord2f(100.0, 0.0); glVertex3f(50.0, 0.0, 0.0); glEnd(); } glutSwapBuffers(); } 24