Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: ninogenio on May 11, 2007
-
jim got me curious about opengls pbuffer so i started googling well ive comeup with this it uses the framebuffer arb extension instead of the pbuffer but its easyer to read and the framebuffer is newer.
most of this code has come from google sites but its very easy to understand.
exe and source.
-
here is another test it draw too two textures its amazing how fast gl can do this
could you guys test this and let me know if it runs ok i need to know how compatible it is on diffrent comp and also does it run smooth?
-
I get a black cube, so it's not supported here. ATI X1600, latest drivers. Which extension is it using?
Jim
-
weird im on an ati x1550 latest drivers?
here is the extensions.
Dim Shared As PFNGLISRENDERBUFFEREXTPROC glIsRenderbufferEXT
Dim Shared As PFNGLBINDRENDERBUFFEREXTPROC glBindRenderbufferEXT
Dim Shared As PFNGLDELETERENDERBUFFERSEXTPROC glDeleteRenderbuffersEXT
Dim Shared As PFNGLGENRENDERBUFFERSEXTPROC glGenRenderbuffersEXT
Dim Shared As PFNGLRENDERBUFFERSTORAGEEXTPROC glRenderbufferStorageEXT
Dim Shared As PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC glGetRenderbufferParameterivEXT
Dim Shared As PFNGLISFRAMEBUFFEREXTPROC glIsFramebufferEXT
Dim Shared As PFNGLBINDFRAMEBUFFEREXTPROC glBindFramebufferEXT
Dim Shared As PFNGLDELETEFRAMEBUFFERSEXTPROC glDeleteFramebuffersEXT
Dim Shared As PFNGLGENFRAMEBUFFERSEXTPROC glGenFramebuffersEXT
Dim Shared As PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC glCheckFramebufferStatusEXT
Dim Shared As PFNGLFRAMEBUFFERTEXTURE1DEXTPROC glFramebufferTexture1DEXT
Dim Shared As PFNGLFRAMEBUFFERTEXTURE2DEXTPROC glFramebufferTexture2DEXT
Dim Shared As PFNGLFRAMEBUFFERTEXTURE3DEXTPROC glFramebufferTexture3DEXT
Dim Shared As PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC glFramebufferRenderbufferEXT
Dim Shared As PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC glGetFramebufferAttachmentParameterivEXT
Dim Shared As PFNGLGENERATEMIPMAPEXTPROC glGenerateMipmapEXT
and here are the ones i use in the demo
glGenFramebuffersEXT( 1, @frameBuffer )
glGenRenderbuffersEXT( 1, @depthRenderBuffer )
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, depthRenderBuffer )
glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, FBWidth, FBHeight )
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, frameBuffer )
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT , GL_TEXTURE_2D , buffer , 0 )
glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT , GL_DEPTH_ATTACHMENT_EXT , GL_RENDERBUFFER_EXT , depthRenderBuffer )
< did you run it on vista or xp jim? cause i was thinking its mabey a bug in the vista opengl ati drivers>
-
Vista, but I would say it's far more likely there's a bug in your program - perhaps assuming some extension is supported - than there being a bug in the video driver.
Again, which extensions does it rely on - you know, the strings returned by glGetString(GL_EXTENSIONS)?
Jim
-
Runs fine here, radeon 9800pro probably not newest drivers
-
cheers paul good news that!
it very well could be a bug jim cause ive had to peice together all the info ive googled up.
The extension is EXT_framebuffer_object.
-
My driver reports that extension *is* supported, so it must be something else. I'll grab the code and have a look.
<edit>actually, can you post the source for the second one nino?
Jim
-
cheers jim!
-
You probably missed the edit - is it possible to post the source for this second demo?
Jim
-
oops sorry jim here you go.
its pretty much the same as the first except i use two textures and point the frame buffer ata diffrent one each pass.
-
Thanks!
I've tried and I can't get it to draw anything. The texture from the framebuffer's always black :(
http://www.opengl.org/registry/specs/EXT/framebuffer_object.txt (http://www.opengl.org/registry/specs/EXT/framebuffer_object.txt)
Sample 3 here does what we want (minus the stencil buffer). I went into your code and mostly copied it in - it should be correct, but it doesn't display anything, just a black cube.
<edit> If I run the same exe on another PC it works OK, so I'm guessing there's something boned in this setup. There's no errors reported at any step of the way, it just draws nothing.
Jim
-
Found this nice demo too. http://www.nvnews.net/vbulletin/showthread.php?t=49390 (http://www.nvnews.net/vbulletin/showthread.php?t=49390)
Also not working. There's no reason why this card won't render a 2yo demo like that. Something's broken.
Jim
-
thanks for trying to get it going jim.
its really weirdand i cant really think of any thing that would make it not run on your system other than possibly a slight driver bug for vista from amd.
btw thats a really cool demo in the link above and again it works fine in xp?
-
Just tested it (the first and second archives in this thread), unfortunately it crashed totally when trying to set up the screen;
Radeon X300 SE 128mb, Intel Pentium 4 3.0 GHZ, drivers are up to date I think.
It opened the console window wirst and then bombed out whilst opening the graphics screen, not even a black screen to report I am sorry!
-
nino, your code is a bit of a jumble. Can you change the startup code for this to look more like the sample 3 (minus the stencil stuff) from opengl.org?
If not I'll write a couple of very basic demos to show the technique.
Shockwave, nino's code doesn't check if GL_EXT_framebuffer_object is actually supported by your card. If it isn't it'll just jump off to some function in oblivion somewhere. I suspect that's why it's crashing.
Jim
-
yep no problem jim my first try is usually a mess as its just a quick test then i clean it all up after but for sure i will do mate!
im really sorry about your crash shockwave from now on ill put some error checking in to stop this in future :cheers:
-
right here we go it now has error checking and ive cleaned it up and got it as close to example 3 as i could the problem with making it exactly like example 3 is that i need to be able to repoint the frame between my two textures.
which brings me too would more of you guys like to test this for me i need to know how compatible it is there should be no more crashes.
#Include "GenioGL.Bi"
#Include "GL/GLext.bi"
CONST SWIDTH = 800
CONST SHEIGHT = 600
GenioGraphics( SWIDTH , SHEIGHT , 32 , WINDOWED )
'Type For The Extensions to get to the framebuffer
Type FrameBufferEXT
glIsRenderbufferEXT As PFNGLISRENDERBUFFEREXTPROC
glBindRenderbufferEXT As PFNGLBINDRENDERBUFFEREXTPROC
glDeleteRenderbuffersEXT As PFNGLDELETERENDERBUFFERSEXTPROC
glGenRenderbuffersEXT As PFNGLGENRENDERBUFFERSEXTPROC
glRenderbufferStorageEXT As PFNGLRENDERBUFFERSTORAGEEXTPROC
glGetRenderbufferParameterivEXT As PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC
glIsFramebufferEXT As PFNGLISFRAMEBUFFEREXTPROC
glBindFramebufferEXT As PFNGLBINDFRAMEBUFFEREXTPROC
glDeleteFramebuffersEXT As PFNGLDELETEFRAMEBUFFERSEXTPROC
glGenFramebuffersEXT As PFNGLGENFRAMEBUFFERSEXTPROC
glCheckFramebufferStatusEXT As PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC
glFramebufferTexture1DEXT As PFNGLFRAMEBUFFERTEXTURE1DEXTPROC
glFramebufferTexture2DEXT As PFNGLFRAMEBUFFERTEXTURE2DEXTPROC
glFramebufferTexture3DEXT As PFNGLFRAMEBUFFERTEXTURE3DEXTPROC
glFramebufferRenderbufferEXT As PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC
glGetFramebufferAttachmentParameterivEXT As PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC
glGenerateMipmapEXT As PFNGLGENERATEMIPMAPEXTPROC
frameBuffer As Gluint
depthRenderBuffer As GLuint
End Type
Type TexType
TWidth As Integer
THeight As Integer
Buffer As GLuint
End Type
Type KeyTracker
Key As Ubyte ptr
Esckey as Uinteger
Up As uinteger
Down As Uinteger
KLeft As Uinteger
KRight As Uinteger
Z As Uinteger
End Type
Declare sub GenioCheckKeys( Keys As KeyTracker )
Declare Sub GLInitFbuff( Fbuffer As FrameBufferEXT )
Declare Sub GLLockFbuff( Fbuffer As FrameBufferEXT , Tex As TexType )
Declare Sub UnlockFBuff( Fbuffer As FrameBufferEXT )
Declare Sub Dellet_Demo()
Declare Sub SetUpBlankTexture( Tex As TexType , Byval TWidth As Integer , Byval THeight As Integer )
Declare Function CheckFrameBufferStatus( Fbuffer As FrameBufferEXT ) As Integer
Dim Shared As KeyTracker Key
Dim Shared As FrameBufferEXT GLCapture
Dim Shared As TexType Texture1, Texture2
SetUpBlankTexture( Texture1 , 512 , 512 )
SetUpBlankTexture( Texture2 , 512 , 512 )
dim shared light as Geniolight
Dim Shared Camera As GenioEntity PTR
Dim Shared TexCube As GenioEntity PTR
Dim Shared TexCube1 As GenioEntity PTR
Dim Shared Cube As GenioEntity PTR
GLInitFbuff( GLCapture )
CreateLightEntity( light , GENIOLIGHT0 , 1.0 , 2.0 , -2.0 )
Camera = SetUpCamera()
TexCube = Cube_Mesh(LightMapOn)
TexCube1 = Cube_Mesh(LightMapOn)
Cube = Cube_Mesh(LightMapOn)
scale_entity( TexCube , 1 , 1 , 1 )
Set_Entity_Position( TexCube , 0 , 0 , -5 )
scale_entity( TexCube1 , 1 , 1 , 1 )
Set_Entity_Position( TexCube1 , 0 , 0 , -5 )
scale_entity( Cube , 1 , 1 , 1 )
Set_Entity_Position( Cube , 0 , 0 , -5 )
Do
GenioCheckKeys( Key )
GLLockFBuff( GLCapture , Texture1 )
glClearColor( 1.0f, 0.0f, 0.5f, 1.0f )
GenioClear()
SetEntity_Rgb( TexCube , 255 , 255 , 0 )
Rotate_Entity( TexCube , 0.1 , 0.4 , 1 )
DrawEntity( TexCube )
unLockFBuff( GLCapture )
GLLockFBuff( GLCapture , Texture2 )
glClearColor( 0.0f, 0.0f, 0.5f, 1.0f )
GenioClear()
SetEntity_Rgb( TexCube1 , 255 , 255 , 0 )
Rotate_Entity( TexCube1 , 0.1 , 0.4 , 1 )
DrawEntity( TexCube1 , Texture1.Buffer )
unLockFBuff( GLCapture )
glClearColor( 0.0f, 0.0f, 1.0f, 1.0f )
GenioClear()
Rotate_Entity( Cube , 0.1 , 0.2 , -0.02 )
DrawEntity( Cube , Texture2.Buffer )
GenioRender( Camera )
loop until( inkey$ = chr$( 27 ) )
Dellet_Demo()
End
Sub Dellet_Demo()
DeleteCamera( Camera )
DestroyEntity( Cube )
DestroyEntity( TexCube )
DestroyEntity( TexCube1 )
End Sub
sub GenioCheckKeys( Keys As KeyTracker )
Keys.Up = multikey( SC_UP )
Keys.Down = multikey( SC_DOWN )
Keys.KLeft = multikey( SC_LEFT )
Keys.KRight = multikey( SC_RIGHT )
Keys.Z = multikey( SC_Z )
end sub
Sub GLInitFbuff( Fbuffer As FrameBufferEXT )
dim extensions as string
extensions = *glGetString(GL_EXTENSIONS)
If strstr( extensions , ( "GL_EXT_framebuffer_object" ) ) > 0 Then
Fbuffer.glIsRenderbufferEXT = Cast( PFNGLISRENDERBUFFEREXTPROC , wglGetProcAddress("glIsRenderbufferEXT") )
Fbuffer.glBindRenderbufferEXT = Cast( PFNGLBINDRENDERBUFFEREXTPROC , wglGetProcAddress("glBindRenderbufferEXT") )
Fbuffer.glDeleteRenderbuffersEXT = Cast( PFNGLDELETERENDERBUFFERSEXTPROC , wglGetProcAddress("glDeleteRenderbuffersEXT") )
Fbuffer.glGenRenderbuffersEXT = Cast( PFNGLGENRENDERBUFFERSEXTPROC , wglGetProcAddress("glGenRenderbuffersEXT") )
Fbuffer.glRenderbufferStorageEXT = Cast( PFNGLRENDERBUFFERSTORAGEEXTPROC , wglGetProcAddress("glRenderbufferStorageEXT") )
Fbuffer.glGetRenderbufferParameterivEXT = Cast( PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC , wglGetProcAddress("glGetRenderbufferParameterivEXT") )
Fbuffer.glIsFramebufferEXT = Cast( PFNGLISFRAMEBUFFEREXTPROC , wglGetProcAddress("glIsFramebufferEXT") )
Fbuffer.glBindFramebufferEXT = Cast( PFNGLBINDFRAMEBUFFEREXTPROC , wglGetProcAddress("glBindFramebufferEXT") )
Fbuffer.glDeleteFramebuffersEXT = Cast( PFNGLDELETEFRAMEBUFFERSEXTPROC , wglGetProcAddress("glDeleteFramebuffersEXT") )
Fbuffer.glGenFramebuffersEXT = Cast( PFNGLGENFRAMEBUFFERSEXTPROC , wglGetProcAddress("glGenFramebuffersEXT") )
Fbuffer.glCheckFramebufferStatusEXT = Cast( PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC , wglGetProcAddress("glCheckFramebufferStatusEXT") )
Fbuffer.glFramebufferTexture1DEXT = Cast( PFNGLFRAMEBUFFERTEXTURE1DEXTPROC , wglGetProcAddress("glFramebufferTexture1DEXT") )
Fbuffer.glFramebufferTexture2DEXT = Cast( PFNGLFRAMEBUFFERTEXTURE2DEXTPROC , wglGetProcAddress("glFramebufferTexture2DEXT") )
Fbuffer.glFramebufferTexture3DEXT = Cast( PFNGLFRAMEBUFFERTEXTURE3DEXTPROC , wglGetProcAddress("glFramebufferTexture3DEXT") )
Fbuffer.glFramebufferRenderbufferEXT = Cast( PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC , wglGetProcAddress("glFramebufferRenderbufferEXT") )
Fbuffer.glGetFramebufferAttachmentParameterivEXT = Cast( PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC , wglGetProcAddress("glGetFramebufferAttachmentParameterivEXT") )
Fbuffer.glGenerateMipmapEXT = Cast( PFNGLGENERATEMIPMAPEXTPROC , wglGetProcAddress("glGenerateMipmapEXT") )
Else
MessageBox (0, 0,"Sorry your hardware does not support the extension", MB_OK or MB_ICONINFORMATION)
End
End If
FBuffer.glGenFramebuffersEXT( 1, @FBuffer.frameBuffer )
FBuffer.glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, Fbuffer.frameBuffer )
FBuffer.glGenRenderbuffersEXT( 1, @FBuffer.depthRenderBuffer )
FBuffer.glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, FBuffer.depthRenderBuffer )
FBuffer.glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, 512 , 512 )
FBuffer.glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT , GL_DEPTH_ATTACHMENT_EXT , GL_RENDERBUFFER_EXT, FBuffer.depthRenderBuffer )
End Sub
Sub SetUpBlankTexture( Tex As TexType , Byval TWidth As Integer , Byval THeight As Integer )
glGenTextures( 1, @Tex.Buffer )
glBindTexture( GL_TEXTURE_2D, Tex.Buffer )
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, TWidth , THeight, 0, GL_RGB, GL_UNSIGNED_BYTE, 0 )
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR )
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR )
Tex.TWidth = TWidth
Tex.THeight = THeight
End Sub
Sub GLLockFbuff( Fbuffer As FrameBufferEXT , Tex As TexType )
Dim As Gluint Status
glViewport( 0, 0, Tex.TWidth , Tex.THeight )
glBindTexture(GL_TEXTURE_2D, 0)
FBuffer.glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, Fbuffer.frameBuffer )
FBuffer.glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT , GL_COLOR_ATTACHMENT0_EXT , GL_TEXTURE_2D , Tex.buffer , 0 )
'check to see if the framebuffer is ok
Status = CheckFrameBufferStatus( Fbuffer )
If Status = 0 then
MessageBox ( 0,0, "FrameBuffer Error", MB_OK or MB_ICONINFORMATION )
Dellet_Demo()
End
EndIf
If Status = 2 then
MessageBox ( 0,0, "Need A Diffrent Format", MB_OK or MB_ICONINFORMATION )
Dellet_Demo()
End
EndIf
' Every thing Must Have Went to plan
End Sub
Function CheckFrameBufferStatus( Fbuffer As FrameBufferEXT ) As Integer
Dim as GLenum status
status = Fbuffer.glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT )
If Status = GL_FRAMEBUFFER_COMPLETE_EXT then
'Every Thing is fine
Return (1)
ElseIf Status = GL_FRAMEBUFFER_UNSUPPORTED_EXT then
'need to choose a diffrent format
Return (2)
Else
'error will fail on hardware
Return(0)
EndIf
End Function
Sub UnlockFBuff( Fbuffer As FrameBufferEXT )
Fbuffer.glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 )
glViewport( 0 , 0 , SWIDTH , SHEIGHT )
End Sub
btw shockwave would you mind retring this for me and telling me what message you get mate.
cheers.
-
Black screen opens and is immediately followed by an error message ...
"Sorry you hardware does not support the extension"
My system specs ...
Celeron D 345 @ 3.3GHz
Intel integrated graphics processor
So its not supported here.
-
thank you for testing rain it really is helpfull to know what this will and will not run on cheers.
i may have to go for pbuffers in the end for a bit of compatibility.
-
Thanks nino, that's much better :) I still just get the black cube...
Jim
-
dang it,
i was hopeing youd mabey get "Need A Diffrent Format" or something just so we could work out whats going on...
-
Checked all that, and glGetError returns GL_NOERROR too.
I tried it on my Quadro FX1400 and my GeForce MX and it works OK.
Jim
-
if its supported in the mx line it *should* be fairly compatible.
does pbuffer stuff run on your x1600 jim? cause im thinking it might be the most compatible route as i dont want to make demos that only a few people can veiw.
-
does pbuffer stuff run on your x1600 jim?
I don't know :)
Jim
-
I rechecked this on my Vista X1600 and it's working fast and well now, so it was a driver problem. I also checked it on my Vista 8600GT and it runs, but about 1/10th the speed of the ATI. Not sure whether that's just because it's crap running in a window on nVidia, or what.
Jim
-
great! and thanks for the updated info jim.
its weird it works faster on your ati board, would you like a fullscreen version to test?
-
I'm going to do some experiments of my own, including a comparison with pbuffers :)
Jim
-
cool..could you keep the forum updated on your findings jim,
i really like fbo's for simplicity but until they are a bit more on the stable side i think ill use pbuffers.
-
FORGET PBuffers!!!!
they are buggy, not very advanced in terms of what you can do with them and VERY VERY SLOW!!!
FBOs are the way to go: clean, fast, etc
-
I implemented both, you get a FBO if your card supports them (you're right, they're great, but we had terrible problems with early Vista drivers), and if not, you get a pbuffer. If it works, it works, if it breaks, tough!
Jim
-
Jim, FBOs work really fine, the problem is that almost all the drivers for Vista are not that stable yet... but that's really the way to go....
-
Nino (and gang!)
It works great on my sony vaio laptop (nVidia GeForce 8400M GT) - smooth as a silk dude!
Nice work!
Drew