openfrog
openfrog

Reputation: 40765

How to rotate around x and y in OpenGL ES 1.1?

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?

Upvotes: 2

Views: 459

Answers (1)

Matic Oblak
Matic Oblak

Reputation: 16794

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.

Upvotes: 2

Related Questions