سؤال

How do I transform previously drawn elements? I've drawn a rough 4 million vertices to the screen, and I'd like to translate them after they are drawn. I'd prefer not to redraw them each time I want to translate them (4 million!)

Here is the relevant code.

glOrtho(0, 1024, 0, 576, 0, -4096);
glTranslatef(-512, -288, 512);
glRotatef(45, 1, 0, 0);
glTranslatef(512, 0, -512);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.F, 1.F, 1.F);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_INT, 0, &vertices[0]);
glDrawElements(GL_QUADS, vertexIndex.size(), GL_UNSIGNED_INT, &vertexIndex[0]);
glDisableClientState(GL_VERTEX_ARRAY);
// I would like to translate here
هل كانت مفيدة؟

المحلول

It is not possible, your vertex positions are internally multiplied with a transformation matrix to get the final position which is drawn on the screen.

So if you try to change the matrix after drawing it doesn't have any effect on the drawn vertices, and its goo that way.

To solve your problem just transform it before drawing... its the standard way, there is no other way to do it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top