OpenGL ES2 matrix setup (humbly crawling back)

Posts: 834
Joined: 2002.09
Post: #1
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.
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #2
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
Quote this message in a reply
Posts: 834
Joined: 2002.09
Post: #3
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
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGLES video play back prathap 0 5,382 May 9, 2014 03:45 AM
Last Post: prathap
  OpenGL Pixel Buffer Object setup issue dotbianry 2 6,632 Jan 6, 2013 11:03 AM
Last Post: dotbianry
  bug in OpenGL setup for NSOpenGL subclass (I think) backslash 2 5,329 Jul 18, 2007 01:10 PM
Last Post: backslash
  xCode/SDL Setup hammonjj 2 6,617 Mar 2, 2007 06:37 AM
Last Post: hammonjj
  Fullscreen/Window Setup/toggle skyhawk 10 8,372 Oct 13, 2006 04:05 PM
Last Post: skyhawk