Results 1 to 5 of 5

Thread: Frame Buffer and render to texture problem.

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2009
    Posts
    3

    Frame Buffer and render to texture problem.

    Code :
    GLuint fbo,texture;
    BOOL fbGenerated = false;
    LLRenderTarget target;
    void render_offscreen_fbo(){
    		if(!fbGenerated){
    			fbGenerated = TRUE;
    			glDisable(GL_DEPTH_TEST);
    			glEnable(GL_TEXTURE_2D);
     
    			glGenTextures(1, &texture);
    			glBindTexture(GL_TEXTURE_2D, texture);
    			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 256, 256, 0, GL_RGB, GL_UNSIGNED_INT, NULL);
    	//glGenerateMipmapEXT(GL_TEXTURE_2D);
     
    			glGenFramebuffersEXT(1, &fbo);
    			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
     
    			glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texture, 0);
     
    			if(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)!=GL_FRAMEBUFFER_COMPLETE_EXT)
    			{
    					cout<<"The fbo is not complete"<<endl;
    					cout<<"Error: "<<glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)<<endl;
    			}
    		}
    		//bind the FBO, and the associated texture.
     
     
     
     
     
    	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
    	glClearColor(0.0, 0.0, 1.0, 0.0);
    	glClear(GL_COLOR_BUFFER_BIT);
    	glDisable(GL_TEXTURE_2D);
     
    	glPushAttrib(GL_VIEWPORT_BIT);
    	glViewport(0, 0, 256, 256);
     
    	glColor4f(1.0, 1.0, 0.0, 0.0);
    	glBegin(GL_QUADS);
    		glVertex2f(0.5, 0.5);
    		glVertex2f(0.5, -0.5);
    		glVertex2f(-0.5, -0.5);
    		glVertex2f(-0.5, 0.5);
    	glEnd();
     
    	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    	glClearColor(0.0, 1.0, 0.0, 0.0);
    	glEnable(GL_SCISSOR_TEST);
    	glScissor(0,0,256,256);
    	glClear(GL_COLOR_BUFFER_BIT);
    	glEnable(GL_TEXTURE_2D);
     
     
     
    	glColor4f(1.0, 1.0, 1.0, 0.0);
    	glBegin(GL_QUADS);
    		glTexCoord2f(0.0, 0.0); glVertex2f(1.0, 1.0);
    		glTexCoord2f(0.0, 1.0); glVertex2f(1.0, -1.0);
    		glTexCoord2f(1.0, 1.0); glVertex2f(-1.0, -1.0);
    		glTexCoord2f(1.0, 0.0); glVertex2f(-1.0, 1.0);
    	glEnd();
    	glPopAttrib();
    	glDisable(GL_SCISSOR_TEST);
     
    }

    I am expecting a texture to be rendered with yellow quads.

    But what I am getting is a green screen?

    Any help?

  2. #2
    Senior Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    555

    Re: Frame Buffer and render to texture problem.

    You don't appear to have done anything to setup projection or modelview matrices when drawing to either the FBO or the main framebuffer.. Perhaps you do those elsewhere, but from your code I have no idea.

    Also if you want to draw the contents of an FBO texture to the screen you need to bind the texture associated with the FBO. You neglect to do that at the bottom of the code as far as I can see.

    I presume you've been looking at something like this..
    http://www.gamedev.net/reference/art...rticle2331.asp

    Try this : http://www.songho.ca/opengl/gl_fbo.html
    It has some code to download which may make it easier.



  3. #3
    Junior Member Newbie
    Join Date
    Aug 2009
    Posts
    3

    Re: Frame Buffer and render to texture problem.

    Quote Originally Posted by scratt
    You don't appear to have done anything to setup projection or modelview matrices when drawing to either the FBO or the main framebuffer.. Perhaps you do those elsewhere, but from your code I have no idea.
    This is just basic gl drawing, so I didnt feel the necessity for them.

    Quote Originally Posted by scratt
    Also if you want to draw the contents of an FBO texture to the screen you need to bind the texture associated with the FBO. You neglect to do that at the bottom of the code as far as I can see.
    Yeah I realized it late and added it, but couldnt find any effect, except for a small bluedot in the green region.

  4. #4
    Senior Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    555

    Re: Frame Buffer and render to texture problem.

    Quote Originally Posted by mickey123
    This is just basic gl drawing, so I didnt feel the necessity for them.
    I am confused by your reply..

    You mean you don't have them anywhere in your code? If so, then be aware they *are* necessary for all OpenGL drawing. You may get lucky with their default settings, but their default settings are not Ortho, so you are going to get strange results.

    If they are elsewhere in your code, and you are asking for help with a bug / problem it is best to post a complete example, even if it is a slightly cut down version of your problem. Otherwise we'll just be guessing for our replies...

    Quote Originally Posted by mickey123
    Yeah I realized it late and added it, but couldnt find any effect, except for a small bluedot in the green region.
    This tends to suggest something wrong with your matrices... The "small blue dot" is your *entire* FBO texture by the looks of the clear colour you are using!

  5. #5
    Junior Member Newbie
    Join Date
    Aug 2009
    Posts
    3

    Re: Frame Buffer and render to texture problem.

    @scratt

    True regarding blue dot, as a noob have to learn the usage of projections decently.

Similar Threads

  1. Artifacts from scaling texture in frame buffer. Why ?
    By 0xdimon in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-22-2018, 07:37 AM
  2. can't bind a texture depth buffer to a frame buffer
    By sczybt in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 02-23-2014, 06:37 AM
  3. How to sample texture to frame buffer?
    By SagoO in forum OpenGL: GLSL
    Replies: 2
    Last Post: 04-04-2011, 08:59 AM
  4. glCopyTexImage2D Problem -> Texture to copy bigger than frame buffer
    By Kilam Malik in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 03-13-2002, 12:03 AM
  5. Copy from texture memory to frame buffer
    By Xelatihy in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 11-04-2000, 02:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean