Reputation: 11597
Im trying to make an app that simulates dice rolls, at the moment everything works fine. Im trying to add a shader for when the user selects a dice, it will put an outline around the selected dice. How im going about this is to render the particular dice scaled up slightly and completely black, then draw the textured dice on top of it to make it look like it has an outline.
The problem im having is that when the shader for drawing the object black is first applied, it draws the black dice fine, but when the textured dice is trying to be drawn over it, it draws it in the wrong place, and draws the wrong dice. The odd thing is it draws it inside one of the other dice on the screen.
If I apply the the same shader to the object twice, everything draws how its supposed to for that particular shader (either all black because of the outline shader or all textured and lit from the normal shader), but when I apply both shaders to the same model, things go wrong.
This class loads the vertices and stuff, and draws the object: http://pastebin.com/N5aYAtBC
This class manages the shaders: http://pastebin.com/0bT7ABRu
I've left out a lot of code that I feel will have nothing to do with the problem, but if you need more just leave a comment
and when i click on different dice this is what happens (first pic is normal): https://i.sstatic.net/OWImo.jpg
Upvotes: 0
Views: 970
Reputation: 35943
glUniformMatrix4fv(toon_mvp, 1, 0, modelViewProjectionMatrix.m);
glUniform4fv(toon_outline, 1, oc);
glUseProgram(Toon);
I think you're handling the uniforms wrong. I pulled out this snippet from your source as an example.
When you upload a uniform, it only effects the currently bound program (each program has it's own internal storage of uniforms).
If you're expecting 'toon_mvp' and 'toon_outline' to be available to the program 'Toon', they will not be. You need to first bind the program you want to modify, and then modify it's uniforms after it is bound, not in the other order.
You'll probably have to fix this in other places in your code as well.
Upvotes: 4