Basically, I am being forced to use OpenGL to do my drawing (by a 3rd party application that I cannot avoid).
I need to be able to draw in image from a png file. I need to be able to rotate that image. Both of these, I have working. What I need help with it figuring out how to clip the image. Basically, the image is large and I want to have a small viewport with the image moving/rotating inside it. The viewport would stay fixed (a small square) and the image I am drawing would pan/rotate behind the viewport square and be clipped to fit within the viewport square (I hope that made sense)
I am currently loading the file and drawing the image as a texture as follows:
(I modified example code to get to here, so please let me know if I am doing this part incorrectly as well)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| m_imageList = gl.glGenLists(1); gl.glNewList(m_imageList, gl.GL_COMPILE); gl.glPushMatrix(); gl.glTranslatef(-0.5, -0.5, 0.0); gl.glTexEnvi(gl.GL_TEXTURE_ENV, gl.GL_TEXTURE_ENV_MODE, gl.GL_MODULATE); gl.glEnable(gl.GL_TEXTURE_2D); gl.glBindTexture(gl.GL_TEXTURE_2D, textureID); gl.glBegin(gl.GL_QUADS); gl.glTexCoord2f(0.0, 0.0); gl.glVertex2f(0.0, 0.0); gl.glTexCoord2f(1.0, 0.0); gl.glVertex2f(1.0, 0.0); gl.glTexCoord2f(1.0, 1.0); gl.glVertex2f(1.0, 1.0); gl.glTexCoord2f(0.0, 1.0); gl.glVertex2f(0.0, 1.0); gl.glEnd(); gl.glPopMatrix(); gl.glEndList();
gl.glPushMatrix(); gl.glLoadIdentity(); gl.glPushMatrix(); gl.glTranslate(x, y, 0.0); gl.glScalef(256.0, 32.0, 0.0); gl.glColor4f(1.0, 1.0, 1.0, 0.5); gl.glCallList(m_imageList); gl.glPopMatrix(); |