org.newdawn.slick.opengl.Texture Java Examples
The following examples show how to use
org.newdawn.slick.opengl.Texture.
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 File: ShapeRenderer.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Draw the outline of the given shape. Only the vertices are set. * The colour has to be set independently of this method. * * @param shape The shape to draw. */ public static final void draw(Shape shape) { Texture t = TextureImpl.getLastBind(); TextureImpl.bindNone(); float points[] = shape.getPoints(); LSR.start(); for(int i=0;i<points.length;i+=2) { LSR.vertex(points[i], points[i + 1]); } if (shape.closed()) { LSR.vertex(points[0], points[1]); } LSR.end(); if (t == null) { TextureImpl.bindNone(); } else { t.bind(); } }
Example #2
Source File: Sprite.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 6 votes |
/** * Draws the sprite . * * @param x the x * @param y the y * @param depth the depth * @param transform the transform * @param shader the shader */ public void render(float x, float y, float depth, Transform transform, ShaderArgs shader) { if(currentAnimation == null) return; int width = currentAnimation.getWidth(); int height = currentAnimation.getHeight(); int frameX = currentAnimation.getFrame() % currentAnimation.getColumns(); int frameY = currentAnimation.getFrame() / currentAnimation.getColumns(); int offX = currentAnimation.getOffsetX(); int offY = currentAnimation.getOffsetY();; if(transform != null) { if(transform.flipHorizontal) { offX = -offX + width; } if(transform.flipVertical) { offY = -offY + height; } } float x0 = ((float)frameX * width)/currentAnimation.getImageWidth(); float x1 = ((float)(frameX+1) * width)/currentAnimation.getImageWidth(); float y0 = ((float)frameY * height)/currentAnimation.getImageHeight(); float y1 = ((float)(frameY+1) * height)/currentAnimation.getImageHeight(); Texture texture = currentAnimation.getTexture(); Renderer.render(texture, x0, y0, x1, y1, x - offX, y - offY, x + width - offX, y + height - offY, depth, transform, shader, currentAnimation.getBlendMode()); }
Example #3
Source File: PaletteSwapper.java From FEMultiplayer with GNU General Public License v3.0 | 6 votes |
public static ShaderArgs setup(FightUnit u) { Unit unit = u.getUnit(); ShaderArgs args = new ShaderArgs(); if(unit.getTheClass().name.equals("Lord")) return args; String c = unit.functionalClassName(); Texture t = palettes.get(c); if(t == null) return args; if(lookup.get(c) == null) return args; int offset = lookup.get(c).indexOf(unit.name); if(offset < 0) return args; args.programName = "paletteSwap"; args.args = new float[] {t.getTextureWidth(), t.getTextureHeight(), offset, t.getImageWidth()}; GL13.glActiveTexture(GL13.GL_TEXTURE8); t.bind(); GL13.glActiveTexture(GL13.GL_TEXTURE0); return args; }
Example #4
Source File: TurnDisplay.java From FEMultiplayer with GNU General Public License v3.0 | 6 votes |
public TurnDisplay(boolean yourTurn, Color teamColor) { super(0, 0); xpos = -512; renderDepth = 0.0f; Texture t, f; text = new Sprite(); flash = new Sprite(); if(yourTurn) { t = FEResources.getTexture("player_phase"); } else { t = FEResources.getTexture("enemy_phase"); } if(teamColor == Party.TEAM_BLUE) { f = FEResources.getTexture("blue_flash"); } else { f = FEResources.getTexture("red_flash"); } text.addAnimation("default", t); flash.addAnimation("default",f); AudioPlayer.playAudio("turn_change", 1, 1); }
Example #5
Source File: Healthbar.java From FEMultiplayer with GNU General Public License v3.0 | 6 votes |
public void render(){ Renderer.drawRectangle(x-24, y-6, x+85, y+20, renderDepth, FightStage.BORDER_DARK); Renderer.drawRectangle(x-23, y-5, x+84, y+19, renderDepth, FightStage.BORDER_LIGHT); Renderer.drawRectangle(x-22, y-4, x+83, y+18, renderDepth, color); int offY = 0; int offX = 0; int width = FEResources.getBitmapFont("stat_numbers").getStringWidth((int)displayedHealth + ""); if(totalHealth <= 40) { Renderer.drawString("stat_numbers", (int)displayedHealth + "", x-5-width, y-2, renderDepth); } else { Renderer.drawString("stat_numbers", (int)displayedHealth + "", x-5-width, y+2, renderDepth); } for (int hp = 1; hp <= totalHealth; hp++) { Texture t = hp <= displayedHealth ? tickFilled : tickEmpty; Renderer.render(t, 0, 0, 1, 1, x + offX, y + offY, x + offX + 2, y + offY + 6, renderDepth); if(hp == 40){ offY = 8; offX = 0; } else { offX +=2; } } }
Example #6
Source File: Healthbar.java From FEMultiplayer with GNU General Public License v3.0 | 6 votes |
public void render() { int offY = 0; int offX = 0; int width = FEResources.getBitmapFont("stat_numbers").getStringWidth((int)displayedHealth + ""); if(totalHealth <= 40) { Renderer.drawString("stat_numbers", (int)displayedHealth + "", x-5-width, y-2, renderDepth); } else { Renderer.drawString("stat_numbers", (int)displayedHealth + "", x-5-width, y+2, renderDepth); } for (int hp = 1; hp <= totalHealth; hp++) { Texture t = hp <= displayedHealth? filled: empty; Renderer.render(t, 0, 0, 1, 1, x + offX, y + offY, x + offX + 2, y + offY + 6, renderDepth); if(hp == 40){ offY = 8; offX = 0; } else { offX +=2; } } }
Example #7
Source File: Healthbar.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 6 votes |
public void render() { int offY = 0; int offX = 0; int width = FEResources.getBitmapFont("stat_numbers").getStringWidth((int)displayedHealth + ""); if(totalHealth <= 40) { Renderer.drawString("stat_numbers", (int)displayedHealth + "", x-5-width, y-2, renderDepth); } else { Renderer.drawString("stat_numbers", (int)displayedHealth + "", x-5-width, y+2, renderDepth); } for (int hp = 1; hp <= totalHealth; hp++) { Texture t = hp <= displayedHealth? filled: empty; Renderer.render(t, 0, 0, 1, 1, x + offX, y + offY, x + offX + 2, y + offY + 6, renderDepth); if(hp == 40){ offY = 8; offX = 0; } else { offX +=2; } } }
Example #8
Source File: Healthbar.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 6 votes |
public void render(){ Renderer.drawRectangle(x-24, y-6, x+85, y+20, renderDepth, FightStage.BORDER_DARK); Renderer.drawRectangle(x-23, y-5, x+84, y+19, renderDepth, FightStage.BORDER_LIGHT); Renderer.drawRectangle(x-22, y-4, x+83, y+18, renderDepth, color); int offY = 0; int offX = 0; int width = FEResources.getBitmapFont("stat_numbers").getStringWidth((int)displayedHealth + ""); if(totalHealth <= 40) { Renderer.drawString("stat_numbers", (int)displayedHealth + "", x-5-width, y-2, renderDepth); } else { Renderer.drawString("stat_numbers", (int)displayedHealth + "", x-5-width, y+2, renderDepth); } for (int hp = 1; hp <= totalHealth; hp++) { Texture t = hp <= displayedHealth ? tickFilled : tickEmpty; Renderer.render(t, 0, 0, 1, 1, x + offX, y + offY, x + offX + 2, y + offY + 6, renderDepth); if(hp == 40){ offY = 8; offX = 0; } else { offX +=2; } } }
Example #9
Source File: PaletteSwapper.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 6 votes |
/** * Setup. * * @param u the u * @return the shader args */ public static ShaderArgs setup(FightUnit u) { Unit unit = u.getUnit(); ShaderArgs args = new ShaderArgs(); if(unit.getTheClass().name.equals("Lord")) return args; String c = unit.functionalClassName(); Texture t = palettes.get(c); if(t == null) return args; if(lookup.get(c) == null) return args; int offset = lookup.get(c).indexOf(unit.name); if(offset < 0) return args; args.programName = "paletteSwap"; args.args = new float[] {t.getTextureWidth(), t.getTextureHeight(), offset, t.getImageWidth()}; GL13.glActiveTexture(GL13.GL_TEXTURE8); t.bind(); GL13.glActiveTexture(GL13.GL_TEXTURE0); return args; }
Example #10
Source File: Sprite.java From FEMultiplayer with GNU General Public License v3.0 | 6 votes |
/** * Draws the sprite * @param x * @param y * @param depth * @param transform * @param shader */ public void render(float x, float y, float depth, Transform transform, ShaderArgs shader) { if(currentAnimation == null) return; int width = currentAnimation.getWidth(); int height = currentAnimation.getHeight(); int frameX = currentAnimation.getFrame() % currentAnimation.getColumns(); int frameY = currentAnimation.getFrame() / currentAnimation.getColumns(); int offX = currentAnimation.getOffsetX(); int offY = currentAnimation.getOffsetY();; if(transform != null) { if(transform.flipHorizontal) { offX = -offX + width; } if(transform.flipVertical) { offY = -offY + height; } } float x0 = ((float)frameX * width)/currentAnimation.getImageWidth(); float x1 = ((float)(frameX+1) * width)/currentAnimation.getImageWidth(); float y0 = ((float)frameY * height)/currentAnimation.getImageHeight(); float y1 = ((float)(frameY+1) * height)/currentAnimation.getImageHeight(); Texture texture = currentAnimation.getTexture(); Renderer.render(texture, x0, y0, x1, y1, x - offX, y - offY, x + width - offX, y + height - offY, depth, transform, shader); }
Example #11
Source File: PBufferGraphics.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Initialise the PBuffer that will be used to render to * * @throws SlickException */ private void init() throws SlickException { try { Texture tex = InternalTextureLoader.get().createTexture(image.getWidth(), image.getHeight(), image.getFilter()); final RenderTexture rt = new RenderTexture(false, true, false, false, RenderTexture.RENDER_TEXTURE_2D, 0); pbuffer = new Pbuffer(screenWidth, screenHeight, new PixelFormat(8, 0, 0), rt, null); // Initialise state of the pbuffer context. pbuffer.makeCurrent(); initGL(); GL.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID()); pbuffer.releaseTexImage(Pbuffer.FRONT_LEFT_BUFFER); image.draw(0,0); image.setTexture(tex); Display.makeCurrent(); } catch (Exception e) { Log.error(e); throw new SlickException("Failed to create PBuffer for dynamic image. OpenGL driver failure?"); } }
Example #12
Source File: PBufferUniqueGraphics.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Initialise the PBuffer that will be used to render to * * @throws SlickException */ private void init() throws SlickException { try { Texture tex = InternalTextureLoader.get().createTexture(image.getWidth(), image.getHeight(), image.getFilter()); pbuffer = new Pbuffer(screenWidth, screenHeight, new PixelFormat(8, 0, 0), null, null); // Initialise state of the pbuffer context. pbuffer.makeCurrent(); initGL(); image.draw(0,0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID()); GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, 0, 0, tex.getTextureWidth(), tex.getTextureHeight(), 0); image.setTexture(tex); Display.makeCurrent(); } catch (Exception e) { Log.error(e); throw new SlickException("Failed to create PBuffer for dynamic image. OpenGL driver failure?"); } }
Example #13
Source File: Sprite.java From FEMultiplayer with GNU General Public License v3.0 | 5 votes |
/** * Add a new single-image animation. * @param name Name of the animation * @param tex Texture to use as the static image */ public void addAnimation(String name, Texture tex) { Animation anim = new Animation(tex); animations.put(name.toUpperCase(), anim); currentAnimation = anim; curAnimName = name; anim.setSprite(this); }
Example #14
Source File: Animation.java From FEMultiplayer with GNU General Public License v3.0 | 5 votes |
public Animation(Texture t, int width, int height, int length, int columns, int offsetX, int offsetY, float speed) { this(t); this.width = width; this.height = height; this.columns = columns; this.rows = (length/columns)+1; this.length = length; this.speed = speed; this.offsetX = offsetX; this.offsetY = offsetY; this.currentFrame = 0; counter = 0; }
Example #15
Source File: Animation.java From FEMultiplayer with GNU General Public License v3.0 | 5 votes |
public Animation(Texture t, int width, int height, int length, int columns, float speed) { this(t); this.width = width; this.height = height; this.columns = columns; this.rows = (length/columns)+1; this.length = length; this.speed = speed; this.offsetX = 0; this.offsetY = 0; this.currentFrame = 0; counter = 0; }
Example #16
Source File: Animation.java From FEMultiplayer with GNU General Public License v3.0 | 5 votes |
public Animation(Texture t) { texture = t; width = t.getImageWidth(); height = t.getImageHeight(); length = 1; rows = 1; columns = 1; speed = 0; currentFrame = 0; counter = 0; }
Example #17
Source File: AnimationData.java From FEMultiplayer with GNU General Public License v3.0 | 5 votes |
public Texture getTexture() { try { Texture t = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(path)); System.out.println("Loaded "+path); return t; } catch (IOException e) { System.err.println("Texture not found: "+path); e.printStackTrace(); return null; } }
Example #18
Source File: Tileset.java From FEMultiplayer with GNU General Public License v3.0 | 5 votes |
public Tileset(Texture t, int tileWidth, int tileHeight) { tileset = t; this.tileWidth = tileWidth; this.tileHeight = tileHeight; width = tileset.getImageWidth(); height = tileset.getImageHeight(); }
Example #19
Source File: FBOGraphics.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Initialise the FBO that will be used to render to * * @throws SlickException */ private void init() throws SlickException { IntBuffer buffer = BufferUtils.createIntBuffer(1); EXTFramebufferObject.glGenFramebuffersEXT(buffer); FBO = buffer.get(); // for some reason FBOs won't work on textures unless you've absolutely just // created them. try { Texture tex = InternalTextureLoader.get().createTexture(image.getWidth(), image.getHeight(), image.getFilter()); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, FBO); EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, tex.getTextureID(), 0); completeCheck(); unbind(); // Clear our destination area before using it clear(); flush(); // keep hold of the original content drawImage(image, 0, 0); image.setTexture(tex); } catch (Exception e) { throw new SlickException("Failed to create new texture for FBO"); } }
Example #20
Source File: PaletteSwapper.java From FEMultiplayer with GNU General Public License v3.0 | 5 votes |
public static ShaderArgs setup(Unit u) { ShaderArgs args = new ShaderArgs(); int offset = u.getPartyColor().equals(Party.TEAM_BLUE) ? 0 : 1; if(offset == 0) return args; Texture t = palettes.get("overworld"); args.programName = "paletteSwap"; args.args = new float[] {t.getTextureWidth(), t.getTextureHeight(), offset, t.getImageWidth()}; GL13.glActiveTexture(GL13.GL_TEXTURE8); t.bind(); GL13.glActiveTexture(GL13.GL_TEXTURE0); return args; }
Example #21
Source File: TextureManager.java From Slyther with MIT License | 5 votes |
public Texture getTexture(String path) { if (textures.containsKey(path)) { return textures.get(path); } else { try { return textures.put(path, TextureLoader.getTexture("png", TextureManager.class.getResourceAsStream(path))); } catch (IOException e) { Log.error("Failed to load texture {}", path); Log.catching(e); } } return null; }
Example #22
Source File: Tileset.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 5 votes |
/** * Instantiates a new tileset. * * @param t the t * @param tileWidth the tile width * @param tileHeight the tile height */ public Tileset(Texture t, int tileWidth, int tileHeight) { tileset = t; this.tileWidth = tileWidth; this.tileHeight = tileHeight; width = tileset.getImageWidth(); height = tileset.getImageHeight(); }
Example #23
Source File: SpriteSheet.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @see org.newdawn.slick.Image#setTexture(org.newdawn.slick.opengl.Texture) */ public void setTexture(Texture texture) { if (target == this) { super.setTexture(texture); return; } target.setTexture(texture); }
Example #24
Source File: Sprite.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 5 votes |
/** * Add a new single-image animation. * @param name Name of the animation * @param tex Texture to use as the static image */ public void addAnimation(String name, Texture tex) { Animation anim = new Animation(tex, BlendModeArgs.ALPHA_BLEND); animations.put(name.toUpperCase(), anim); currentAnimation = anim; curAnimName = name; anim.setSprite(this); }
Example #25
Source File: TurnDisplay.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 5 votes |
/** * Instantiates a new turn display. * * @param yourTurn the your turn * @param teamColor the team color */ public TurnDisplay(boolean yourTurn, Color teamColor, boolean spec) { super(0, 0); xpos = -512; renderDepth = 0.0f; Texture t, f; text = new Sprite(); flash = new Sprite(); if(yourTurn) { t = FEResources.getTexture("player_phase"); } else { if(spec){ if(teamColor == Party.TEAM_BLUE) { t = FEResources.getTexture("blue_phase"); } else { t = FEResources.getTexture("red_phase"); } }else{ t = FEResources.getTexture("enemy_phase");} } if(teamColor == Party.TEAM_BLUE) { f = FEResources.getTexture("blue_flash"); } else { f = FEResources.getTexture("red_flash"); } text.addAnimation("default", t); flash.addAnimation("default",f); AudioPlayer.playAudio("turn_change"); }
Example #26
Source File: PaletteSwapper.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 5 votes |
/** * Setup. * * @param u the u * @return the shader args */ public static ShaderArgs setup(Unit u) { ShaderArgs args = new ShaderArgs(); int offset = u.getPartyColor().equals(Party.TEAM_BLUE) ? 0 : 1; if(offset == 0) return args; Texture t = palettes.get("overworld"); args.programName = "paletteSwap"; args.args = new float[] {t.getTextureWidth(), t.getTextureHeight(), offset, t.getImageWidth()}; GL13.glActiveTexture(GL13.GL_TEXTURE8); t.bind(); GL13.glActiveTexture(GL13.GL_TEXTURE0); return args; }
Example #27
Source File: MainMenu.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
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 #28
Source File: AnimationData.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 5 votes |
/** * Gets the texture. * * @return the texture */ public Texture getTexture() { try { Texture t = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(path)); System.out.println("Loaded "+path); return t; } catch (IOException e) { System.err.println("Texture not found: "+path); e.printStackTrace(); return null; } }
Example #29
Source File: Animation.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 5 votes |
/** * Instantiates a new single-frame animation. * * @param t the texture * @param blend the blend mode to use when drawing this animation */ public Animation(Texture t, BlendModeArgs blend) { texture = t; width = t.getImageWidth(); height = t.getImageHeight(); length = 1; rows = 1; columns = 1; speed = 0; currentFrame = 0; counter = 0; this.blend = blend; }
Example #30
Source File: Animation.java From FEMultiPlayer-V2 with GNU General Public License v3.0 | 5 votes |
/** * Instantiates a new animation. * * @param t the t * @param width the width * @param height the height * @param length the length * @param columns the columns * @param speed the speed * @param blend the blend mode to use when drawing this animation */ public Animation(Texture t, int width, int height, int length, int columns, float speed, BlendModeArgs blend) { this(t, blend); this.width = width; this.height = height; this.columns = columns; this.rows = (length/columns)+1; this.length = length; this.speed = speed; this.offsetX = 0; this.offsetY = 0; this.currentFrame = 0; counter = 0; }