OpenGL rotations and scaling

Hi All,

since I don’t have time to learn OpenGL during the next week due to a deadline, I ask for someone for a snippet of code on how to do image rotations and image scaling with LWJGL?

Thanks a lot!

We’ve all got deadlines, what makes yours so great. :stuck_out_tongue:

Assuming you can already draw sprites as textured quads then you can just do your scale and rotate with the modelview matrix (and glRotatef and glScalef).

If you need to learn drawing sprites as well, then have a shufti at Kev’s space invaders tutorial and the other stuff in lwjgl/test.

Thanks for your help.

[quote]We’ve all got deadlines, what makes yours so great. Tongue
[/quote]
Mighty Bubbles will be demoed at GDC and I want to migrate it to LWJGL before the conf. to make it looks better and run faster particularly for image scaling. And I have to enhance the graphics that my graphics designer is working on plus some fixes to do.

The code to draw sprites is already in place. Concerning the modelview matrix, is it the same as it is for drawing image?

Probably, somewhere after your projection setup you’ve probably got a glMatrixMode(GL_MODELVIEW) call to use that. Then all you have to make sure of is to push/pop around your scale/rotate so you undo them correctly (but if you’re already using glTranslatef for positioning you’ll already have that).

Of course you could always just tinker with the vertices yourself, which might be easier if you need the transformed shape for collision.

ok thanks for help. :slight_smile:

I wrote a routine in Rimscape that draws an image using an AffineTransform. You might find it useful if you already got the Java2D version running.

      
/** Is used to convert from a AffineTransform to a opengl matrix */
private static double affineMatrix[] = new double[3*3];
      
/** Opengl matrix */
private static FloatBuffer glMatrix = BufferUtils.createFloatBuffer(16);

/**
 * Draws a sprite using a AffineTransform as the location.
 */
public static void drawImage(TexturedImage img, AffineTransform transform) {
      transform.getMatrix(affineMatrix);
      glMatrix.rewind();
      glMatrix.put((float)affineMatrix[0]).put((float)affineMatrix[1]).put(0).put(0);
      glMatrix.put((float)affineMatrix[2]).put((float)affineMatrix[3]).put(0).put(0);
      glMatrix.put(0).put(0).put(1).put(0);
      glMatrix.put((float)affineMatrix[4]).put((float)affineMatrix[5]).put(0).put(1);
      glMatrix.rewind();
      GL11.glPushMatrix();
      GL11.glMultMatrix(glMatrix);
      drawImage(img, 0, 0);
      GL11.glPopMatrix();
}

tom rocks ;D