shaders?

Hi there,

Looking forward to working with openFrameworks! Just wondering if it’s possible to use GLSL shaders with openframeworks? Are there any simple examples on this topic?

Thanks!
m.

(I’ve moved this to advanced…)

hi,

nice to have you with us!

we don’t have examples about glsl, but from my understanding it shouldn’t be too hard, especially that we are now using GLEE for getting different extensions to load. We will take a look at what’s involved to get a shader in…

take care
zach

Thanks Zach!

Yeah if there was a simple example to show how to hook up a very simple shader (your typical ultra simple setting the color of a primitive to red for example), that would be great. It would be cool to work with shaders within the openFrameworks framework. Guess that was redundant, huh. =)

Thanks.
m.

ok good news,

I tested a very simple example from

http://www.lighthouse3d.com/opengl/glsl

and it seems to work just fine with GLEE to check about the chance to run shaders … we will need to clean it up, and likely add some functionality to load the shader programs from text files, but it seems to work pretty well. I have almost no knowledge of glsl, but was able make the vertices of an object shake with some random displacement, and that gave me a big smile…

more soon,
zach

here’s an early snapshot of “ofShader” which is an addon we are going to add to the site shortly:

openFrameworks.cc/files/ofShader_test.zip

it includes the code ofShader.cpp / ofShader.h as well as a very simple shader that modifies vertexs and color, and a testApp that runs the shader. Press any key to turn on or off the shader. The shader makes everything red (as you suggested) and alters the vertices based on mouse position.

you need to put both shaders (color.vert / color.frag) with the bin / exe of the app (like fonts/images/etc)

If you alter the code and it doesn’t compile, it should print out to the console what the issue is. You can also google around about GLSL tweaks, somethings you might be used to programming wise might not be possible.

If your card doesn’t support shaders, you wont see anything — it should run fine, but I need to check it. We are using GLEE to test for shader GLSL support.

I don’t have a lot of experience with shaders, so all feedback, issues, etc are really appreciated !!

take care!
zach

Hi,

I’m trying to compile the example ofShader_test and I get an error in ofShader.cpp line 23:
“vertexShader = glCreateShader(GL_VERTEX_SHADER);”

the first error:
ofShader.cpp:23: error: invalid conversion from ‘GLuint’ to ‘void*’

I’m running MAC with xcode. Do you thing that’s the problem?

(I’d imported all the staff with “Relative to project” option. Is that ok?)
THANKS!
j

doh’ ! my bad - theo sent me fixes for mac

can you try this code (changes are only to ofShader.cpp):

www.openframeworks.cc/files/ofShader-test2.zip

take care,
zach

(sorry moved again, now to extend, since ofShader will be an addon… seemed appropriate)

Wow!

Thanks for your quick response. Now it’s working fine in mac! So cool, so great!
I want to write lumakey and cromakey shader, but am new in this language, so… I will try…

Thanks again!
j

_I seem to be missing a lib??

/…/…/libs/openCV/lib) does not exist_

*Thump* … hitting my head! Doh! Read first - type later!

I tried to compile ofShader … installing open CV

ofshader is here:

www.openframeworks.cc/files/ofShader-test2.zip

there aren’t instructions yet, because we are still testing —

to test, just replace the source of your app with the source (main, testApp h/cpp, ofShader h/cpp). you will likely need to add ofShader.h and ofshader.cpp to the project, whatever IDE you are on.

the two shader components (.frag / .vert) need to be in the bin folder (edit, or for mac, follow the ‘add to xcode’ part of the mac setup guide)

you will need a GLSL compatible card – there are plenty of apps (mac/pc) that output opengl specs for your card if your not sure. The general rule is that if you have an ATI or Nvidia from the last year or two you are ok, and if you have an integrated graphics (ie, intel laptop, etc) you probably don’t have glsl support. If you don’t have glsl support ofShader should print something in the console, but you wont see any effect.

hope that helps !
zach

yes im sure it will . im on a spanking new MacBook Pro 2.2

I got the stuff where it needs to be! I’ll just install the CV

hmm i might be stupid but i did a copy of another of-app and then replaced the source files - did a clean all and then started building … i get a undefined:

  
/usr/bin/ld: Undefined symbols:  
ofShader::loadShader(char*)  
ofShader::setShaderActive(bool)  
ofShader::setUniformVariable(char*, float)  
/Users/fh/Kod/of_preRelease_v0.02_xcode/app/glShadersExample/build/openFrameworks.build/Release/openFrameworks.build/Objects-normal/ppc/testApp.o reference to undefined ofShader::loadShader(char*)  
/Users/fh/Kod/of_preRelease_v0.02_xcode/app/glShadersExample/build/openFrameworks.build/Release/openFrameworks.build/Objects-normal/ppc/testApp.o reference to undefined ofShader::setShaderActive(bool)  
/Users/fh/Kod/of_preRelease_v0.02_xcode/app/glShadersExample/build/openFrameworks.build/Release/openFrameworks.build/Objects-normal/ppc/testApp.o reference to undefined ofShader::setUniformVariable(char*, float)  
collect2: ld returned 1 exit status  

I haven’t done any cpp programming on macs before so xcode is all new to me … mostly visual studio stuff and old commandline c stuff on linux/unix so it’s probl. just me beeing stupid …

yep . it was me beeing stupid . added the rest of the files . and it worked like a charm! thanks so much. This lib kicks ass …

/fredrik

hi OF

i installed and tested succesfully the shader addon programs :stuck_out_tongue_winking_eye: OF 0.02 in DEV-C++ compiler.

even my laptops graphic card is arround 4 years old it works fine :wink: !! yupiiii

Hi ZACH :slight_smile:

ofshader is here:

www.openframeworks.cc/files/ofShader-test2.zip

there aren’t instructions yet, because we are still testing —

to test, just replace the source of your app with the source (main, testApp h/cpp, ofShader h/cpp). you will likely need to add ofShader.h and ofshader.cpp to the project, whatever IDE you are on.

the two shader components (.frag / .vert) need to be in the bin folder (edit, or for mac, follow the ‘add to xcode’ part of the mac setup guide)

you will need a GLSL compatible card – there are plenty of apps (mac/pc) that output opengl specs for your card if your not sure. The general rule is that if you have an ATI or Nvidia from the last year or two you are ok, and if you have an integrated graphics (ie, intel laptop, etc) you probably don’t have glsl support. If you don’t have glsl support ofShader should print something in the console, but you wont see any effect.

When I try to run the ofShader example on my laptop I get the following message:

  
vertexShader reports: Vertex shader was successfully compiled to run on hardware  

which sounds good to me. But nothing happens when I press a key or move the mouse.

I only see three primitives in different colors.

When try I the following example there are no problems: http://www.clockworkcoders.com/oglsl/noise-demo.zip

Any idea?