tags:

views:

162

answers:

3

Hi,

I am drawing a rectangular block:

GLfloat cubeVertexV[] = {
    // FRONT
    -0.5f, -1.0f,  0.5f,
     0.5f, -1.0f,  0.5f,
    -0.5f,  1.0f,  0.5f,
     0.5f,  1.0f,  0.5f,
    // BACK
    -0.5f, -1.0f,  -0.5f,
     0.5f, -1.0f,  -0.5f,
    -0.5f,  1.0f,  -0.5f,
     0.5f,  1.0f,  -0.5f,
    // LEFT
    -0.5f, -1.0f,  0.5f,
    -0.5f,  1.0f,  0.5f,
    -0.5f, -1.0f, -0.5f,
    -0.5f,  1.0f, -0.5f,
    // RIGHT
     0.5f, -1.0f, -0.5f,
     0.5f,  1.0f, -0.5f,
     0.5f, -1.0f,  0.5f,
     0.5f,  1.0f,  0.5f,
    // TOP
    -0.5f,  1.0f,  0.5f,
     0.5f,  1.0f,  0.5f,
     -0.5f,  1.0f, -0.5f,
     0.5f,  1.0f, -0.5f,
    // BOTTOM
    -0.5f, -1.0f,  0.5f,
    -0.5f, -1.0f, -0.5f,
     0.5f, -1.0f,  0.5f,
     0.5f, -1.0f, -0.5f,
};

now i apply glRotate() in x,y,z axes on ths block... now i want to change the cubeVertex array with the new coordinates resulting from the application of glrotate call.. is this possible in opengl?

Thanks.

+1  A: 

You can use glGet with GL_MODELVIEW_MATRIX to get the current modelview matrix (assuming you applied the glRotate call to it). Then, manually transform your vertices by the matrix.

Alexander Gessler
+1  A: 

Generally speaking, OpenGL will just accumulate the transforms, and only actually apply them to the data when you render it. In the plain old fixed-function graphics pipeline, there's no way to do it. However, as programmability has been increasing every generation, there is support for this now via OpenGL extensions, provided you're using a recent enough graphics card. Whether you have an nVidia or ATI card might also make a difference, as they don't always support the same extensions.

It's been some time since I did much OpenGL, so this is going to be a little vague, but the general idea is:

  • you bind a pair of Vertex Buffer Objects,
  • put your data in the first one,
  • use Transform Feedback to render the transformed vertices into the second,
  • and you can then read back data from the second VBO into memory.

The nVidia Transform Feedback Fractal demo on their OpenGL Code Samples page should help you with the actual code for this.

If you want to do more general math on your GPU, you should look into GPGPU techniques, there's a LOT more stuff you can do, and with CUDA / OpenCL / etc. it gets a lot easier to code, too.

tzaman
A: 

It's not trivial, but look up glRenderMode(GL_FEEDBACK); to get started. This will give you not only the coordinates, but also (for example) colors after lighting has been applied.

Jerry Coffin