ofMaterial and OpenGL


Hey everyone,

I have recently been learning to program shaders in OpenGL. Normally to use custom shaders with openFrameworks I change main.cpp from this:

ofSetupOpenGL(1024, 768, OF_WINDOW);            // <-------- setup the GL context

// this kicks off the running of my app
// pass in width and height too:
ofRunApp(new ofApp()); 

To this:

ofGLWindowSettings settings;
settings.setSize(1200, 800);
settings.setGLVersion(3, 2);    
ofRunApp(new ofApp());

This is the first time I’ve used custom shaders in a project that is also using ofMaterial. I’ve noticed that after switching to GL version 3.2, all the places in my scene where I am using an instance ofMaterial are no longer working properly. Is this expected behaviour and do I now need to write custom shaders to create my own ofMaterial?

Any help would be appreciated!


It should still work. You have to set up the light and a camera properly. Have a look into examples/3d/ofNodeExample


if you mean combining ofShader with ofMaterial, no it won’t work right away cause ofMaterial uses shaders when using opengl 3+ internally and you can’t use more than one shader simultaneously.

ofMaterial can be setup using ofMaterialSettings and there add a postFragment with shader code that will be run after the lighting and reflectance calculations. There’s more information in the docs: https://openframeworks.cc/documentation/gl/ofMaterialSettings/


Hey Arturo,

Thanks for your reply. I had seen from your other forum posts that combining ofShader and ofMaterial won’t work.

That’s interesting about the postFragment shader code. I will definitely look into that at some point.

However, my problem is simply that when I switch to settings.GLVersion(3, 2) that some of the materials in my scene stop behaving as they should.

What confuses me is that some of the materials work as before, for example, the legs of my table and the wall. However, the material I was using for the window, the table top, the silver lamp and the glass lamp, which was transparent, all no longer work as before.

I have attached two screenshots. I can also show you some code as well but the only difference between the two apps are the setup I’ve done in main().

p.s. It’s saying new users can only upload one image in a post. Will post the image of the working project first.



Hey edapx,

I had a look at the example. Some handy things in there about ofNode that I hadn’t seen before. I changed my code so it setups the lighting identically to the example but the same issue persists.


This looks like a bug with transparency, can you open an issue on github?


Ok sure, I will do. One thing to note is that it isn’t just happening with transparent objects. The glass for the window isn’t actually transparent at the moment but ofMaterial isn’t working properly for that either.


A further update on this:

I realised that asides from the alpha problem, which I have now raised as an issue on github (https://github.com/openframeworks/openFrameworks/issues/6272), the common link between the other cases where ofMaterial isn’t working properly is when I am using ofMesh.

The window was drawn with a mesh and also the parts of the table that aren’t being shown properly take a mesh from parts of a cylinder primitive.

ofMesh side = table_top.getCylinderMesh();

The silver lamp didn’t have a material attached to it, which is why it was just white.


So the reason the meshes were not working is that for some reason when using the programmable renderer, if you are taking the mesh from a primitive you have to also use enableNormals().

ofMesh side = table_top.getCylinderMesh();