OpenGL ES2 matrix setup (humbly crawling back)

Oldtimer
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:
Code:
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
Luminary
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 http://glm.g-truc.net/
Quote this message in a reply
Oldtimer
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 1,296 May 9, 2014 03:45 AM
Last Post: prathap
  OpenGL Pixel Buffer Object setup issue dotbianry 2 3,393 Jan 6, 2013 11:03 AM
Last Post: dotbianry
  The tabbing on a word playing back the recorded voice itcreate 0 2,530 Jun 25, 2010 02:06 PM
Last Post: itcreate
  bug in OpenGL setup for NSOpenGL subclass (I think) backslash 2 3,821 Jul 18, 2007 01:10 PM
Last Post: backslash
  xCode/SDL Setup hammonjj 2 4,837 Mar 2, 2007 06:37 AM
Last Post: hammonjj