OpenGL ES2 matrix setup (humbly crawling back)
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.
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:
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.
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.

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 * vertexDigging 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.
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/
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/
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
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenGL Pixel Buffer Object setup issue | dotbianry | 2 | 1,063 |
Jan 6, 2013 11:03 AM Last Post: dotbianry |
|
| The tabbing on a word playing back the recorded voice | itcreate | 0 | 1,977 |
Jun 25, 2010 02:06 PM Last Post: itcreate |
|
| bug in OpenGL setup for NSOpenGL subclass (I think) | backslash | 2 | 3,256 |
Jul 18, 2007 01:10 PM Last Post: backslash |
|
| xCode/SDL Setup | hammonjj | 2 | 4,292 |
Mar 2, 2007 06:37 AM Last Post: hammonjj |
|
| SDL 2D OpenGL setup | unknown | 13 | 6,376 |
Jul 16, 2005 09:07 PM Last Post: unknown |
|

