Hi everybody, I’m trying to go through this tutorial applying it to iOS but I’m blocked at the first example:
http://openframeworks.cc/tutorials/graphics/shaders.html
Here’s my code from main.mm:
ofSetCurrentRenderer(ofGLProgrammableRenderer::TYPE);
ofSetupOpenGL( 1024, 768, OF_FULLSCREEN ); // <-------- setup the GL context
ofRunApp( new ofApp() );
And here’s the setup function from ofApp.mm:
shader.load( "tutorial.vs", "tutorial.fs" ); xRes = 768; yRes = 1024; ofSetFrameRate( 60 );
And this is the draw function from ofApp.mm:
ofSetColor( ofColor::white ); shader.begin(); ofRect( 0, 0, 100, 100 ); shader.end();
Vertex shader:
precision highp float;
uniform mat4 modelViewProjectionMatrix;
varying vec4 position;
void main() {
gl_Position = modelViewProjectionMatrix * position;
}
Fragment shader:
precision highp float;
void main() {
float windowWidth = 768.0;
float windowHeight = 1024.0;
float r = gl_FragCoord.x / windowWidth;
float g = gl_FragCoord.y / windowHeight;
float b = 1.0;
float a = 1.0;
gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
}
My console says:
trying to lauunch delegate ofxiOSAppDelegate
2015-03-21 09:39:54.232 emptyExample[3072:60b] Creating OpenGL ES2 Renderer
And the output is a white screen, as if the rect is being drawn without the shader applied.
I’m pretty sure the shaders are being compiled, because I had to go through a few steps fixing syntax errors in them. I’m not sure what is going on here, I expect the rect to be filled red. Is there anything else I need to do to turn on shaders?
Thank you!