thrash
thrash

Reputation: 187

JOGL - translate GL_QUADS

In JOGL im trying to create a few 3D shapes using GL_QUADS (i.e. different components of a whole object) and so far its been fine to do this but I cant figure out how to translate the shape, there must be a way to do this but im not very familiar with GL_QUADS so im not entirely sure how to go about this. Editing gl.glVertex3f just results in the shape being a different size which seems to be the only thing I can edit, is it possible to give a GL_QUAD a variable name?

Upvotes: 1

Views: 1674

Answers (2)

Quetzalcoatl
Quetzalcoatl

Reputation: 3067

Calling gl.glTranslatef(1.0f, 0.0f, 0.0f); will apply to the current matrix in the stack, effectively meaning that whatever you draw from then on will appear 1 unit along on the x axis from whatever the matrix was on before (probably the origin in your case).

I can see why it might seem confusing, rather than creating the shape then moving it (can't be done, it's already been drawn), you'll want to translate then draw your shape.

For example:

gl.glPushMatrix();
    gl.glTranslatef(1.0f, 0.0f, 0.0f);
    gl.glBegin(GL2.GL_QUADS);
        // draw some vertices here
    gl.glEnd();
gl.glPopMatrix();

Upvotes: 1

gcvt
gcvt

Reputation: 1512

You can use the glTranslatef function:

// render the shape
gl.glTranslatef(5.0f, 0.0f, 0.0f); // translate along x, y, z
// render the shape - you will now have two shapes next to each other

Upvotes: 2

Related Questions