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, and z axes on this 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?
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:
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.