@motorcycleboy wrote:
Hey,
I am trying to work out exactly how ofxFX works so I can recreate some of the ideas and use them in other projects.
I am finding it difficult to understand what this code in ofxFXObject.h does:
// Constructor Shader Source Strings: These strings can be specified // by inheritors in their constructors, and will be loaded when // appropriate. If any of the above strings are empty, the ones // below are tried. If shaders are loaded from file, these are also // ignored. string glESFragmentShader; string glESVertexShader; string gl2FragmentShader; string gl2VertexShader;
I can see that from this code in the selectShaderSource() function, that if we are not using the programmable renderer and a vertex shader is not specified then vertexShader is assigned the string gl2VertexShader:
if (ofIsGLProgrammableRenderer()){ vertexShader = gl3VertexShader; // If the vertex shader for GL3 isn't specified, we fill // in a simple pass-through shader. This way, users can // give only fragment shaders, just like for GL2/ES. This // is necessary because having a vertex shader is mandatory // in GL3. if (vertexShader.empty()){ vertexShader = "#version 150\n"; vertexShader += STRINGIFY( uniform mat4 modelViewProjectionMatrix; in vec4 position; void main(){ gl_Position = modelViewProjectionMatrix * position; }); } } else { vertexShader = gl2VertexShader; }
Then when compileCode() is called the vertex shader is loaded as follows:
shader.setupShaderFromSource(GL_VERTEX_SHADER, vertexShader);
As far as I can see gl2VertexShader is never assigned anything in ofxFXObject.cpp so this is the same as passing in an empty string.
However, if I pass in an empty string when attempting to recreate this in one of my own projects I get the following error:
ERROR: Compiled vertex shader was corrupt
I have tried to use a very simple vertex shader instead, i.e.
void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
But then the output is not the same as what I am seeing with the ofxFX examples.
Posts: 1
Participants: 1