Java Code Examples for org.newdawn.slick.opengl.renderer.SGL

The following examples show how to use org.newdawn.slick.opengl.renderer.SGL. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: opsu-dance   Source File: Image.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create an image based on a file at the specified location
 * 
 * @param ref The location of the image file to load
 * @param flipped True if the image should be flipped on the y-axis on load
 * @param f The filtering method to use when scaling this image
 * @param transparent The color to treat as transparent
 * @throws SlickException Indicates a failure to load the image
 */
public Image(String ref, boolean flipped, int f, Color transparent) throws SlickException {
	this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
	this.transparent = transparent;
	this.flipped = flipped;
	
	try {
		this.ref = ref;
		int[] trans = null;
		if (transparent != null) {
			trans = new int[3];
			trans[0] = (int) (transparent.r * 255);
			trans[1] = (int) (transparent.g * 255);
			trans[2] = (int) (transparent.b * 255);
		}
		texture = InternalTextureLoader.get().getTexture(ref, flipped, filter, trans);
	} catch (IOException e) {
		Log.error(e);
		throw new SlickException("Failed to load image from: "+ref, e);
	}
}
 
Example 2
Source Project: opsu-dance   Source File: Image.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Load the image
 * 
 * @param in The input stream to read the image from
 * @param ref The name that should be assigned to the image
 * @param flipped True if the image should be flipped on the y-axis  on load
 * @param f The filter to use when scaling this image
 * @param transparent The color to treat as transparent
 * @throws SlickException Indicates a failure to load the image
 */
private void load(InputStream in, String ref, boolean flipped, int f, Color transparent) throws SlickException {
	this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
	
	try {
		this.ref = ref;
		int[] trans = null;
		if (transparent != null) {
			trans = new int[3];
			trans[0] = (int) (transparent.r * 255);
			trans[1] = (int) (transparent.g * 255);
			trans[2] = (int) (transparent.b * 255);
		}
		texture = InternalTextureLoader.get().getTexture(in, ref, flipped, filter, trans);
	} catch (IOException e) {
		Log.error(e);
		throw new SlickException("Failed to load image from: "+ref, e);
	}
}
 
Example 3
Source Project: opsu   Source File: Image.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create an image based on a file at the specified location
 * 
 * @param ref The location of the image file to load
 * @param flipped True if the image should be flipped on the y-axis on load
 * @param f The filtering method to use when scaling this image
 * @param transparent The color to treat as transparent
 * @throws SlickException Indicates a failure to load the image
 */
public Image(String ref, boolean flipped, int f, Color transparent) throws SlickException {
	this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
	this.transparent = transparent;
	this.flipped = flipped;
	
	try {
		this.ref = ref;
		int[] trans = null;
		if (transparent != null) {
			trans = new int[3];
			trans[0] = (int) (transparent.r * 255);
			trans[1] = (int) (transparent.g * 255);
			trans[2] = (int) (transparent.b * 255);
		}
		texture = InternalTextureLoader.get().getTexture(ref, flipped, filter, trans);
	} catch (IOException e) {
		Log.error(e);
		throw new SlickException("Failed to load image from: "+ref, e);
	}
}
 
Example 4
Source Project: opsu   Source File: Image.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Load the image
 * 
 * @param in The input stream to read the image from
 * @param ref The name that should be assigned to the image
 * @param flipped True if the image should be flipped on the y-axis  on load
 * @param f The filter to use when scaling this image
 * @param transparent The color to treat as transparent
 * @throws SlickException Indicates a failure to load the image
 */
private void load(InputStream in, String ref, boolean flipped, int f, Color transparent) throws SlickException {
	this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
	
	try {
		this.ref = ref;
		int[] trans = null;
		if (transparent != null) {
			trans = new int[3];
			trans[0] = (int) (transparent.r * 255);
			trans[1] = (int) (transparent.g * 255);
			trans[2] = (int) (transparent.b * 255);
		}
		texture = InternalTextureLoader.get().getTexture(in, ref, flipped, filter, trans);
	} catch (IOException e) {
		Log.error(e);
		throw new SlickException("Failed to load image from: "+ref, e);
	}
}
 
Example 5
Source Project: slick2d-maven   Source File: Image.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create an image based on a file at the specified location
 * 
 * @param ref The location of the image file to load
 * @param flipped True if the image should be flipped on the y-axis on load
 * @param f The filtering method to use when scaling this image
 * @param transparent The color to treat as transparent
 * @throws SlickException Indicates a failure to load the image
 */
public Image(String ref, boolean flipped, int f, Color transparent) throws SlickException {
	this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
	this.transparent = transparent;
	this.flipped = flipped;
	
	try {
		this.ref = ref;
		int[] trans = null;
		if (transparent != null) {
			trans = new int[3];
			trans[0] = (int) (transparent.r * 255);
			trans[1] = (int) (transparent.g * 255);
			trans[2] = (int) (transparent.b * 255);
		}
		texture = InternalTextureLoader.get().getTexture(ref, flipped, filter, trans);
	} catch (IOException e) {
		Log.error(e);
		throw new SlickException("Failed to load image from: "+ref, e);
	}
}
 
Example 6
Source Project: slick2d-maven   Source File: Image.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Load the image
 * 
 * @param in The input stream to read the image from
 * @param ref The name that should be assigned to the image
 * @param flipped True if the image should be flipped on the y-axis  on load
 * @param f The filter to use when scaling this image
 * @param transparent The color to treat as transparent
 * @throws SlickException Indicates a failure to load the image
 */
private void load(InputStream in, String ref, boolean flipped, int f, Color transparent) throws SlickException {
	this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
	
	try {
		this.ref = ref;
		int[] trans = null;
		if (transparent != null) {
			trans = new int[3];
			trans[0] = (int) (transparent.r * 255);
			trans[1] = (int) (transparent.g * 255);
			trans[2] = (int) (transparent.b * 255);
		}
		texture = InternalTextureLoader.get().getTexture(in, ref, flipped, filter, trans);
	} catch (IOException e) {
		Log.error(e);
		throw new SlickException("Failed to load image from: "+ref, e);
	}
}
 
Example 7
/**
    * Reload a given texture blob
    * 
    * @param texture The texture being reloaded
    * @param srcPixelFormat The source pixel format
    * @param componentCount The component count
    * @param minFilter The minification filter
    * @param magFilter The magnification filter 
    * @param textureBuffer The pixel data 
    * @return The ID of the newly created texture
    */
public int reload(TextureImpl texture, int srcPixelFormat, int componentCount,
		int minFilter, int magFilter, ByteBuffer textureBuffer) {
   	int target = SGL.GL_TEXTURE_2D;
       int textureID = createTextureID(); 
       GL.glBindTexture(target, textureID); 
       
       GL.glTexParameteri(target, SGL.GL_TEXTURE_MIN_FILTER, minFilter); 
       GL.glTexParameteri(target, SGL.GL_TEXTURE_MAG_FILTER, magFilter); 
       
       // produce a texture from the byte buffer
       GL.glTexImage2D(target, 
                     0, 
                     dstPixelFormat, 
                     texture.getTextureWidth(), 
                     texture.getTextureHeight(), 
                     0, 
                     srcPixelFormat, 
                     SGL.GL_UNSIGNED_BYTE, 
                     textureBuffer); 
       
       return textureID; 
}
 
Example 8
/**
 * Draw the the given shape filled in.  Only the vertices are set.  
 * The colour has to be set independently of this method.
 * 
 * @param shape The shape to fill.
 * @param callback The callback that will be invoked for each shape point
 */
private static final void fill(Shape shape, PointCallback callback) {
	Triangulator tris = shape.getTriangles();

    GL.glBegin(SGL.GL_TRIANGLES);
    for (int i=0;i<tris.getTriangleCount();i++) {
    	for (int p=0;p<3;p++) {
    		float[] pt = tris.getTrianglePoint(i, p);
    		float[] np = callback.preRenderPoint(shape, pt[0],pt[1]);
    		
    		if (np == null) {
    			GL.glVertex2f(pt[0],pt[1]);
    		} else {
    			GL.glVertex2f(np[0],np[1]);
    		}
    	}
    }
    GL.glEnd();
}
 
Example 9
/**
 * Loads a single glyph to the backing texture, if it fits.
 * 
 * @param glyph The glyph to be rendered
 * @param width The expected width of the glyph
 * @param height The expected height of the glyph
 * @throws SlickException if the glyph could not be rendered.
 */
private void renderGlyph(Glyph glyph, int width, int height) throws SlickException {
	// Draw the glyph to the scratch image using Java2D.
	scratchGraphics.setComposite(AlphaComposite.Clear);
	scratchGraphics.fillRect(0, 0, MAX_GLYPH_SIZE, MAX_GLYPH_SIZE);
	scratchGraphics.setComposite(AlphaComposite.SrcOver);
	scratchGraphics.setColor(java.awt.Color.white);
	for (Iterator iter = unicodeFont.getEffects().iterator(); iter.hasNext();)
		((Effect)iter.next()).draw(scratchImage, scratchGraphics, unicodeFont, glyph);
	glyph.setShape(null); // The shape will never be needed again.

	WritableRaster raster = scratchImage.getRaster();
	int[] row = new int[width];
	for (int y = 0; y < height; y++) {
		raster.getDataElements(0, y, width, 1, row);
		scratchIntBuffer.put(row);
	}
	GL.glTexSubImage2D(SGL.GL_TEXTURE_2D, 0, pageX, pageY, width, height, SGL.GL_BGRA, SGL.GL_UNSIGNED_BYTE,
		scratchByteBuffer);
	scratchIntBuffer.clear();

	glyph.setImage(pageImage.getSubImage(pageX, pageY, width, height));
}
 
Example 10
/**
 * Set clipping that controls which areas of the world will be drawn to.
 * Note that world clip is different from standard screen clip in that it's
 * defined in the space of the current world coordinate - i.e. it's affected
 * by translate, rotate, scale etc.
 * 
 * @param x
 *            The x coordinate of the top left corner of the allowed area
 * @param y
 *            The y coordinate of the top left corner of the allowed area
 * @param width
 *            The width of the allowed area
 * @param height
 *            The height of the allowed area
 */
public void setWorldClip(float x, float y, float width, float height) {
	predraw();
	worldClipRecord = new Rectangle(x, y, width, height);
	
	GL.glEnable(SGL.GL_CLIP_PLANE0);
	worldClip.put(1).put(0).put(0).put(-x).flip();
	GL.glClipPlane(SGL.GL_CLIP_PLANE0, worldClip);
	GL.glEnable(SGL.GL_CLIP_PLANE1);
	worldClip.put(-1).put(0).put(0).put(x + width).flip();
	GL.glClipPlane(SGL.GL_CLIP_PLANE1, worldClip);

	GL.glEnable(SGL.GL_CLIP_PLANE2);
	worldClip.put(0).put(1).put(0).put(-y).flip();
	GL.glClipPlane(SGL.GL_CLIP_PLANE2, worldClip);
	GL.glEnable(SGL.GL_CLIP_PLANE3);
	worldClip.put(0).put(-1).put(0).put(y + height).flip();
	GL.glClipPlane(SGL.GL_CLIP_PLANE3, worldClip);
	postdraw();
}
 
Example 11
Source Project: opsu-dance   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the image filtering to be used. Note that this will also affect any
 * image that was derived from this one (i.e. sub-images etc)
 * 
 * @param f The filtering mode to use
 */
public void setFilter(int f) {
	this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;

	texture.bind();
	GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_MIN_FILTER, filter); 
       GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_MAG_FILTER, filter); 
}
 
Example 12
Source Project: opsu-dance   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create an empty image
 * 
 * @param width The width of the image
 * @param height The height of the image
 * @param f The filter to apply to scaling the new image
 * @throws SlickException Indicates a failure to create the underlying resource
 */
public Image(int width, int height, int f) throws SlickException {
	ref = super.toString();
	this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
	
	try {
		texture = InternalTextureLoader.get().createTexture(width, height, this.filter);
	} catch (IOException e) {
		Log.error(e);
		throw new SlickException("Failed to create empty image "+width+"x"+height);
	}
	
	init();
}
 
Example 13
Source Project: opsu-dance   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create an image from a image data source. Note that this method uses 
 * 
 * @param data The pixelData to use to create the image
 * @param f The filter to use when scaling this image
 */
public Image(ImageData data, int f) {
	try {
		this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
		texture = InternalTextureLoader.get().getTexture(data, this.filter);
		ref = texture.toString();
	} catch (IOException e) {
		Log.error(e);
	}
}
 
Example 14
Source Project: opsu-dance   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Clamp the loaded texture to it's edges
 */
public void clampTexture() {
       if (GL.canTextureMirrorClamp()) {
       	GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT);
       	GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT);
       } else {
       	GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_CLAMP);
       	GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_CLAMP);
       }
}
 
Example 15
Source Project: opsu-dance   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draw this image at a specified location and size
 * 
 * @param x The x location to draw the image at
 * @param y The y location to draw the image at
 * @param width The width to render the image at
 * @param height The height to render the image at
 * @param filter The color to filter with while drawing
 */
@Override
   public void draw(float x,float y,float width,float height,Color filter) { 
   	if (alpha != 1) {
   		if (filter == null) {
   			filter = Color.white;
   		}
   		
   		filter = new Color(filter);
   		filter.a *= alpha;
   	}
       if (filter != null) { 
           filter.bind(); 
       } 
      
       texture.bind(); 
       
       GL.glTranslatef(x, y, 0);
       if (angle != 0) {
        GL.glTranslatef(centerX, centerY, 0.0f); 
        GL.glRotatef(angle, 0.0f, 0.0f, 1.0f); 
        GL.glTranslatef(-centerX, -centerY, 0.0f); 
       }
       
       GL.glBegin(SGL.GL_QUADS); 
           drawEmbedded(0,0,width,height); 
       GL.glEnd(); 
       
       if (angle != 0) {
        GL.glTranslatef(centerX, centerY, 0.0f); 
        GL.glRotatef(-angle, 0.0f, 0.0f, 1.0f); 
        GL.glTranslatef(-centerX, -centerY, 0.0f); 
       }
       GL.glTranslatef(-x, -y, 0);
   }
 
Example 16
Source Project: opsu-dance   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draw this image at a specified location and size as a silohette
 * 
 * @param x The x location to draw the image at
 * @param y The y location to draw the image at
 * @param width The width to render the image at
 * @param height The height to render the image at
 * @param col The color for the sillohette
 */
public void drawFlash(float x,float y,float width,float height, Color col) {
	init();
	
	col.bind();
	texture.bind();

	if (GL.canSecondaryColor()) {
		GL.glEnable(SGL.GL_COLOR_SUM_EXT);
		GL.glSecondaryColor3ubEXT((byte)(col.r * 255), 
												 (byte)(col.g * 255), 
												 (byte)(col.b * 255));
	}
	
	GL.glTexEnvi(SGL.GL_TEXTURE_ENV, SGL.GL_TEXTURE_ENV_MODE, SGL.GL_MODULATE);

       GL.glTranslatef(x, y, 0);
       if (angle != 0) {
        GL.glTranslatef(centerX, centerY, 0.0f); 
        GL.glRotatef(angle, 0.0f, 0.0f, 1.0f); 
        GL.glTranslatef(-centerX, -centerY, 0.0f); 
       }
       
	GL.glBegin(SGL.GL_QUADS);
		drawEmbedded(0,0,width,height);
	GL.glEnd();

       if (angle != 0) {
        GL.glTranslatef(centerX, centerY, 0.0f); 
        GL.glRotatef(-angle, 0.0f, 0.0f, 1.0f); 
        GL.glTranslatef(-centerX, -centerY, 0.0f); 
       }
       GL.glTranslatef(-x, -y, 0);
       
	if (GL.canSecondaryColor()) {
		GL.glDisable(SGL.GL_COLOR_SUM_EXT);
	}
}
 
Example 17
Source Project: opsu-dance   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
	 * Draw a section of this image at a particular location and scale on the screen
	 * 
	 * @param x The x position to draw the image
	 * @param y The y position to draw the image
	 * @param x2 The x position of the bottom right corner of the drawn image
	 * @param y2 The y position of the bottom right corner of the drawn image
	 * @param srcx The x position of the rectangle to draw from this image (i.e. relative to this image)
	 * @param srcy The y position of the rectangle to draw from this image (i.e. relative to this image)
	 * @param srcx2 The x position of the bottom right cornder of rectangle to draw from this image (i.e. relative to this image)
	 * @param srcy2 The t position of the bottom right cornder of rectangle to draw from this image (i.e. relative to this image)
	 * @param filter The colour filter to apply when drawing
	 */
	public void draw(float x, float y, float x2, float y2, float srcx, float srcy, float srcx2, float srcy2, Color filter) {
		init();

    	if (alpha != 1) {
    		if (filter == null) {
    			filter = Color.white;
    		}
    		
    		filter = new Color(filter);
    		filter.a *= alpha;
    	}
		filter.bind();
		texture.bind();
		
        GL.glTranslatef(x, y, 0);
        if (angle != 0) {
	        GL.glTranslatef(centerX, centerY, 0.0f); 
	        GL.glRotatef(angle, 0.0f, 0.0f, 1.0f); 
	        GL.glTranslatef(-centerX, -centerY, 0.0f); 
        }
        
        GL.glBegin(SGL.GL_QUADS); 
			drawEmbedded(0,0,x2-x,y2-y,srcx,srcy,srcx2,srcy2);
        GL.glEnd(); 
        
        if (angle != 0) {
	        GL.glTranslatef(centerX, centerY, 0.0f); 
	        GL.glRotatef(-angle, 0.0f, 0.0f, 1.0f); 
	        GL.glTranslatef(-centerX, -centerY, 0.0f); 
        }
        GL.glTranslatef(-x, -y, 0);
        
//		GL.glBegin(SGL.GL_QUADS);
//		drawEmbedded(x,y,x2,y2,srcx,srcy,srcx2,srcy2);
//		GL.glEnd();
	}
 
Example 18
Source Project: opsu-dance   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draw the image in a warper rectangle. The effects this can 
 * have are many and varied, might be interesting though.
 * 
 * @param x1 The top left corner x coordinate
 * @param y1 The top left corner y coordinate
 * @param x2 The top right corner x coordinate
 * @param y2 The top right corner y coordinate
 * @param x3 The bottom right corner x coordinate
 * @param y3 The bottom right corner y coordinate
 * @param x4 The bottom left corner x coordinate
 * @param y4 The bottom left corner y coordinate
 */
public void drawWarped(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
       Color.white.bind();
       texture.bind();

       GL.glTranslatef(x1, y1, 0);
       if (angle != 0) {
           GL.glTranslatef(centerX, centerY, 0.0f);
           GL.glRotatef(angle, 0.0f, 0.0f, 1.0f);
           GL.glTranslatef(-centerX, -centerY, 0.0f);
       }

       GL.glBegin(SGL.GL_QUADS);
       init();

       GL.glTexCoord2f(textureOffsetX, textureOffsetY);
       GL.glVertex3f(0, 0, 0);
       GL.glTexCoord2f(textureOffsetX, textureOffsetY + textureHeight);
       GL.glVertex3f(x2 - x1, y2 - y1, 0);
       GL.glTexCoord2f(textureOffsetX + textureWidth, textureOffsetY
               + textureHeight);
       GL.glVertex3f(x3 - x1, y3 - y1, 0);
       GL.glTexCoord2f(textureOffsetX + textureWidth, textureOffsetY);
       GL.glVertex3f(x4 - x1, y4 - y1, 0);
       GL.glEnd();

       if (angle != 0) {
           GL.glTranslatef(centerX, centerY, 0.0f);
           GL.glRotatef(-angle, 0.0f, 0.0f, 1.0f);
           GL.glTranslatef(-centerX, -centerY, 0.0f);
       }
       GL.glTranslatef(-x1, -y1, 0);
   }
 
Example 19
Source Project: opsu-dance   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Start using this sheet. This method can be used for optimal rendering of a collection 
 * of sprites from a single sprite sheet. First, startUse(). Then render each sprite by
 * calling renderInUse(). Finally, endUse(). Between start and end there can be no rendering
 * of other sprites since the rendering is locked for this sprite sheet.
 */
public void startUse() {
	if (inUse != null) {
		throw new RuntimeException("Attempt to start use of a sprite sheet before ending use with another - see endUse()");
	}
	inUse = this;
	init();

	Color.white.bind();
	texture.bind();
	GL.glBegin(SGL.GL_QUADS);
}
 
Example 20
Source Project: opsu-dance   Source File: MainMenu.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void drawMenuButton(
	Image img,
	int x,
	int y,
	int clipxtop,
	int clipxbot,
	Color col)
{
	col.bind();
	final Texture t = img.getTexture();
	t.bind(); 
	
	final int width = img.getWidth();
	final int height = img.getHeight();
	final float twidth = t.getWidth();
	final float theight = t.getHeight();
	y -= height / 2;
	
	final float texXtop = clipxtop > 0 ? (float) clipxtop / width * twidth : 0f;
	final float texXbot = clipxbot > 0 ? (float) clipxbot / width * twidth : 0f;

	GL11.glBegin(SGL.GL_QUADS); 
	GL11.glTexCoord2f(texXtop, 0);
	GL11.glVertex3i(x + clipxtop, y, 0);
	GL11.glTexCoord2f(twidth, 0);
	GL11.glVertex3i(x + width, y, 0);
	GL11.glTexCoord2f(twidth, theight);
	GL11.glVertex3i(x + width, y + height, 0);
	GL11.glTexCoord2f(texXbot, theight);
	GL11.glVertex3i(x + clipxbot, y + height, 0);
	GL11.glEnd(); 
}
 
Example 21
Source Project: opsu   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set the image filtering to be used. Note that this will also affect any
 * image that was derived from this one (i.e. sub-images etc)
 * 
 * @param f The filtering mode to use
 */
public void setFilter(int f) {
	this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;

	texture.bind();
	GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_MIN_FILTER, filter); 
       GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_MAG_FILTER, filter); 
}
 
Example 22
Source Project: opsu   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create an empty image
 * 
 * @param width The width of the image
 * @param height The height of the image
 * @param f The filter to apply to scaling the new image
 * @throws SlickException Indicates a failure to create the underlying resource
 */
public Image(int width, int height, int f) throws SlickException {
	ref = super.toString();
	this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
	
	try {
		texture = InternalTextureLoader.get().createTexture(width, height, this.filter);
	} catch (IOException e) {
		Log.error(e);
		throw new SlickException("Failed to create empty image "+width+"x"+height);
	}
	
	init();
}
 
Example 23
Source Project: opsu   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create an image from a image data source. Note that this method uses 
 * 
 * @param data The pixelData to use to create the image
 * @param f The filter to use when scaling this image
 */
public Image(ImageData data, int f) {
	try {
		this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST;
		texture = InternalTextureLoader.get().getTexture(data, this.filter);
		ref = texture.toString();
	} catch (IOException e) {
		Log.error(e);
	}
}
 
Example 24
Source Project: opsu   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Clamp the loaded texture to it's edges
 */
public void clampTexture() {
       if (GL.canTextureMirrorClamp()) {
       	GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT);
       	GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT);
       } else {
       	GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_CLAMP);
       	GL.glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_CLAMP);
       }
}
 
Example 25
Source Project: opsu   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draw this image at a specified location and size
 * 
 * @param x The x location to draw the image at
 * @param y The y location to draw the image at
 * @param width The width to render the image at
 * @param height The height to render the image at
 * @param filter The color to filter with while drawing
 */
@Override
   public void draw(float x,float y,float width,float height,Color filter) { 
   	if (alpha != 1) {
   		if (filter == null) {
   			filter = Color.white;
   		}
   		
   		filter = new Color(filter);
   		filter.a *= alpha;
   	}
       if (filter != null) { 
           filter.bind(); 
       } 
      
       texture.bind(); 
       
       GL.glTranslatef(x, y, 0);
       if (angle != 0) {
        GL.glTranslatef(centerX, centerY, 0.0f); 
        GL.glRotatef(angle, 0.0f, 0.0f, 1.0f); 
        GL.glTranslatef(-centerX, -centerY, 0.0f); 
       }
       
       GL.glBegin(SGL.GL_QUADS); 
           drawEmbedded(0,0,width,height); 
       GL.glEnd(); 
       
       if (angle != 0) {
        GL.glTranslatef(centerX, centerY, 0.0f); 
        GL.glRotatef(-angle, 0.0f, 0.0f, 1.0f); 
        GL.glTranslatef(-centerX, -centerY, 0.0f); 
       }
       GL.glTranslatef(-x, -y, 0);
   }
 
Example 26
Source Project: opsu   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draw this image at a specified location and size as a silohette
 * 
 * @param x The x location to draw the image at
 * @param y The y location to draw the image at
 * @param width The width to render the image at
 * @param height The height to render the image at
 * @param col The color for the sillohette
 */
public void drawFlash(float x,float y,float width,float height, Color col) {
	init();
	
	col.bind();
	texture.bind();

	if (GL.canSecondaryColor()) {
		GL.glEnable(SGL.GL_COLOR_SUM_EXT);
		GL.glSecondaryColor3ubEXT((byte)(col.r * 255), 
												 (byte)(col.g * 255), 
												 (byte)(col.b * 255));
	}
	
	GL.glTexEnvi(SGL.GL_TEXTURE_ENV, SGL.GL_TEXTURE_ENV_MODE, SGL.GL_MODULATE);

       GL.glTranslatef(x, y, 0);
       if (angle != 0) {
        GL.glTranslatef(centerX, centerY, 0.0f); 
        GL.glRotatef(angle, 0.0f, 0.0f, 1.0f); 
        GL.glTranslatef(-centerX, -centerY, 0.0f); 
       }
       
	GL.glBegin(SGL.GL_QUADS);
		drawEmbedded(0,0,width,height);
	GL.glEnd();

       if (angle != 0) {
        GL.glTranslatef(centerX, centerY, 0.0f); 
        GL.glRotatef(-angle, 0.0f, 0.0f, 1.0f); 
        GL.glTranslatef(-centerX, -centerY, 0.0f); 
       }
       GL.glTranslatef(-x, -y, 0);
       
	if (GL.canSecondaryColor()) {
		GL.glDisable(SGL.GL_COLOR_SUM_EXT);
	}
}
 
Example 27
Source Project: opsu   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
	 * Draw a section of this image at a particular location and scale on the screen
	 * 
	 * @param x The x position to draw the image
	 * @param y The y position to draw the image
	 * @param x2 The x position of the bottom right corner of the drawn image
	 * @param y2 The y position of the bottom right corner of the drawn image
	 * @param srcx The x position of the rectangle to draw from this image (i.e. relative to this image)
	 * @param srcy The y position of the rectangle to draw from this image (i.e. relative to this image)
	 * @param srcx2 The x position of the bottom right cornder of rectangle to draw from this image (i.e. relative to this image)
	 * @param srcy2 The t position of the bottom right cornder of rectangle to draw from this image (i.e. relative to this image)
	 * @param filter The colour filter to apply when drawing
	 */
	public void draw(float x, float y, float x2, float y2, float srcx, float srcy, float srcx2, float srcy2, Color filter) {
		init();

    	if (alpha != 1) {
    		if (filter == null) {
    			filter = Color.white;
    		}
    		
    		filter = new Color(filter);
    		filter.a *= alpha;
    	}
		filter.bind();
		texture.bind();
		
        GL.glTranslatef(x, y, 0);
        if (angle != 0) {
	        GL.glTranslatef(centerX, centerY, 0.0f); 
	        GL.glRotatef(angle, 0.0f, 0.0f, 1.0f); 
	        GL.glTranslatef(-centerX, -centerY, 0.0f); 
        }
        
        GL.glBegin(SGL.GL_QUADS); 
			drawEmbedded(0,0,x2-x,y2-y,srcx,srcy,srcx2,srcy2);
        GL.glEnd(); 
        
        if (angle != 0) {
	        GL.glTranslatef(centerX, centerY, 0.0f); 
	        GL.glRotatef(-angle, 0.0f, 0.0f, 1.0f); 
	        GL.glTranslatef(-centerX, -centerY, 0.0f); 
        }
        GL.glTranslatef(-x, -y, 0);
        
//		GL.glBegin(SGL.GL_QUADS);
//		drawEmbedded(x,y,x2,y2,srcx,srcy,srcx2,srcy2);
//		GL.glEnd();
	}
 
Example 28
Source Project: opsu   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draw the image in a warper rectangle. The effects this can 
 * have are many and varied, might be interesting though.
 * 
 * @param x1 The top left corner x coordinate
 * @param y1 The top left corner y coordinate
 * @param x2 The top right corner x coordinate
 * @param y2 The top right corner y coordinate
 * @param x3 The bottom right corner x coordinate
 * @param y3 The bottom right corner y coordinate
 * @param x4 The bottom left corner x coordinate
 * @param y4 The bottom left corner y coordinate
 */
public void drawWarped(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) {
       Color.white.bind();
       texture.bind();

       GL.glTranslatef(x1, y1, 0);
       if (angle != 0) {
           GL.glTranslatef(centerX, centerY, 0.0f);
           GL.glRotatef(angle, 0.0f, 0.0f, 1.0f);
           GL.glTranslatef(-centerX, -centerY, 0.0f);
       }

       GL.glBegin(SGL.GL_QUADS);
       init();

       GL.glTexCoord2f(textureOffsetX, textureOffsetY);
       GL.glVertex3f(0, 0, 0);
       GL.glTexCoord2f(textureOffsetX, textureOffsetY + textureHeight);
       GL.glVertex3f(x2 - x1, y2 - y1, 0);
       GL.glTexCoord2f(textureOffsetX + textureWidth, textureOffsetY
               + textureHeight);
       GL.glVertex3f(x3 - x1, y3 - y1, 0);
       GL.glTexCoord2f(textureOffsetX + textureWidth, textureOffsetY);
       GL.glVertex3f(x4 - x1, y4 - y1, 0);
       GL.glEnd();

       if (angle != 0) {
           GL.glTranslatef(centerX, centerY, 0.0f);
           GL.glRotatef(-angle, 0.0f, 0.0f, 1.0f);
           GL.glTranslatef(-centerX, -centerY, 0.0f);
       }
       GL.glTranslatef(-x1, -y1, 0);
   }
 
Example 29
Source Project: opsu   Source File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Start using this sheet. This method can be used for optimal rendering of a collection 
 * of sprites from a single sprite sheet. First, startUse(). Then render each sprite by
 * calling renderInUse(). Finally, endUse(). Between start and end there can be no rendering
 * of other sprites since the rendering is locked for this sprite sheet.
 */
public void startUse() {
	if (inUse != null) {
		throw new RuntimeException("Attempt to start use of a sprite sheet before ending use with another - see endUse()");
	}
	inUse = this;
	init();

	Color.white.bind();
	texture.bind();
	GL.glBegin(SGL.GL_QUADS);
}
 
Example 30
/**
 * @see Font#drawString(float, float, String, org.newdawn.slick.Color, int, int)
 */
public void drawString(float x, float y, String whatchars,
		org.newdawn.slick.Color color, int startIndex, int endIndex) {
	color.bind();
	fontTexture.bind();

	IntObject intObject = null;
	int charCurrent;

	GL.glBegin(SGL.GL_QUADS);

	int totalwidth = 0;
	for (int i = 0; i < whatchars.length(); i++) {
		charCurrent = whatchars.charAt(i);
		if (charCurrent < 256) {
			intObject = charArray[charCurrent];
		} else {
			intObject = (IntObject)customChars.get( new Character( (char) charCurrent ) );
		} 
		
		if( intObject != null ) {
			if ((i >= startIndex) || (i <= endIndex)) {
				drawQuad((x + totalwidth), y,
						(x + totalwidth + intObject.width),
						(y + intObject.height), intObject.storedX,
						intObject.storedY, intObject.storedX + intObject.width,
						intObject.storedY + intObject.height);
			}
			totalwidth += intObject.width;
		}
	}

	GL.glEnd();
}