About FBO

HI,I write one example about FBO,only compile 0 error and 0 warnings but linking as failure.I checked my code but found no error.which one can help me checking my code for finding the errors where occuring.This is the linking result:
Linking…
Creating library Debug/Cpp1.lib and object Debug/Cpp1.exp
Cpp1.obj : error LNK2001: unresolved external symbol “public: static int CyFrameBufferChannel::SizeT” (?SizeT@CyFrameBufferChannel@@2HA)
Cpp1.obj : error LNK2001: unresolved external symbol “public: static int CyFrameBufferChannel::SizeS” (?SizeS@CyFrameBufferChannel@@2HA)
Cpp1.obj : error LNK2001: unresolved external symbol “public: static bool CyFrameBufferChannel::asGenFrameBuffer” (?asGenFrameBuffer@CyFrameBufferChannel@@2_NA)
Cpp1.obj : error LNK2001: unresolved external symbol “public: static unsigned int * CyFrameBufferChannel::ColorImage” (?ColorImage@CyFrameBufferChannel@@2PAIA)
Cpp1.obj : error LNK2001: unresolved external symbol “public: static unsigned int * CyFrameBufferChannel::FrameBuffer” (?FrameBuffer@CyFrameBufferChannel@@2PAIA)
Debug/Cpp1.exe : fatal error LNK1120: 5 unresolved externals
Error executing link.exe.

Cpp1.exe - 6 error(s), 0 warning(s)
Cy_DLL_H

#ifndef __Cy_FBO_H__
#define __Cy_FBO_H__
#include<stdlib.h>
#include<GL/glew.h>
#ifdef _WIN32
    #ifdef __cplusplus
        extern "C"{
    #endif
            #ifdef GL_VERSION_2_2
                #define GenFrameBuffers glGenFramebuffers
                #define BindFrameBuffer glBindFramebuffer
                #define AttachFrameBuffer2D glFramebufferTexture2D
                #define CheckAttachPointStatus glCheckFramebufferStatus
                #define IsFrameBuffer glIsFramebuffer
                #define GetFrameBufferParameter glGetFramebufferParameter
                #define DeleteFramebuffers glDeleteFrameBuffers
                #define FRAME_BUFFER GL_FRAMEBUFFER_EXT
                #define RENDER_BUFFER GL_RENDERBUFFER_EXT
                #define COLOR_ATTACHPT0 GL_COLOR_ATTACHMENT0
                #define COLOR_ATTACHPT1 GL_COLOR_ATTACHMENT1
                #define COLOR_ATTACHPT2 GL_COLOR_ATTACHMENT2
                #define COLOR_ATTACHPT3 GL_COLOR_ATTACHMENT3
                #define COLOR_ATTACHPT4 GL_COLOR_ATTACHMENT4
                #define COLOR_ATTACHPT5 GL_COLOR_ATTACHMENT5
                #define COLOR_ATTACHPT6 GL_COLOR_ATTACHMENT6
                #define COLOR_ATTACHPT7 GL_COLOR_ATTACHMENT7
                #define COLOR_ATTACHPT8 GL_COLOR_ATTACHMENT8
                #define COLOR_ATTACHPT9 GL_COLOR_ATTACHMENT9
                #define COLOR_ATTACHPT10 GL_COLOR_ATTACHMENT10
                #define COLOR_ATTACHPT11 GL_COLOR_ATTACHMENT11
                #define COLOR_ATTACHPT12 GL_COLOR_ATTACHMENT12
                #define COLOR_ATTACHPT13 GL_COLOR_ATTACHMENT13
                #define COLOR_ATTACHPT14 GL_COLOR_ATTACHMENT14
                #define FBO_COMPLETE GL_FRAMEBUFFER_COMPLETE
                #define FBO_INCOMPLETE_DRAW_BUFFER GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
                #define FBO_INCOMPLETE_READ_BUFFER GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
                #define FBO_INCOMPLETE_ATTACHPT GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
                #define FBO_INCOMPLETE_FORMATS GL_FRAMEBUFFER_INCOMPLETE_FORMATS
                #define FBO_INCOMPLETE_DIMENSIONS GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS
                #define FBO_INCOMPLETE_MISSING_ATTACHPT GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
                #define FBO_UNSUPPORTED GL_FRAMEBUFFER_UNSUPPORTED
            #elif defined GL_VERSION_2_0&#0124;&#0124;GL_VERSION_2_1
                #define GenFrameBuffers glGenFramebuffersEXT
                #define BindFrameBuffer glBindFramebufferEXT
                #define AttachFrameBuffer2D glFramebufferTexture2DEXT
                #define CheckAttachPointStatus glCheckFramebufferStatusEXT
                #define IsFrameBuffer glIsFramebufferEXT
                #define GetFrameBufferParameter glGetFramebufferParameterEXT
			    #define DeleteFrameBuffers glDeleteFramebuffersEXT
                #define FRAME_BUFFER GL_FRAMEBUFFER_EXT
                #define RENDER_BUFFER GL_RENDERBUFFER_EXT
                #define COLOR_ATTACHPT0 GL_COLOR_ATTACHMENT0_EXT
                #define COLOR_ATTACHPT1 GL_COLOR_ATTACHMENT1_EXT
                #define COLOR_ATTACHPT2 GL_COLOR_ATTACHMENT2_EXT
                #define COLOR_ATTACHPT3 GL_COLOR_ATTACHMENT3_EXT
                #define COLOR_ATTACHPT4 GL_COLOR_ATTACHMENT4_EXT
                #define COLOR_ATTACHPT5 GL_COLOR_ATTACHMENT5_EXT
                #define COLOR_ATTACHPT6 GL_COLOR_ATTACHMENT6_EXT
                #define COLOR_ATTACHPT7 GL_COLOR_ATTACHMENT7_EXT
                #define COLOR_ATTACHPT8 GL_COLOR_ATTACHMENT8_EXT
                #define COLOR_ATTACHPT9 GL_COLOR_ATTACHMENT9_EXT
                #define COLOR_ATTACHPT10 GL_COLOR_ATTACHMENT10_EXT
                #define COLOR_ATTACHPT11 GL_COLOR_ATTACHMENT11_EXT
                #define COLOR_ATTACHPT12 GL_COLOR_ATTACHMENT12_EXT
                #define COLOR_ATTACHPT13 GL_COLOR_ATTACHMENT13_EXT
                #define COLOR_ATTACHPT14 GL_COLOR_ATTACHMENT14_EXT
                #define FBO_COMPLETE GL_FRAMEBUFFER_COMPLETE_EXT
                #define FBO_INCOMPLETE_DRAW_BUFFER GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
                #define FBO_INCOMPLETE_READ_BUFFER GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
                #define FBO_INCOMPLETE_ATTACHPT GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
                #define FBO_INCOMPLETE_FORMATS GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
                #define FBO_INCOMPLETE_DIMENSIONS GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
                #define FBO_INCOMPLETE_MISSING_ATTACHPT GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
                #define FBO_UNSUPPORTED GL_FRAMEBUFFER_UNSUPPORTED_EXT
            #else
                #define
            #endif
    #ifdef __cplusplus
        }
    #endif
#endif
//
const unsigned int ColorAttachPoint[]={COLOR_ATTACHPT0, COLOR_ATTACHPT1, COLOR_ATTACHPT2,
                                       COLOR_ATTACHPT3, COLOR_ATTACHPT4, COLOR_ATTACHPT5,
                                       COLOR_ATTACHPT6, COLOR_ATTACHPT7, COLOR_ATTACHPT8,
                                       COLOR_ATTACHPT9, COLOR_ATTACHPT10,COLOR_ATTACHPT11,
                                       COLOR_ATTACHPT12,COLOR_ATTACHPT13,COLOR_ATTACHPT14};
//
class __declspec(dllexport) CyFrameBufferChannel{
         CyFrameBufferChannel();
virtual ~CyFrameBufferChannel();
public:
       void Gen();
       void Begin();
       void End();
       void Delete();
       void CheckStatus();
       bool IsValid(unsigned int);
public:
       static unsigned int* FrameBuffer;
       static unsigned int* ColorImage;
       static bool asGenFrameBuffer;
       static int GenFrameBufferCount;
       static int SizeS;
       static int SizeT;
};
#endif

Cy_DLL_CPP

#include<stdlib.h>
#include<iostream.h>
#include<assert.h>
#include<GL/glew.h>
#include<GL/glut.h>
#include "CyFBO.h"
#pragma comment(lib,"glew32.lib")

CyFrameBufferChannel::CyFrameBufferChannel()
{
	asGenFrameBuffer=false;
	FrameBuffer=0;
	ColorImage=0;
	GenFrameBufferCount=1;
	SizeS=512;
	SizeT=512;
}
//
CyFrameBufferChannel::~CyFrameBufferChannel(){}
//
void CyFrameBufferChannel::Gen()
{
    if(asGenFrameBuffer)
    {
        GenFrameBuffers(GenFrameBufferCount,FrameBuffer);
        glGenTextures(GenFrameBufferCount,ColorImage);
    }
    else
    {
        FrameBuffer[0]=GL_BACK;
    }
}
//
void CyFrameBufferChannel::Begin()
{
    unsigned int* attachPoint=0;
    for(int i=0;i<GenFrameBufferCount;i++)
    {
		assert(IsValid(ColorImage[i]));
          glActiveTexture(GL_TEXTURE0+i);
          glBindTexture(GL_TEXTURE_2D,ColorImage[i]);
          glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
          glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
          glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
          glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
          glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE);
          glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_INTERPOLATE);
          glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_ALPHA,GL_INTERPOLATE);
          glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,SizeS,SizeT,0,GL_RGBA,GL_UNSIGNED_BYTE,NULL);
		assert(IsValid(FrameBuffer[i]));
          BindFrameBuffer(FRAME_BUFFER,ColorAttachPoint[i]);
          AttachFrameBuffer2D(FRAME_BUFFER,ColorAttachPoint[i],GL_TEXTURE_2D,ColorImage[i],0);
          attachPoint[i]=ColorAttachPoint[i];
    }
    glDrawBuffers(GenFrameBufferCount,attachPoint);
}
//
void CyFrameBufferChannel::End()
{
    if(FrameBuffer!=0)
	{
        for(int i=0;i<GenFrameBufferCount;i++)
        {
            BindFrameBuffer(FRAME_BUFFER,0);
        }
	}
    else{ exit(1); }
}
//
void CyFrameBufferChannel::Delete()
{
    if(FrameBuffer!=0)
        DeleteFrameBuffers(GenFrameBufferCount,FrameBuffer);
	else{ return; }
}
//
void CyFrameBufferChannel::CheckStatus()
{
    unsigned int status=CheckAttachPointStatus(FRAME_BUFFER);
    switch(status)
    {
        case FBO_COMPLETE:
               cout<<"No error with frame buffer.
";
               break;
        case FBO_INCOMPLETE_FORMATS:
               cout<<"Error:each attached image must have the same formats.
";
               break;
        case FBO_INCOMPLETE_DIMENSIONS:
               cout<<"Error:each attached image must have the same dimensions.
";
               break;
        case FBO_INCOMPLETE_DRAW_BUFFER:
               cout<<"Error:missing draw buffers.
";
               break;
        case FBO_INCOMPLETE_READ_BUFFER:
               cout<<"Error:missing read buffers.
";
               break;
        case FBO_INCOMPLETE_ATTACHPT:
               cout<<"Error:incomplete color attach point.
";
               break;
        case FBO_INCOMPLETE_MISSING_ATTACHPT:
               cout<<"Error:missing color attach point.
";
               break;
    }
}
bool CyFrameBufferChannel::IsValid(unsigned int fbo)
{
    return IsFrameBuffer(fbo)==GL_TRUE?true:false;
}

unsigned int* CyFrameBufferChannel::FrameBuffer;
unsigned int* CyFrameBufferChannel::ColorImage;
bool CyFrameBufferChannel::asGenFrameBuffer;
int CyFrameBufferChannel::GenFrameBufferCount;
int CyFrameBufferChannel::SizeS;
int CyFrameBufferChannel::SizeT;

Proc

#include<stdlib.h>
#include<iostream.h>
#include<assert.h>
#include<GL/glew.h>
#include<GL/glut.h>
#include<IL/il.h>
#include"CyFBO.h"

#pragma comment(lib,"glew32.lib")
#pragma comment(lib,"CyFBO.lib")
#pragma comment(lib,"DevIL.lib")

CyFrameBufferChannel* fboNode;
GLuint PBO;
ILuint image;
void samplerInit()
{
    ilInit();
    ilGenImages(1,&image);
    ilBindImage(image);
    ilLoadImage("C:\\dream.jpg");
    if(!ilConvertImage(IL_RGBA,GL_UNSIGNED_BYTE))
    {
        cout<<"Convert image as failure.
";
        exit(1);
    }
    int size_h=ilGetInteger(IL_IMAGE_WIDTH);
    int size_v=ilGetInteger(IL_IMAGE_HEIGHT);
    fboNode->asGenFrameBuffer=true;
    fboNode->SizeS=size_h;
    fboNode->SizeT=size_v;
}

void display()
{ 
    fboNode->Begin();
        //Copy pixels form FBO to PBO
	    assert(fboNode->IsValid(*(fboNode->FrameBuffer)));
        glGenBuffers(1,&PBO);
        glReadBuffer(ColorAttachPoint[0]);
        glDrawBuffer(GL_BACK);
		fboNode->CheckStatus();
        glBindBuffer(GL_PIXEL_PACK_BUFFER,PBO);
        glClear(GL_COLOR_BUFFER_BIT);
        glClearColor(1.0,1.0,1.0,1.0);
        glCopyPixels(fboNode->SizeS,fboNode->SizeT,GL_RGBA,GL_UNSIGNED_BYTE,GL_COLOR);
    fboNode->End();
	fboNode->Delete();
    
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D,fboNode->ColorImage[0]);
    glBegin(GL_QUADS);
        glColor4f(0.45,0.25,0.3,1.0);
        glMultiTexCoord2f(GL_TEXTURE0,0.0,0.0);
        glVertex2f(0.0,0.0);
        glColor4f(0.45,0.25,0.3,1.0);
        glMultiTexCoord2f(GL_TEXTURE0,0.0,1.0);
        glVertex2f(0.0,1.0);
        glColor4f(0.45,0.25,0.3,1.0);
        glMultiTexCoord2f(GL_TEXTURE0,1.0,1.0);
        glVertex2f(1.0,1.0);
        glColor4f(0.45,0.25,0.3,1.0);
        glMultiTexCoord2f(GL_TEXTURE0,1.0,0.0);
        glVertex2f(1.0,0.0);
    glEnd();
    glFinish();
    glutSwapBuffers();
}

void lightingInit() 
{ 
    GLfloat k0=1.0; 
    GLfloat k1=0.125; 
    GLfloat k2=0.25; 
	
    GLfloat mSpecular[]={ 0.9,0.9,0.9,1.0 }; 
    GLfloat Pos0[]={ 0.0,10.0,0.0,1.0 }; 
    GLfloat Pos1[]={ 10.0,0.0,0.0,1.0 }; 
    GLfloat Pos2[]={ 0.0,0.0,10.0,1.0 }; 
    GLfloat dif0[]={ 0.5,0.25,0.25,1.0 }; 
    GLfloat dif1[]={ 0.25,0.5,0.25,1.0 }; 
    GLfloat dif2[]={ 0.25,0.25,0.5,1.0 }; 
    GLfloat exp0[]={ 0.95,0.95,0.95,1.0 }; 
    GLfloat exp1[]={ 0.95,0.85,0.85,1.0 }; 
    GLfloat exp2[]={ 0.95,0.75,0.95,1.0 }; 
    glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE); 
    glMaterialf(GL_FRONT,GL_SHININESS,128.0); 
    glLightfv(GL_LIGHT0,GL_POSITION,Pos0); 
    glLightfv(GL_LIGHT1,GL_POSITION,Pos1); 
    glLightfv(GL_LIGHT2,GL_POSITION,Pos2); 
    glLightfv(GL_LIGHT0,GL_DIFFUSE,dif0); 
    glLightfv(GL_LIGHT1,GL_DIFFUSE,dif1); 
    glLightfv(GL_LIGHT2,GL_DIFFUSE,dif2); 
    glLightfv(GL_LIGHT0,GL_SPECULAR,exp0); 
    glLightfv(GL_LIGHT1,GL_SPECULAR,exp1); 
    glLightfv(GL_LIGHT2,GL_SPECULAR,exp2); 
    glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION,k0); 
    glLightf(GL_LIGHT1,GL_CONSTANT_ATTENUATION,k0); 
    glLightf(GL_LIGHT2,GL_CONSTANT_ATTENUATION,k0); 
    glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION,k1); 
    glLightf(GL_LIGHT1,GL_LINEAR_ATTENUATION,k1); 
    glLightf(GL_LIGHT2,GL_LINEAR_ATTENUATION,k1); 
    glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION,k2); 
    glLightf(GL_LIGHT1,GL_QUADRATIC_ATTENUATION,k2); 
    glLightf(GL_LIGHT2,GL_QUADRATIC_ATTENUATION,k2); 
    glEnable(GL_COLOR_MATERIAL); 
    glEnable(GL_LIGHTING); 
    glEnable(GL_LIGHT0); 
    glEnable(GL_LIGHT1); 
    glEnable(GL_LIGHT2); 
    glShadeModel(GL_SMOOTH); 
} 

void stateForZero()
{
    glDisable(GL_LIGHT2);
    glDisable(GL_LIGHT1);
    glDisable(GL_LIGHT0);
    glDisable(GL_LIGHTING);
    glDisable(GL_TEXTURE_2D);
}

void reshape(GLsizei w,GLsizei h)
{
    glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(-5.0,5.0,-5.0,5.0,-10.0,10.0);
    glMatrixMode(GL_TEXTURE);
        glTranslatef(0.5,0.5,0.0);
        glScalef(0.5,0.5,1.0);
        glRotatef(60.0,0.0,0.0,1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0f,0.0,-1.0);
}

int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE);
    glutInitWindowSize(800,600);
    glutInitWindowPosition(0,0);
    glutCreateWindow("Frame_Buffer_Rect");
    lightingInit();
    samplerInit();
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutMainLoop();
    stateForZero();	
    return 0;
}

Are you sure you want these fields to be static?

Thanks for k_szczech,now it no error but can not
run.The feedback information is:Program need to be closed due to technical problems,what reason is it?
–thanks

Originally posted by Cgor_Cyrosly:
The feedback information is:Program need to be closed due to technical problems,what reason is it?

You need to initialize the fboNode variable by new object at the start of your program before you use it.

This my fbo project:
http://www.physdev.com/upload/upload/public/FboProc.rar

[b]

You need to initialize the fboNode variable by new object at the start of your program before you use it.
[/b]
I dont understand what your means,I have been initialized the "fboNode" with the function "samplerInit()".Is that or another? Therere the problems as the same as my old programs which both compiled and linked with no error and no warning but execuate as failure.The same debugging result for the programs as the leaved point at glGenFramebuffersEXT.Why?I will Crazy :eek:

You have this line in your code:

CyFrameBufferChannel* fboNode;

Which is correct - fboNode is a pointer to an object. This object’s type is CyFrameBufferChannel.
Now you only need to create this object before you start using it:

fboNode = new CyFrameBufferChannel;

And destroy it at exit of program when you don’t want to use it anymore:

delete fboNode;

Originally posted by Cgor_Cyrosly:
I don`t understand what your means,I have been initialized the “fboNode” with the function “samplerInit()”.Is that or another?

I meant construction of the object as explained by k_szczech.


There`re the problems as the same as my old programs which both compiled and linked with no error and no warning but execuate as failure.The same debugging result for the programs as the leaved point at glGenFramebuffersEXT.

It seems that you are using the GLEW library. This library has function named glewInit() which must be called after you create the window (glutCreateWindow) before you can use any extension function the library provides including the glGenFramebuffersEXT. If you do not call the glewInit(), the pointer to glGenFramebuffersEXT function will not point to the valid function and the call will fail with access violation. See this example of GLEW initialization code.

Originally posted by Komat:
[b] [quote]Originally posted by Cgor_Cyrosly:
[b]I dont understand what your means,I have been initialized the "fboNode" with the function "samplerInit()".Is that or another? [/b] I meant construction of the object as explained by k_szczech. Ive changed DLL_H form:
static unsigned int* FrameBuffer;
static unsigned int* ColorImage;
static bool asGenFrameBuffer;
static int GenFrameBufferCount;
static int SizeS;
static int SizeT;
to:
unsigned int* FrameBuffer;
unsigned int* ColorImage;
bool asGenFrameBuffer;
int GenFrameBufferCount;
int SizeS;
int SizeT;
and delete these maped in DLL_CPP with “::”

[b]
Therere the problems as the same as my old programs which both compiled and linked with no error and no warning but execuate as failure.The same debugging result for the programs as the leaved point at glGenFramebuffersEXT.[/b] It seems that you are using the GLEW library. This library has function named glewInit() which must be called after you create the window (glutCreateWindow) before you can use any extension function the library provides including the glGenFramebuffersEXT. If you do not call the glewInit(), the pointer to glGenFramebuffersEXT function will not point to the valid function and the call will fail with access violation. See [this example](http://glew.sourceforge.net/basic.html) of GLEW initialization code. [/b][/QUOTE]I add the under code: GLenum err; if((err=glewInit())!=GLEW_OK) { printf("Initializing as failure. "); } after glutCreateWindow() be called. As the result,it faliure at fboNode->asGenFrameBuffer=true;The debugging with information "expression can not be evaluated". I found no error,wheres it?

Originally posted by Cgor_Cyrosly:
As the result,it faliure at fboNode->asGenFrameBuffer=true;The debugging with information “expression can not be evaluated”.
I found no error,where`s it?

You also need to create the object for fboNode variable using the

fboNode = new CyFrameBufferChannel;

as k_szczech told you in his second post.

Yes,I`ve did it also,but unresolved external

Your constructor and destructor are not public:

         CyFrameBufferChannel();
virtual ~CyFrameBufferChannel();

Make them public and you can also try this to create object:

fboNode = new CyFrameBufferChannel();

Now,That`s ok,thanks for all