Question

I am drawing a texture with 4 vertices in OpenGL ES 1.1.

It can rotate around z:

glRotatef(20, 0, 0, 1);

But when I try to rotate it around x or y like a CALayer then the texture just disappears completely. Example for rotation around x:

glRotatef(20, 1, 0, 0);

I also tried very small values and incremented them in animation loop.

// called in render loop
static double angle = 0;
angle += 0.005;
glRotatef(angle, 1, 0, 0);

At certain angles I see only the edge of the texture. As if OpenGL ES would clip away anything that goes into depth.

Can the problem be related to projection mode? How would you achieve a perspective transformation of a texture like you can do with CALayer transform property?

Was it helpful?

Solution

The problem is most likely in one of the glFrustumf or glOrthof. The last parameter in this 2 calls will take z-far and it should be large enough for the primitive to be drawn. If a side length of the square is 1.0 and centre is in (.0, .0, .5) then z-far should be (> 1.0) to see the square rotated 90 degrees around X or Y axis. Though note these can depend on other matrix operations as well (translating the object or using tools like lookAt). Making this parameter large enough should solve your problem.

To achieve a perspective transformation use glFrustumf instead of glOrthof.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top