2
votes

Newbie to OpenGL...

I have some very simple code (non OpenGL) for rotating a rectangle around a single axis, and projecting the result down to screen coordinates. I'm now trying to map a bitmap to the resulting shape using OpenGL. When animating the rotation, the perspective of the bitmap is quite heavily distorted. Is this to be expected? Is there something I can do about it?

I know I can use OpenGL to do the whole thing instead (and that works fine), but for my current project the approach above would suit me better, if I can just get around this perspective issue... I'm thinking maybe there's not enough information after I have projected the rotated rectangle down to 2D space for OpenGL to correctly map the bitmap with the right perspective..?

Any input would be much appreciated.

Thanks, Daniel

To clarify: I'm using an orthographic projection, and doing the 3D calculation and projection to 2D myself. Then I just use OpenGL for rendering the resulting shape with a texture.

2
use glRotatef() to rotate your rectangle. check your texture coordinates as well, they have nothing to do with the vertex coordinates. i think you are using vertex coordinates in the texture coordinates. without any image of how it looks for you, its hard to say. (it is not expected to get distorted).Newbie

2 Answers

0
votes

If you project your coordinates yourself and do the texture mapping in 2D screen coordinates you will loose all projective information and the textures will badly distort.

You can get around this by using a perspective texture mapping. A lot of different ways to do this exist. Either by writing a real perspective texture mapper or by faking and using a plain texture mapper.

Explaining how this works is somewhat beyond the scope of a single question. I assume you read the wiki-page about perspective texture mapping first and try out the subdivision method:

http://en.wikipedia.org/wiki/Texture_mapping

Then come back and ask for detail questions..

0
votes

I found the following page that explains the subdivision method in detail: http://freespace.virgin.net/hugo.elias/graphics/x_persp.htm

It worked perfectly! Thanks Nils for pointing me in the right direction.