What's wrong with this?

BlitzMax Forums/OpenGL Module/What's wrong with this?

Brucey(Posted 2015) [#1]
Hallo :-)

I'm trying to apply an orthographic matrix to a shader, but it's not drawing anything. Can anyone see what I'm doing wrong?

Platform is iOS, OpenGL ES 2

Here's the original without the matrix :

This renders a full-screen coloured box.

And here's the modified version that doesn't seem to draw anything.


Similar code does work on the Pi and Android, so I'm not sure if there's anything specific to iOS that I'm doing wrong?

Thanks in advance for any help.


Floyd(Posted 2015) [#2]
Wild guess, perhaps the roles of -Z and +Z got swapped somewhere. That seems like something that could easily happen in multi-platform development.

You might try swapping them again in the matrix and seeing if it helps.
		u_pmatrix.SetOrthographic( 0, screen_width, 0, screen_height, +1, -1 )



Brucey(Posted 2015) [#3]
Interestingly, if I use an identity matrix on the second example, and set the viewport, and use the original vertex data, it renders correctly - as you would expect - which I think proves the code for applying the matrix itself is okay.

Which leaves 2 things as far as I can tell :
1) the ortho math is wrong
2) something to do the viewport is wrong? I am not calling glViewport() in the second version because I thought that's what the ortho is for?


Floyd(Posted 2015) [#4]
I would imagine you need a viewport in any case.

Perspective projection is like real life. As things get farther away they look smaller.

Orthographic project is done with parallel lines and there is no perspective. Identical objects will look the same at all distances. You can also think of it as the limiting case of standing very far away and looking through a powerful telescope. Suppose you look at two things at distances 1 and 2. The far one looks half as big. Now move back so distances are 1001 and 1002, but look through a 1000x zoom lens. The objects look as if the distances were 1.001 and 1.002 so they look practically identical. Orthographic projection is the limiting case as distance goes to infinity, but zoom cancels it out.

In any case the projected result must get put on the screen. I think you still need a viewport for that.


LT(Posted 2015) [#5]
The orthographic matrix and the viewport are two different things, I think. It's just that computing the matrix happens to need similar values. I believe that glViewport does some kind of additional transformation from device to window coords.


Brucey(Posted 2015) [#6]
Thanks for the help guys :-)

I appear to have got my head around it now...




DStastny(Posted 2015) [#7]
Nice


markcw(Posted 2015) [#8]
.


markcw(Posted 2015) [#9]
Sorry for the silly post, I had a bit much to drink. I guess I was trying to say brilliant work.