Two Shaders on two objects

I created two shaders. I want one on one object and one on the other. Can ofShader do this? I always get the last shader compiled for everything. Currently the classes are in display list to draw them. I am probably missing something obvious.

Do I need FBOs?

no, why would you need FBOs?

You simply do it like this:


ok, it works but the program crashes constantly. If I have one shader it runs perfectly the second I add another shader and try to draw another object the program crashes.

Could it be something with the pointer in ofShader?

The fastest way to find out where and why it’s crashing is to use the debugger. If you’re on OSX, simply choose debug instead of run (with the Debug target selected). There’s a similar command for visual studio on windows and Code blocks on Linux.

When the program crashes, the debugger should show you exactly where things are tripping up. If not, set a breakpoint just before the shader binding and step through your code until it does crash.

All I get is a “EXC_BAD_ACCESS” from the debugger

I tracked down where the error is occurring.

When I press ‘1’ I should create a new “atom” class object.

void testApp::keyPressed (int key){
if (key == ‘1’){
atomArray[numAtoms] = new Atom(0,0,0,“brick”);

This works fine if I only use one shader but the second I use two the program crashes.
The problem seems to be linked with these lines of code in the .h file.

ofShader tempAtom;
ofShader tempTri;

If I remove one it works but I cannot have both.

Well… I solved my problem

I forgot to add the array initialization back into the program when I made the second version.

atomArray = new Atom*[numAtoms];