Shaders implementation

I am following along the iPhone 3D Programming book, and just complete chapter 1, now I want to port the code from the book to OF using the ofxiPhone version, but by doing so I get lots of errors, for example if I use:

  
  
glUseProgram(m_simpleProgram);  
  
// or  
  
GLuint positionSlot = glGetAttribLocation(m_simpleProgram, "Position");  
GLuint colorSlot = glGetAttribLocation(m_simpleProgram, "SourceColor");  
  

I get the error: ‘glGetAttribLocation’ was not declared in this scope

My guess is that this are OpenGLES 2 methods and ofxiPhone only use OpenGLES 1.x, is this correct? can I change ofxiPhone to do ES2 stuff? am I doomed?

Find my code attach, all the calls are in the Arrow Class

Cheers
rS

Archive.zip

Hi, most of that code is for initialising the window and glview etc. All of that is already done in ofxiPhone. So if you want to follow those steps and code from the book you’re really better off starting from scratch in a new project - as the book recommends you do. ofxiPhone currently does take an ES1.0 only approach but ES2.0 support is in the works.

I see, correct me if I am wrong, but from my understanding shaders are only supported in OpenGL ES 2.0, you mention that those steps are handle by ofxiPhone already, so is there a different approach to use shaders in the current version ofxiPhone? If so can you share an example?

Cheers
rS

Hi,

yes shaders are only available in opengl es2.0. So you will not be able to use them in the current version of ofxiPhone since it automatically inits everything with ES1. If you want to use shaders currently with OF you need to go in the guts and manually change all the init stuff. There is a WIP here but it’s not finished yet. Chapter one of that book explains the init procedures pretty well. (or you can look at the Apple OpenGL template).

Hi,

When I compile an iPhoneOF app the console outputs this:
2010-11-22 10:46:39.359 ShaderAddonTest[751:207] Creating OpenGL ES2 Renderer
2010-11-22 10:46:39.441 ShaderAddonTest[751:207] Failed to load vertex shader
2010-11-22 10:46:39.442 ShaderAddonTest[751:207] Failed to compile vertex shader
2010-11-22 10:46:39.443 ShaderAddonTest[751:207] OpenGL ES2 failed
2010-11-22 10:46:39.472 ShaderAddonTest[751:207] Creating OpenGL ES1 Renderer

So I guess it is possible some how but ofxShader has lots of methods that are not compatible with iOS OpenGL ES.

Has anyone manage to get a shader working with OF in the iPhone? I try Memo’s suggestion but fail miserably.

Cheers

  • rS

[quote author=“nardove”]Hi,

When I compile an iPhoneOF app the console outputs this:
2010-11-22 10:46:39.359 ShaderAddonTest[751:207] Creating OpenGL ES2 Renderer
2010-11-22 10:46:39.441 ShaderAddonTest[751:207] Failed to load vertex shader
2010-11-22 10:46:39.442 ShaderAddonTest[751:207] Failed to compile vertex shader
2010-11-22 10:46:39.443 ShaderAddonTest[751:207] OpenGL ES2 failed
2010-11-22 10:46:39.472 ShaderAddonTest[751:207] Creating OpenGL ES1 Renderer

So I guess it is possible some how but ofxShader has lots of methods that are not compatible with iOS OpenGL ES.

Has anyone manage to get a shader working with OF in the iPhone?

Cheers

  • rS[/quote]

i have the same problem .
OF v0.062
Mac OSX 10.6.5
Xcode 3.2.4
iPhone 4 - (iOS 4.1)

Hey, so has anyone working ofxiphone with ofxShader?
or any other way of using OF and shaders on iOS?

Thanks!

/roger

[quote author=“rogerpala”]Hey, so has anyone working ofxiphone with ofxShader?
or any other way of using OF and shaders on iOS?
r[/quote]

any news on this?
thx!

so, there are a few issues:

The code that runs shaders (in ofShader) relies on function calls that need to be changed on openglES. It would require pretty big tweaks.

The other issue is that openglES 1 and openglES 2 are pretty different in the way that they draw to the screen, basically you need to build the rendering pipeline yourself on es2.

The short answer is that it requires a pretty major restructuring of both the OF core, and the ofShader addon.

Does anybody know the status of this?
I would like to help if I could. I might be hiring someone to do this as well and contribute the code.
I just want to know what’s been done or whether there are plans in the works.

I also found that cocos2D-iPhone has some discussion on OpenGL ES 2.0 .
http://www.cocos2d-iphone.org/forum/topic/6074/page/3

Anybody have an example of using the es2renderer files that memo added? Following the thread I understand that it’s not easy to get es2 fully integrated with ofxiPhone, but an example where the es2renderer is initialized and the draw calls are made in raw gl would be extremely helpful.

Thanks!