Upgrading shaders in ofxFluid

Hi guys,

I am tryng to upgrade ofxFluid from glsl version 120 to 150 because my app needs OpenGL versione 3.2. The shaders are quite simple but I am not expert and probably I made some error in transaltion… the result, in fact, is a black screen (no errors on console). here is the first one, very similar to the others. If someone see any error I will appreciate any feedback, thanks!

GLSL 120

uniform sampler2DRect tex0; // Real obstacles
uniform sampler2DRect backbuffer;
uniform sampler2DRect VelocityTexture;

uniform float TimeStep;
uniform float Dissipation;

void main(){

vec2 st = gl_TexCoord[0].st;

float solid = texture2DRect(tex0, st).r;

if (solid > 0.1) {
    gl_FragColor = vec4(0.0,0.0,0.0,0.0);

vec2 u = texture2DRect(VelocityTexture, st).rg;
vec2 coord =  st - TimeStep * u;

gl_FragColor = Dissipation * texture2DRect(backbuffer, coord);


GLSL 150

#version 150 core

uniform sampler2DRect tex0; // Real obstacles
uniform sampler2DRect backbuffer;
uniform sampler2DRect VelocityTexture;

uniform float TimeStep;
uniform float Dissipation;

out vec4 FragColor;

void main(){

vec2 st = gl_FragCoord.xy;

float solid = texture(tex0, st).r;

if (solid > 0.1) {
    FragColor = vec4(0.0, 0.0, 0.0, 0.0);

vec2 u = texture(VelocityTexture, st).rg;
vec2 coord = st - TimeStep * u;

FragColor = Dissipation * texture(backbuffer, coord);


1 Like

Hey @Paolo , this shader code looks pretty good to me. I haven’t found any errors yet. One thing to remember is that #version 150 in the shaders corresponds with openGL version 3.2. So don’t forget to set the openGL version in main.cpp:

int main() {
    ofGLFWWindowSettings settings;
    settings.setGLVersion(3, 2);
    settings.setSize(1920, 1080);

    auto window = ofCreateWindow(settings);
    ofRunApp(window, make_shared<ofApp>());

Thanks @TimChi, I had already done that.

I removed all but one shader from ofxFluid and verified that something appeared on the screen in version 120. Once I verified that the pipeline was working, I changed the openGL setting from 2.1 to 3.2 and loaded version 150 of the same shader. I did this to minimize the lines of code where to look for the error.

On version 150 I no longer see anything, but if I add ofDrawRectangle(…) between shader.begin() and shader.end() the app crashes and Mac Os Ventura on console reports “FALLBACK (log once): Fallback to SW vertex processing, m_disable_code: 10”.

the next test will be to run the same code on Windows 10 and try to see if the problem is due to OpenGL on Mac. Actually the 01_simpleColorQuad example from OpenFrameworks works correctly even with OpenGL 3.2, so there should be no problem with ofxFluid with shader version 150 on MacOS Ventura.

Anyway the only one working shader now is:

#version 150

uniform vec2 Point;
uniform float Radius;
uniform vec3 Value;

out vec4 FragColor;

void main(){

float d = distance(Point, gl_FragCoord.xy);
if (d < Radius) {
    float a = (Radius - d) * 0.5;
    a = min(a, 1.0);
    FragColor = vec4(Value, a);
} else {
    FragColor = vec4(0);

FragColor = vec4(1.0, 1.0, 1.0, 1.0);


thanks to everybody for any help!

1 Like

Hey one more quick thought. Have the vertex shaders been modified (or added) for openGL 3.2? The OF examples in /shader have both openGL 2.1 and 3.2, and the vertex shaders are different between the two versions. I had a quick look at ofxFluid.cpp and didn’t see where the vertex shader(s) were setup from source like the fragment shaders are.

The OF projects from /examples/shader for openGL 3.2 should definitely run on macOS.

Yes, I added. I removed almost anything from ofxFluid and I found that the issues is in the way the quad is drawn.

On /examples/shader for openGL 3.2 the quad is drawn by:

ofDrawRectangle(0, 0, width, height);

in ofxFluid is drawn by:

glTexCoord2f(0, 0); glVertex3f(0, 0, 0);

on Windows, if I draw the quad by ofDrawRectangle it works but I have to flip coords. On Mac I still have the Fallback issue. I’ve just removed dependency from ofxFX and the bug, now, has to be found in less than 100 lines of code. I hope to catch it soon.

Thanks for your help!

Found it…


shader.setupShaderFromFile(GL_FRAGMENT_SHADER, "shader.frag");



I’ve also created the passthrough shader. In ofxFluid it was created via code in ofxFXObject

As soon as I’ll have a version of ofxFluid for OpenGL 3.2 I’ll make a post