00001 #include "common.h"
00002 #include <glew.h>
00003
00004 #include <windows.h>
00005 #include <stdlib.h>
00006 #include <io.h>
00007 #include <glew.h>
00008
00010
00017 class FBO
00018 {
00019 public:
00024 FBO(int g_iWidth, int g_iHeight)
00025 {
00026 bool bit32 =true;
00027 GLenum FBOstatus;
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 glGenTextures(1,&tex1);
00039 glBindTexture(GL_TEXTURE_2D, tex1);
00040 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
00041 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
00042 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
00043 glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
00044 if(bit32) glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, g_iWidth, g_iHeight, 0, GL_RGBA, GL_FLOAT, 0);
00045 else glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, g_iWidth, g_iHeight, 0, GL_RGBA, GL_FLOAT, 0);
00046 glGenerateMipmapEXT(GL_TEXTURE_2D);
00047 glBindTexture(GL_TEXTURE_2D, 0);
00048
00049 glGenFramebuffersEXT(1, &fbo1);
00050 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo1);
00051
00052 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D, tex1, 0);
00053
00054 FBOstatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
00055 if(FBOstatus != GL_FRAMEBUFFER_COMPLETE_EXT) CheckFBO(FBOstatus);
00056 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
00057 };
00058
00061 ~FBO()
00062 {
00063 glDeleteFramebuffersEXT(1, &fbo1);
00064 glDeleteRenderbuffersEXT(1, &depthbuffer1);
00065 glDeleteTextures(1, &tex1);
00066 };
00067
00071 void CheckFBO(GLenum FBOstatus)
00072 {
00073 if(FBOstatus == GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT) printf("Incomplete attachment\n");
00074 if(FBOstatus == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT) printf("Missing attachment\n");
00075 if(FBOstatus == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT) printf("Incomplete dimensions\n");
00076 if(FBOstatus == GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT) printf("Incomplete formats\n");
00077 if(FBOstatus == GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT) printf("Incomplete draw buffer\n");
00078 if(FBOstatus == GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT) printf("Incomplete read buffer\n");
00079 if(FBOstatus == GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT) printf("GL_FRAMEBUFFER_COMPLETE_EXT für Blur Effekt konnte ned benutzt werden\n");
00080 if(FBOstatus == GL_FRAMEBUFFER_UNSUPPORTED_EXT) printf("Framebufferobjects unsupported\n");
00081 };
00082
00085 void Bind()
00086 {
00087 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo1);
00088 };
00089
00092 void Unbind()
00093 {
00094 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
00095 };
00096
00100 void BindColorAttachementAtTextureAndEnable(unsigned int i)
00101 {
00102 glActiveTexture(GL_TEXTURE0+i);
00103 glBindTexture(GL_TEXTURE_2D, tex1);
00104 glEnable(GL_TEXTURE_2D);
00105 };
00106
00107
00108 GLuint fbo1;
00109 GLuint depthbuffer1;
00110 GLuint tex1;
00111
00112 };