I need help setting up multi-pass rendering with OpenGL ES 2.0 on the iPhone. I haven't been able to find an example which implements both rendering to a texture and multi-pass shading.
I'm looking for some instructions and sample code which implement:
First stage: Render to a texture
Second stage: Input that texture and render to screen
I have referenced Apple's OpenGL ES Programming Guide, OpenGL Shading Language (Orange Book), and O'Reilly's iPhone 3D Programming Book.
The Orange Book discusses deferred shading and provides two shader programs for first-pass and second-pass rendering, but doesn't provide example code to setup that application or show how to communicate data between both shaders.
Questions:
How to render to texture?
Using glDrawElements
How to input that texture to the next pass?
How to implement two shading programs?
How to alternate first- and second-pass shading programs?
Need to attach, detach, and call 'use' for each pass?
How to implement multi-pass shading?
I wrote a short example of doing just this (multiple render-to-texture passes on the iPhone using OpenGL ES 2.0) a few weeks ago: http://www.mat.ucsb.edu/a.forbes/blog/?p=245
**
Edit, this post is a bit old, and it has moved here:
http://blog.angusforbes.com/openglglsl-render-to-texture/
**
Ok, first of all: I'm no expert on OpenGL ES 2.0. I was kind of in the same situation where I wanted to do a multipass render setup, in one of my first OpenGL ES applications.
I also used the Orange Book. Check chapter 12. Framebuffer Objects > Examples. The first example demonstrates how to use a framebuffer to render to a texture, and then draws that texture to screen.
Basically using that example I created an application that renders some geometry to a texture using an effect shader, then renders that texture to screen, layered with some other content all using a different shader.
I'm not sure if this is the best approach, but it works for my purposes. My setup:
I create two framebuffers, the default and an offscreen one. Same for the renderbuffers
I create a texture which the app will render to
I bind the offscreen framebuffer, and attach the texture to it using glFramebufferTexture2D
My rendering:
bind the offscreen framebuffer.
use my first shader program
draw my geometry
bind the default framebuffer
use my second shader program
draw a fullscreen quad with the texture attached to it.
Related
I want to implement image edition using OpenGL shaders. I have found some examples how to implement off-screen rendering using OpenGL ES1.
Do you now any example about off-screen rendering using OpenGL ES2 ans shaders on iPhone?
Thank you in advance
You need to use the framebuffer object extension (FBO), which is part of OpenGL ES2.
This is the same way as with OpenGL ES 1.0, except the functions lose their OES suffix (because FBO was an OES extension to ES1, not a part of the core).
You might like http://programming4.us/multimedia/3288.aspx this tutorial. The code is pretty simple and should be pretty easy to use it with GLES2.
I want to enable rendering in specified points (I am holding the collection of points in array) and disable rendering on rest of OpenGL layer
can any one help me to get out of this problem for iPhone!!!!
If you're using OpenGL ES 2.0, you can use the stencil buffer to mask those areas.
How big of a difference is the description language of Quartz2d to OpenGL ES?
It seems they are similar in description power... except that Quartz is mostly 2d and that OpenGL is out of the box 3d ( but can be made 2d focused ).
Are the mappings from 2dQuartz to 2d OpenGL ES that different? Im sure there must be differences in some specific features that might be handled differently on one vs another... but to do a translator?
Anyone have experience with both OpenGL and Quartz2d have some insights?
Quartz and OpenGL ES are two completely different animals. While they both have a C-based API that deals with a state machine and that draws into a context, their purposes are dissimilar. In Quartz you specify lines, Bezier and quadratic curves, arcs, or rectangles, as well as fills, gradients, and shadows / glows. In OpenGL ES, you provide vertices, raster textures, and lighting information, from which a scene is generated.
They are both useful in particular cases. You might draw a 2-D static element using Quartz, into a view, layer, or texture, and then place and move that view or layer in 3-D space using Core Animation or do the same for a texture using OpenGL ES.
Rather than try to overlay one API on the other, use whichever is more appropriate for what you are doing, or look to a framework like cocos2d which lets you build and animate 2-D scenes or Core Animation where you can do Quartz drawing into a layer but still use a nicely abstracted API for moving these layers around.
So, I've been trying to figure out why the square is moving up and down the iPhone simulator when I Build and Run the template that Apple provides for OpenGL ES. I don't understand why for example they have ES1Render.m, and ES2Render.m instead of just one ESRender.m. Also, where is the equivalent of the glutDisplayFunc, and glutTimerFunc? Thanks in advance.
They are trying to the show the two versions of OpenGL ES. One uses shaders (v2) and the other (v1) uses older OpenGL technology. In the ES2 renderer I believe they are doing all the movement in the shader code. If you want something that looks like older OpenGL code try setting it to use the version 1 renderer. Then you can use stuff like the older demos on http://nehe.gamedev.net/. You just need to fill in the "render" function with your drawing code.
EAGLView has a timer which sets the frame rate, but there is a method which allows you to set it to be whatever you like.
For one of my new games I'm using OpenGL ES since it has multiple enemies and bullets, etc. How do you draw images on the screen with Opengl ES? I have a player.png image that is a 48x48 pixel image; how would I draw that on the screen?
The basic answer is that you create a quad out of two triangles and draw that "camera facing" or in 2D mode on the screen.
In the iPhone example of OpenGL ES (the rocket ship one) you can see the Texture2D class which handles loading png's and displaying them. It's simple, but works.
But I would suggest you take a look at cocos2d iPhone. This framework handles a lot of this stuff for you and lets you focus a lot more on your game: http://code.google.com/p/cocos2d-iphone/
You might also look at GameSalad for a non-programmery way of making simple iPhone games: http://gamesalad.com/