rendered paste body/** * */package loach.view.lwjgl.util.gl.sprite;import loach.view.lwjgl.LWJGLLoachView;import loach.view.lwjgl.util.gl.texture.GLTexture;import org.lwjgl.opengl.GL11;import org.lwjgl.util.Dimension;import org.lwjgl.util.Point;import org.lwjgl.util.Rectangle;/** * Loach V (Java) - GLTexturedSprite * @version 1.0 * @author <a href="mailto:Dessimat0r@ntlworld.com">Chris Dennett</a> */public class GLTexturedSprite extends GLSprite { /** The texture. */ protected final GLTexture texture; protected int textureRotationDegrees = 0; protected boolean flipH = false; protected boolean flipV = false; /** * @param lwjglLoachView * @param texture * @param position * @param z * @param affectedByViewPort */ public GLTexturedSprite( LWJGLLoachView lwjglLoachView, GLTexture texture, Point position, int z, boolean affectedByViewPort ) { this( lwjglLoachView, texture, new Rectangle(position, texture.getSize()), z, affectedByViewPort ); } /** * @param lwjglLoachView * @param texture * @param area * @param z * @param affectedByViewPort */ public GLTexturedSprite( LWJGLLoachView lwjglLoachView, GLTexture texture, Rectangle area, int z, boolean affectedByViewPort ) { super(lwjglLoachView, area, z, affectedByViewPort); this.texture = texture; } /* (non-Javadoc) * @see loach.view.lwjgl.GLSprite#render() */ @Override public void render() { if (isVisibleInViewPort()) { Rectangle renderArea = getAreaRelativeToViewPort(); Dimension textureSize = texture.getSize(); int x = renderArea.getX(), y = renderArea.getY(), width = renderArea.getWidth(), height = renderArea.getHeight(), textureWidth = textureSize.getWidth(), textureHeight = textureSize.getHeight() ; float textureWidthRatio = width / textureWidth, textureHeightRatio = height / textureHeight ; GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glColor3f(1.0f, 1.0f, 1.0f); GL11.glPushMatrix(); /* store current model matrix */ texture.bind(); if (flipH) { textureWidthRatio = -textureWidthRatio; } if (flipV) { textureHeightRatio = -textureHeightRatio; } if (textureRotationDegrees != 0) { GL11.glTranslatef(width / 2, height / 2, 0); GL11.glRotatef(textureRotationDegrees, 0, 0, 1.0f); GL11.glTranslatef(-(width / 2), -(height / 2), 0); } GL11.glTranslatef(x, y, z); /* draw a quad textured to match the sprite */ GL11.glBegin(GL11.GL_QUADS); { GL11.glTexCoord2f(0, 0); GL11.glVertex2i(0, 0); GL11.glTexCoord2f(0, textureHeightRatio); GL11.glVertex2i(0, height); GL11.glTexCoord2f(textureWidthRatio, textureHeightRatio); GL11.glVertex2i(width, height); GL11.glTexCoord2f(textureWidthRatio, 0); GL11.glVertex2i(width, 0); } GL11.glEnd(); GL11.glPopMatrix(); /* restore the model view matrix */ GL11.glDisable(GL11.GL_TEXTURE_2D); } } /** * @param textureRotationDegrees The textureRotationDegrees to set. */ public void setTextureRotationDegrees(int textureRotationDegrees) { this.textureRotationDegrees = textureRotationDegrees; } /** * @param flipH The flipH to set. */ public void setFlipH(boolean flipH) { this.flipH = flipH; } /** * @param flipV The flipV to set. */ public void setFlipV(boolean flipV) { this.flipV = flipV; } }