воскресенье, 22 января 2012 г.

OpenGL FBO (Step by step)

Step by step how to use EXT_framebuffer_object.

Check extenstion

  1. - (BOOL) initFBO  
  2. {  
  3.     // check extension  
  4.     const GLubyte* extensions = glGetString ( GL_EXTENSIONS );  
  5.     if ( extensions )  
  6.     {     
  7.         if(gluCheckExtension((GLubyte*)("GL_EXT_framebuffer_object"), extensions))  
  8.             return YES;  
  9.     }  
  10.     return NO;  
  11. }  

сreate the texture for framebuffer

  1. GLuint textureId      
  2. glGenTextures ( 1, &textureId );  
  3. glBindTexture ( GL_TEXTURE_2D, textureId );  
  4. glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );  
  5. glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );  
  6. glTexImage2D ( GL_TEXTURE_2D, 0, 4, TextureWidth, TextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0 );  

сreate framebuffer (FBO)

  1. GLuint frameBufferId;  
  2.   
  3. glGenFramebuffersEXT ( 1, &frameBufferId ); // 0 - main buffer, framebufferId > 0  
  4. glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT, frameBufferId );  
  5. glFramebufferTexture2DEXT ( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,  
  6.  GL_TEXTURE_2D, textureId, 0 ); // attach texture to fbo  
  7.   
  8. // check fbo ( glCheckFramebufferStatusEXT )  
  9. // ...  
  10.   
  11. glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT, 0 ); // select main buffer  

сheck framebuffer

  1. GLenum status = glCheckFramebufferStatusEXT ( GL_FRAMEBUFFER_EXT );  
  2. if ( status != GL_FRAMEBUFFER_COMPLETE_EXT )  
  3. {  
  4.     switch ( status )  
  5.     {  
  6.         case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:  
  7.             NSLog(@"FrameBuffer Error - GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT");  
  8.             break;  
  9.         case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:  
  10.             NSLog(@"FrameBufferErGL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT");  
  11.             break;  
  12.         case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:  
  13.             NSLog(@"FrameBuffer Error - GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT");  
  14.             break;  
  15.         case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:  
  16.             NSLog(@"FrameBuffer Error - GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT");  
  17.             break;  
  18.         case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:  
  19.             NSLog(@"FrameBuffer Error - GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT");                            
  20.             break;  
  21.         case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:  
  22.             NSLog(@"FrameBuffer Error - GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT");  
  23.             break;  
  24.         case GL_FRAMEBUFFER_UNSUPPORTED_EXT:  
  25.             NSLog(@"FrameBuffer Error - GL_FRAMEBUFFER_UNSUPPORTED_EXT");  
  26.             break;  
  27.         default:  
  28.             NSLog(@"FrameBuffer Error - Unknown error");  
  29.               
  30.             break;  
  31.     }  
  32.         
  33.     return NO;  
  34. }  

use in the code

  1. glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT, frameBufferId ); // select fbo
  2.   
  3. glClearColor ( 0.0f, 0.0f, 1.0f, 1.0f );   
  4. glClear ( GL_COLOR_BUFFER_BIT );  
  5.   
  6. // render into texture ( update model view transforms )
  7. // ...  
  8.   
  9. glBindFramebufferEXT ( GL_FRAMEBUFFER_EXT, 0 );      // select main buffer  

We can use the texture for post-effects. Do not forget to delete resources ;-)

Example OpenGL FBO (github) 


вторник, 3 января 2012 г.

ePic for Mac 1.4 (winter release)




What's New in Version 1.4


* Full support for OS X Lion, including full-screen mode
* Improved support multi-touch gestures to Magic Trackpad and Magic Mouse
* Support Aperture libraries
* Support Picasa web albums
* Support iPhoto albums
* New mode for 3D presentation ( Breath presentation )
* New SlideShow effects ( two nice effect's )
* Ability to hide the control panel
* Function detailed view your photos in a Slide Show
* Many minor fixes

Download via Mac App Store (itunes link)
Donwload via Site (site link)

Epicreal Team Links

twitter
facebook