Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem with framebuffer-objects.

Started by Forlom Jul 2, 2007 at 12:07 PM 1 replies 700+ views
Original Post
Forlom
Forlom
Hi, I've a problem using fbos: I have one created with a depthbuffer and a texture. But if I want to render to this texture, and display it after, the texturecoords are wrong. I render the texture (the one I've rendered to) using GL_QUADS on the screen and the output is mirrored. now to the code: Framebuffer Initialization:

Gl.glGenFramebuffersEXT(1, framebuffer);
Gl.glBindFramebufferEXT(Gl.GL_FRAMEBUFFER_EXT, framebuffer[0]);
						
//adding a depthbuffer 
Gl.glGenRenderbuffersEXT(1, depthbuffer);
Gl.glBindRenderbufferEXT(Gl.GL_RENDERBUFFER_EXT,depthbuffer[0]);
Gl.glRenderbufferStorageEXT(Gl.GL_RENDERBUFFER_EXT, Gl.GL_DEPTH_COMPONENT, width,height);
			
Gl.glFramebufferRenderbufferEXT(Gl.GL_FRAMEBUFFER_EXT, Gl.GL_DEPTH_ATTACHMENT_EXT,Gl.GL_RENDERBUFFER_EXT, depthbuffer[0]);

Gl.glBindFramebufferEXT(Gl.GL_FRAMEBUFFER_EXT, 0);	

glCheckFramebufferStatusEXT(Gl.GL_FRAMEBUFFER_EXT) returns GL_FRAMEBUFFER_COMPLETE_EXT Texture loading:


Gl.glGenTextures(1, texture);
	   		
Gl.glBindTexture( Gl.GL_TEXTURE_2D,texture[0]);
			
Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR );
Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR );
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP_TO_EDGE);
Gl.glTexParameterf(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP_TO_EDGE);

//surface is a SDL-Surface;
Gl.glTexImage2D( Gl.GL_TEXTURE_2D, 0,  Gl.GL_RGBA8, surface.w, surface.h, 0,Gl.GL_RGBA,Gl.GL_UNSIGNED_BYTE, surface.pixels );		

Before the texture is loaded I initialize the framebuffer and after creating the texture I bind it to the fbo:


Gl.glBindFramebufferEXT(Gl.GL_FRAMEBUFFER_EXT, framebuffer[0]);
				
Gl.glBindTexture(Gl.GL_TEXTURE_2D,texture.TextureId);
			
Gl.glFramebufferTexture2DEXT(Gl.GL_FRAMEBUFFER_EXT, Gl.GL_COLOR_ATTACHMENT0_EXT, Gl.GL_TEXTURE_2D,texture.TextureId, 0);
					
Gl.glBindFramebufferEXT(Gl.GL_FRAMEBUFFER_EXT, 0);

before rendering to the texture I call Gl.glBindFramebufferEXT(Gl.GL_FRAMEBUFFER_EXT, framebuffer[0]); the displaylist which I use to render the quad is initialised here

displaylist = Gl.glGenLists(1);
            
            Gl.glNewList(displaylist,Gl.GL_COMPILE);
                
            Gl.glBegin( Gl.GL_QUADS);
                
            Gl.glTexCoord2f(0.0f, 0.0f);    

            Gl.glVertex2i(0, 0);
                
            Gl.glTexCoord2f(0.0f,1.0f);
            Gl.glVertex2i( 0,texture.Height);
                
            Gl.glTexCoord2f(1.0f,1.0f);
            Gl.glVertex2i(  texture.Width, texture.Height);
                
            Gl.glTexCoord2f(1.0f,0.0f);
            Gl.glVertex2i( texture.Width,0);
                
            Gl.glEnd(); 
                                
            Gl.glEndList();
and rendering is going on here:

Gl.glBindFramebufferEXT(Gl.GL_FRAMEBUFFER_EXT, rendertarget.Framebuffer[0]);
            Gl.glPushAttrib(Gl.GL_VIEWPORT_BIT);
            Gl.glViewport(0,0,rendertarget.Width, rendertarget.Height);

texture.Set();
                    
            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);        
            Gl.glEnable(Gl.GL_BLEND);                        
            
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glPushMatrix();                                
            Gl.glLoadIdentity();    
                            
            Gl.glTranslated((double)x,(double)y,0);
            
            
            Gl.glListBase( displaylist);
            Gl.glCallList( displaylist);
            
            
            Gl.glPopMatrix();

Gl.glPopAttrib();
            Gl.glBindFramebufferEXT(Gl.GL_FRAMEBUFFER_EXT, 0);
        }
I hope I could describe my problem with my poor english and somebody can help me. Thank You Bye
Basiror
Basiror
You set your viewport correct but I don t see where you set the projection matrix (glOrtho), maybe you are using the previous projection matrix or maybe your camera is behind the quad thus the left-right coordinates are flipped

http://www.8ung.at/basiror/theironcross.html
Forlom
Forlom
Hi,

thank you very much, basiror you helped me alot! Now everything works just fine. Now I call glOrtho() with the right dimensions before I render to my texture and after it I call it again with the screen dimensions. Now the mirror-effect is gone and its even rendered with the right size! :)

Bye
Forlom

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.