View Full Version : How to store transformation result?

fba218

10-11-2006, 08:58 PM

Hi, I am new to OpenGL hope someone can help me with following problem.

Is it possible to store a transformation result? ie: If I apply glScalef(2,2,0) to a square struct (with 4 points in the struct) and if I want to save the transformed result of the points back to the square variable structure I have. How should I do that?

Thanks

k_szczech

10-11-2006, 11:11 PM

Two ways:

1.using OpenGL's feedback mode

-a bit more difficult

-can be used in combination with vertex shaders

-uses more GPU and less CPU

2.using your own math

-simple

-uses CPU

I would suggest using your own math, and leave GPU alone, so it can render scene while CPU does the math. It's quite simple actually - all you need to do is to read current modelview matrix and multiply all vertices by this matrix.

If you want feedback mode anyway:

Read about glRenderMode and glFeedbackBuffer functions - if you put OpenGL to feedback mode then instead of rendering polygons it will transform them and return everything to your buffer.

Note thet what you get in feedback mode are actually screen coordinates - you should use glOrtho as your projection matrix and make sure that after transformation your object is completely inside view frustum. Otherwise it will be clipped and will in fact be different polygon.

Another thing is that there is no saying in what order you will receive your data back from OpenGL - or worse yet - instead of one quad it can create 2 triangles and return 6 points. The simplest way around that is just using GL_POINTS when rendering in feedback mode.

RigidBody

10-12-2006, 12:07 AM

3. apply the transformations to the modelview matrix, read the modelview matrix with glGetFloatv(GL_MODELVIEW_MATRIX, ...), then multiply your points with the modelview matrix.

Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.