iDevGames Forums
OpenGL ES2 matrix setup (humbly crawling back) - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: OpenGL ES2 matrix setup (humbly crawling back) (/thread-9310.html)

OpenGL ES2 matrix setup (humbly crawling back) - Fenris - Aug 29, 2011 11:59 PM

So, I've spent the last couple of weeks trying to update some of my rendering code for my master thesis project (seven years later...). Working with OpenGL ES 2 has been a very humbling experience, to say the least. I've tried to stick to the documentation so I could make a brilliant return here and actually show something, but I guess that a translating triangle will have to do for now...

I got it mostly to work, except that my matrix transform code felt a bit shoddy, and when I tried to set it right, a couple of mental models fell like card houses. Fail

Here's what I do:
- create one uniform matrix4 with orthographic projection
- create one uniform matrix carrying my camera transform
- create one uniform matrix stack used for placing stuff in the world

I send these to the shader, and multiply them as:
projection * view * model * vertex

Digging through examples, I kind of gather that I'm supposed to bake model and view into a single matrix - is this just convention, or recommended? What's the recommended method for getting the transforms right?

There's nothing special in my code, just a single camera translation (think 2D side-scrolling) and a lot of objects being sprinkled around. Therefore I'd like to have the model matrix as a separate matrix stack, but how does that play along with inverting camera movements?

I realize that the view matrix needs to be inverted, but I thought that was just a simple transpose, but it seems like sample code examples do proper inversions. I can't recall ever doing that in the FF pipeline?

How do you guys do it? Is there any readable sample code that actually sets up projection, camera and movement? All I see is examples shirking their duty by negating camera moves by hand.

RE: OpenGL ES2 matrix setup (humbly crawling back) - OneSadCookie - Aug 30, 2011 09:30 AM

Inside the shader, for performance, you should have a single "uniform mat4 modelViewProjectionMatrix;" and a single multiply. No reason to do mat4*mat4(*mat4)*vec4 for each vertex when only mat4*vec4 is required.

Outside the shader, you can calculate that matrix however you like. If you want to have your view matrix separate from your model matrix, that's fine.

I generally find it easiest to use gluLookAt or equivalent to set up the view matrix. No inversion required...

I like

RE: OpenGL ES2 matrix setup (humbly crawling back) - Fenris - Aug 31, 2011 06:47 AM

Seems reasonable, and good advice. Since I'll be doing translations only (for now, at least) I'll just negate the camera movements. Thanks. <3