I am using this tutorial / sample to do some basic object tracking on the iPhone. Everything works fine, I even tweaked the performance a whole lot, but I am still stuck with one problem.
The basic problem is that I do not understand OpenGL well enough and I should be punished for shamefully taking sample code and turning it into something that works for me. As a matter of fact I am being punished;
The sample shows how to render (with shaders) the iPhone’s camera into an offscreen texture in order to be able to process it and show it on screen. Now I have figured out that it draws the texture/layer using an array of vertex attributes (a principle I barely understand, despite my Google searches).
The vertex array’s are as follows:
static const GLfloat squareVertices[] = {
-1.0f, -1.0f,
1.0f, -1.0f,
-1.0f, 1.0f,
1.0f, 1.0f,
};
static const GLfloat textureVertices[] = {
1.0f, 1.0f,
1.0f, 0.0f,
0.0f, 1.0f,
0.0f, 0.0f,
};
I have also figured out that these vertex attributes can alter the orientation of the drawn texture. The texture is now drawn in portrait, which means that if I keep my iPhone in landscape (which I desire), and let the views rotate along, everything I see on the screen is a camera with a 90 degree angle.
I think I narrowed the problem down enough to blame these vertexes and I have been messing around with their values somewhat but without any acceptable result.
Is there anybody out there who can help me draw the texture in landscape?
P.S: if I inverse the values of ‘squareVerticles’ I am able to get a 180 degree rotated picture. But I want the texture to be rotated 90 degrees, not 180.
Imagine that your screen has normalized coordinates that go from
-1.0,-1.0(left, bottom) to1.0, 1.0. The first array specifies the coordinates of the vertices of a square (presumably as a triangle strip, because they are given in a “Z” fashion).The second array specifies the texture coordinates. Same thing, except that they are in the
0.0, 1.0range.So, to rotate 90 degrees clockwise:
anticlockwise:
I hope that works!