How to enable OpenGL ES2?

What’s going on here:

  
  
2012-02-29 15:59:34.286 iPadEmptyExample[41102:207] Creating OpenGL ES2 Renderer  
2012-02-29 15:59:34.289 iPadEmptyExample[41102:207] Failed to load vertex shader  
2012-02-29 15:59:34.289 iPadEmptyExample[41102:207] Failed to compile vertex shader  
2012-02-29 15:59:34.289 iPadEmptyExample[41102:207] OpenGL ES2 failed  
2012-02-29 15:59:34.290 iPadEmptyExample[41102:207] Creating OpenGL ES1 Renderer  
2012-02-29 15:59:34.295 iPadEmptyExample[41102:207] Applications are expected to have a root view controller at the end of application launch  
  

What’s missing that’s causing the shader and thus ES2 to fail?
I get the same output with all the provided examples. Even the all mighty google has left me empty handed.

Thoughts?

I dont think the OpenGL ES 2 is fully implemented in the current release, but Andreas Muller has a fork with a working ES 2 implementaiton check it out here https://github.com/andreasmuller/openFrameworks

Much thanks nardove

Correct me if I’m wrong but the GLES2 stuff has already been merged into 0.07. The only thing is that there’s no way to easily select which path to use, right now it just attempts to load a specific shader and if it fails it falls back to GLES1.

Any advice on where to go to just force the renderer to look for ES 1.1? Using QCAR image tracking, which works great in 1.1 but want to eliminate the pause on load where the iPhone looks for ES 2 first and can’t seem to hunt it down. Thanks!

NM - figured it out… in EAGLVIEW.mm inside of ofxiPhone, indeed there are indeed no initSettings to turn for es 1.1 (as mentioned in comments).

  
		  
  
// TODO: add initSettings to override ES2Renderer even if available  
        renderer = [[ES2Renderer alloc] initWithDepth:depth andAA:fsaaEnabled andFSAASamples:samples andRetina:retinaEnabled];  
		  
        if (!renderer) {  
            renderer = [[ES1Renderer alloc] initWithDepth:depth andAA:fsaaEnabled andFSAASamples:samples andRetina:retinaEnabled];  
			  
            if (!renderer) {  
				[self release];  
				return nil;  
			}  
        }  

However simply by commenting out the first renderer and the first if(!renderer), it works perfectly and loads in about half the time.

So is ES2 in 007 already? I tried commenting out the check for loadShaders in ES2Renderer.mm’s initWithDepth… but that just gives me a black screen when the app starts.

I just started looking into this, but here’s how I got to run an OpenGLES 2.0 example.

Create a Fragment Shader: “data/Shader.fsh”

  
  
#ifdef GL_ES  
precision mediump float;  
#endif  
  
void main( void ) {  
	float color = 0.9;  
	gl_FragColor = vec4( color, color, color, 1.0 );  
}  
  

Create a Vertex Shader: “data/Shader.vsh”

  
  
// 1.0 / stage width ( 1.0 / 320.0 )  = Should be a uniform  
#define SCALE_X 0.003125  
// 1.0 / stage height ( 1.0 / 480.0 ) = Should be a uniform  
#define SCALE_Y 0.002083  
  
attribute vec3 position;  
void main() {  
	bool portrait = true;  
	if(portrait) {  
		gl_Position = vec4(vec3(position.x * 2.0 * SCALE_X - 1.0, -position.y * 2.0 * SCALE_Y + 1.0, 0), 1.0);  
	} else {  
		gl_Position = vec4(vec3(position.y * 2.0 * SCALE_X - 1.0,  position.x * 2.0 * SCALE_Y - 1.0, 0), 1.0);  
	}  
}  
  

testApp.mm:

  
  
void testApp::setup(){  
	ofSetCircleResolution(40);  
	ofBackground(16, 204, 128);  
	ofSetFrameRate(60);  
	  
	glViewport(0, 0, ofGetWidth(), ofGetHeight());  
}  
void testApp::drawRect(float x, float y, float w, float h) {  
	GLfloat verts[] = {  
		x, y, 0,  
		x+w, y, 0,  
		x+w, y+h, 0,  
		x, y+h, 0  
	};  
	  
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, verts);  
	glEnableVertexAttribArray(0);  
	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);  
}  
void testApp::draw(){  
	drawRect(25, 25, 100, 25);  
}  
  

That vertex shader accounts for the cartesian offset (Top left = 0, 0), however it currently isn’t dynamic to determine when the phone is in portrait/landscape mode (hence the “portrait” bool).

*Notes
ES2Renderer is missing Depth, FSAA Frame and FSAA Color buffers, so don’t count on seeing any Z-Depth or anti-aliasing. In fact, most of the OF Graphics calls currently don’t work.

I spent some time working on this this weekend, and I got it somewhat working.

Unfortunately, as tomorrowevening says, it totally breaks giant chunks of ofGraphics (and ofFbo, and ofShader). But if you want the magic of pixelshaders, that seems like a fair price to pay.

I had used Andreas Muller’s fork early in the weekend, but it seems to have diverged quite far from the ofCore. I don’t know if I am the right person to get it up to date or not.

It would be really cool to get the gles 2.0 stuff in though. I don’t know if it will happen until the core starts moving towards gl 3.0, which is closer to gles 2.0.

i was facing the same problem as well dear… but from this topic discussion i get some glue… if i properly enable it… i must tell you…

Looks like most of our problems have been answered with Cocos2d-X’s-OpenGLES-2-implementation. Now we just need someone to finish migrating it :slight_smile: I’ll be working on my own-version-for-now.

actually this is closed to being working in OF.
Arturo and Julapy are working on an ES 2.0 branch here: https://github.com/julapy/openFrameworks/commits/ios-feature-es2

It should be fairly usable at this point.