Hierarchical Edge Bundle 1.0
|
00001 #pragma once 00002 #include <glew.h > 00003 #include <windows.h> 00004 #include <stdlib.h> 00005 #include <io.h> 00006 #include <stdio.h> 00007 #include <vector> 00008 00010 00017 class FBO 00018 { 00019 public: 00025 FBO(int g_iWidth, int g_iHeight, int numTex) 00026 { 00027 bool bit32 =true; 00028 GLenum FBOstatus; 00029 00030 glGenTextures(1, &depthbuffer1); 00031 glBindTexture(GL_TEXTURE_2D, depthbuffer1); 00032 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 00033 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 00034 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); 00035 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); 00036 glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, g_iWidth, g_iHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); 00037 glBindTexture(GL_TEXTURE_2D, 0); 00038 00039 tex1.resize(numTex); 00040 for(unsigned int i = 0; i < tex1.size(); i++) 00041 { 00042 glGenTextures(1,&tex1[i]); 00043 glBindTexture(GL_TEXTURE_2D, tex1[i]); 00044 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 00045 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 00046 00047 // Remove artefa3ct on the edges of the shadowmap 00048 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); 00049 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); 00050 00051 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, g_iWidth, g_iHeight, 0, GL_RGBA, GL_FLOAT, 0); 00052 glBindTexture(GL_TEXTURE_2D, 0); 00053 } 00054 00055 glGenFramebuffersEXT(1, &fbo1); 00056 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo1); 00057 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT ,GL_TEXTURE_2D, depthbuffer1, 0); 00058 00059 buffers.resize(tex1.size()); 00060 for(unsigned int i = 0; i < tex1.size(); i++) 00061 { 00062 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i,GL_TEXTURE_2D, tex1[i], 0); 00063 buffers[i] = GL_COLOR_ATTACHMENT0_EXT+i; 00064 } 00065 00066 00067 FBOstatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); 00068 if(FBOstatus != GL_FRAMEBUFFER_COMPLETE_EXT) CheckFBO(FBOstatus); 00069 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 00070 }; 00071 00074 ~FBO() 00075 { 00076 glDeleteFramebuffersEXT(1, &fbo1); 00077 glDeleteRenderbuffersEXT(1, &depthbuffer1); 00078 for(unsigned int i = 0; i < tex1.size(); i++) glDeleteTextures(1, &tex1[i]); 00079 tex1.clear(); 00080 }; 00081 00085 void CheckFBO(GLenum FBOstatus) 00086 { 00087 if(FBOstatus == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT) printf("Incomplete attachment\n"); 00088 if(FBOstatus == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT) printf("Missing attachment\n"); 00089 if(FBOstatus == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT) printf("Incomplete dimensions\n"); 00090 if(FBOstatus == GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT) printf("Incomplete formats\n"); 00091 if(FBOstatus == GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT) printf("Incomplete draw buffer\n"); 00092 if(FBOstatus == GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT) printf("Incomplete read buffer\n"); 00093 if(FBOstatus == GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT) printf("GL_FRAMEBUFFER_COMPLETE_EXT für Blur Effekt konnte ned benutzt werden\n"); 00094 if(FBOstatus == GL_FRAMEBUFFER_UNSUPPORTED_EXT) printf("Framebufferobjects unsupported\n"); 00095 }; 00096 00099 void Bind() 00100 { 00101 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo1); //FRAMEBUFFEROBJECT START!!! 00102 }; 00103 00106 void Unbind() 00107 { 00108 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 00109 }; 00110 00114 void BindColorAttachementAtTextureAndEnable(unsigned int i) 00115 { 00116 glActiveTexture(GL_TEXTURE0+i); 00117 glBindTexture(GL_TEXTURE_2D, tex1[0]); 00118 glEnable(GL_TEXTURE_2D); 00119 }; 00120 00125 void BindDepthBufferAtTextureAndEnable(unsigned int i) 00126 { 00127 glActiveTexture(GL_TEXTURE0+i); 00128 glBindTexture(GL_TEXTURE_2D, depthbuffer1); 00129 glEnable(GL_TEXTURE_2D); 00130 }; 00131 00135 void DrawBuffers() 00136 { 00137 glDrawBuffers(buffers.size(), &buffers[0]); 00138 } 00139 00140 GLuint fbo1; 00141 GLuint depthbuffer1; 00142 std::vector<GLuint> tex1; 00143 std::vector<GLenum> buffers; 00144 00145 };