OpenGL shader examples
OpenGL shader examples
Hi all. I've made a couple of OpenGL shader examples. One is a simple triangle on the screen example. The other is 3D and uses a maths library I've been building (also included). I've put comments and labels everywhere to try and explain everything. I don't think I've used any depreciated OpenGL functions (I tried not too).
One thing I should mention is that the examples required OpenGL 2.0 or above. I know some on the forum are running older hardware so its worth mentioning.
Anyway, here's the download link, http://www.mediafire.com/file/wlrwrro93 ... Shader.zip
Also, this is a webpage that I found very useful. It has a really good explanation of everything shaders, and its also up to date. When I was searching for shader info and examples most of what I could find was useful, but out of data (used depreciated function, etc). http://duriansoftware.com/joe/An-intro- ... tents.html
One thing I should mention is that the examples required OpenGL 2.0 or above. I know some on the forum are running older hardware so its worth mentioning.
Anyway, here's the download link, http://www.mediafire.com/file/wlrwrro93 ... Shader.zip
Also, this is a webpage that I found very useful. It has a really good explanation of everything shaders, and its also up to date. When I was searching for shader info and examples most of what I could find was useful, but out of data (used depreciated function, etc). http://duriansoftware.com/joe/An-intro- ... tents.html
Last edited by pestery on Nov 07, 2011 11:26, edited 4 times in total.
Great to see some newer OpenGL examples. Extra points for using VBOs and going beyond the old OpenGL 2.0 and using GLSL from OpenGL 3.1 (note for people with 2.0 only: see the readme).
EDIT: Examples run fine on Linux, but I needed to add a definition of NULL to shader.bi:
EDIT: Examples run fine on Linux, but I needed to add a definition of NULL to shader.bi:
Code: Select all
#Ifndef NULL
#Define NULL 0
#EndIf
-
- Posts: 148
- Joined: Nov 12, 2007 11:46
- Location: Russia
Damn good Pestery!
or incode constantAave wrote: EDIT: Examples run fine on Linux, but I needed to add a definition of NULL to shader.bi:
Code: Select all
const NULL = 0
-
- Posts: 206
- Joined: Aug 27, 2005 2:02
- Location: Istanbul, Turkey
Thanks for the examples. They are very useful.
There is something wrong with test3 though. It gives this when I try to compile.
I'm on Archlinux. The other examples compile and run fine.
Thanks again.
Anil
There is something wrong with test3 though. It gives this when I try to compile.
Code: Select all
/usr/include/freebasic/crt/sys/linux/types.bi(96) error 4: Duplicated definition in 'type int64_t as integer'
Thanks again.
Anil
-
- Posts: 148
- Joined: Nov 12, 2007 11:46
- Location: Russia
Hi Anil. I've fixed the bug so it should work now. The bug was actually in my OpenGL headers, which I guess your using :-)
I've updated the download link in the other post. Thanks for letting me know.
http://www.freebasic.net/forum/viewtopi ... highlight=
I've updated the download link in the other post. Thanks for letting me know.
http://www.freebasic.net/forum/viewtopi ... highlight=
-
- Posts: 206
- Joined: Aug 27, 2005 2:02
- Location: Istanbul, Turkey
Hi all. Back again with another update of the examples.
I noticed a bug in my maths library that I'd bundled with the shader examples. I've tested this new version a lot and I'm pretty sure its bug free. Its also a lot longer because I've added a heap on new datatypes, functions and operators.
If anyone is using the bundled API files for FbEdit then I've updated those too. I added some stuff for framebuffer object functions. Also made a couple of small changes to the existing examples to make them automatically select the shader files.
Lastly, I've added a forth example which has a nice glow effect. The example also uses framebuffer objects as well, though because they are only available in GL 3.0 there are also fallback commands in the example. I've tested it and it runs fine on both GL 2.1 and GL 4.2.
Enjoy :-)
I noticed a bug in my maths library that I'd bundled with the shader examples. I've tested this new version a lot and I'm pretty sure its bug free. Its also a lot longer because I've added a heap on new datatypes, functions and operators.
If anyone is using the bundled API files for FbEdit then I've updated those too. I added some stuff for framebuffer object functions. Also made a couple of small changes to the existing examples to make them automatically select the shader files.
Lastly, I've added a forth example which has a nice glow effect. The example also uses framebuffer objects as well, though because they are only available in GL 3.0 there are also fallback commands in the example. I've tested it and it runs fine on both GL 2.1 and GL 4.2.
Enjoy :-)
I get compile error form all tests:
If I hard code that into an arbitrary value, I can build and run tests 1-3. However test 4 gives:
One other thing, it would be nice if you could name the bas and dir differently, e.g. test1.bas and test1-data. This is because on linux, exes don't generally have any suffix (.exe), so if I command: fbc test1.bas, it won't work as it tries to create and exe named 'test1' but there's already a directory by that name. Of course I can work around this with fbc test1.bas -x test1exe, but it's slightly annoying.
Code: Select all
OpenGL_Shader/inc/shader.bi(282) error 41: Variable not declared, GL_MAX_COLOR_ATTACHMENTS in 'glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, @opengl_info.fbo_attach)'
Code: Select all
test4.bas(496) error 41: Variable not declared, GL_RENDERBUFFER in 'glBindRenderbuffer(GL_RENDERBUFFER, .fbo_depth)'
test4.bas(502) error 41: Variable not declared, GL_FRAMEBUFFER in 'glBindFramebuffer(GL_FRAMEBUFFER, .fbo)'
test4.bas(506) error 41: Variable not declared, GL_COLOR_ATTACHMENT0 in 'glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, .texture[i], 0)'
test4.bas(510) error 41: Variable not declared, GL_DEPTH_ATTACHMENT in 'glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, .fbo_depth)'
test4.bas(514) error 41: Variable not declared, GL_FRAMEBUFFER_COMPLETE in 'If check <> GL_FRAMEBUFFER_COMPLETE Then'
test4.bas(598) error 41: Variable not declared, GL_COLOR_ATTACHMENT1 in 'Dim As GLenum drawbuf(0 To 1) = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1}'
test4.bas(696) error 41: Variable not declared, GL_COLOR_ATTACHMENT2 in 'glDrawBuffer GL_COLOR_ATTACHMENT2'
Thanks for letting me know Aave. I've fixed up the folder names to make it easier on Linux. I've also added a bit to make sure those constants get defined if they are not present. I think I got them all :-)
Regarding the constants not being defined, you might want to get the updated version of glext.bi that I did a while ago. Using it should stop any other problems with things not being defined. http://www.freebasic.net/forum/viewtopi ... highlight=
Regarding the constants not being defined, you might want to get the updated version of glext.bi that I did a while ago. Using it should stop any other problems with things not being defined. http://www.freebasic.net/forum/viewtopi ... highlight=
Not quite :Ppestery wrote:I've also added a bit to make sure those constants get defined if they are not present. I think I got them all :-)
Code: Select all
test4.bas(510) error 41: Variable not declared, GL_DEPTH_ATTACHMENT in 'glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, .fbo_depth)'
test4.bas(514) error 41: Variable not declared, GL_FRAMEBUFFER_COMPLETE in 'If check <> GL_FRAMEBUFFER_COMPLETE Then'