/** * 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?"); } }
/** * 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?"); } }
/** * 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(); } }
/** * get the texture of all image ghost * @return a vector with a texture: * [0] = Im1up, [1] = Im2up * [2] = Im1down, [3] = Im2down * [4] = Im1left, [5] = Im2left * [6] = Im1right, [7] = Im2right * @throws SlickException */ private Texture[] getTextureImage() throws SlickException{ Image Im1up = new Image(PATH_IMAGE.concat(nameGhost).concat("_up1.png")); Image Im2up = new Image(PATH_IMAGE.concat(nameGhost).concat("_up2.png")); Image Im1down = new Image(PATH_IMAGE.concat(nameGhost).concat("_down1.png")); Image Im2down = new Image(PATH_IMAGE.concat(nameGhost).concat("_down2.png")); Image Im1left = new Image(PATH_IMAGE.concat(nameGhost).concat("_left1.png")); Image Im2left = new Image(PATH_IMAGE.concat(nameGhost).concat("_left2.png")); Image Im1right = new Image(PATH_IMAGE.concat(nameGhost).concat("_right1.png")); Image Im2right = new Image(PATH_IMAGE.concat(nameGhost).concat("_right2.png")); Texture []t = new Texture[8]; t[0] = Im1up.getTexture(); t[1] = Im2up.getTexture(); t[2] = Im1down.getTexture(); t[3] = Im2down.getTexture(); t[4] = Im1left.getTexture(); t[5] = Im2left.getTexture(); t[6] = Im1right.getTexture(); t[7] = Im2right.getTexture(); return t; }
public int loadTexture(final String fileName) { Texture texture = null; try (final FileInputStream inputStream = new FileInputStream(getResourcePath("textures/" + fileName + ".png"))) { texture = TextureLoader.getTexture("PNG", inputStream); } catch (final IOException ex) { LOGGER.error("Exception occurred - {} while loading texture file - {}", ex, fileName); } assertTextureNotNullForFileName(texture, fileName); final int textureId = texture.getTextureID(); textures.add(textureId); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT); return textureId; }
public int loadTexture(String fileName) { Texture texture = null; try { texture = TextureLoader.getTexture("PNG", new FileInputStream(Primary.fileHandler.getTexture(fileName))); GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0f); } catch (Exception e) { e.printStackTrace(); System.err.println("Tried to load texture " + fileName + ".png , didn't work"); System.exit(-1); } textures.add(texture.getTextureID()); return texture.getTextureID(); }
/** * 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; }
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; } } }
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; } } }
/** * 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()); }
public int loadTexture(String fileName) { Texture texture = null; try { texture = TextureLoader.getTexture("PNG", new FileInputStream("res/"+fileName +".png")); // Mipmapping to lower resolution of distance textures GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); // Changes the level of detail to change the mipmapping to a slightly higher resolution GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, -0.4f); } catch (IOException e) { e.printStackTrace(); } //TODO fix null assertion int textureID = texture.getTextureID(); textures.add(textureID); return textureID; }
public int loadTexture(String fileName) { Texture texture = null; try { texture = TextureLoader.getTexture("PNG", new FileInputStream(MainGameLoop.fileManager.getTextureFile(fileName))); GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL14.GL_TEXTURE_LOD_BIAS, 0); if (GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic) { float amount = Math.min(4f, GL11.glGetFloat(EXTTextureFilterAnisotropic.GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT)); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, amount); } else { System.out.println("Filter Anisotropic Not Supported"); } } catch (Exception e) { e.printStackTrace(); System.err.println("Tried to load texture " + fileName + ".png , didn't work"); System.exit(-1); } textures.add(texture.getTextureID()); return texture.getTextureID(); }
@Override protected void Init() { try { GL11.glEnable(GL11.GL_TEXTURE_2D); Texture button1 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/Buttons/HMButton1.png"), false, GL11.GL_NEAREST); GUI.AddButton(460, 154, button1.getImageWidth(), button1.getImageHeight(), button1); Texture button2 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/Buttons/HMButton2.png"), false, GL11.GL_NEAREST); GUI.AddButton(460, 214, button2.getImageWidth(), button2.getImageHeight(), button2); Texture button3 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/Buttons/HMButton3.png"), false, GL11.GL_NEAREST); GUI.AddButton(460, 274, button3.getImageWidth(), button3.getImageHeight(), button3); Texture button4 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/Buttons/HMButton4.png"), false, GL11.GL_NEAREST); GUI.AddButton(460, 334, button4.getImageWidth(), button4.getImageHeight(), button4); Texture button5 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/Buttons/Back.png"), false, GL11.GL_NEAREST); GUI.AddButton(460, 394, button5.getImageWidth(), button5.getImageHeight(), button5); BackGroundImage = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/Menus/HMMenu.png"), false, GL11.GL_NEAREST); HeightMap1 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/images/Heightmap1.png")); HeightMap2 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/images/Heightmap2.png")); HeightMap3 = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/images/Heightmap3.png")); } catch (IOException e) { System.out.println("ERROR: Failed to load image @ Menu"); e.printStackTrace(); } }
public GUI_Button(int startX, int startY, int width, int height, Texture t){ int displayWidth = NextPowerOf2(Game.Width); int displayHeight = NextPowerOf2(Game.Height); int gameWidth = Game.Width; int gameHeight = Game.Height; //System.out.println(startX); //System.out.println(gameWidth); //System.out.println(displayWidth); ScreenX=startX; ScreenY=startY; ScreenButtonWidth=width; ScreenButtonHeight=height; StartX=(int) (((float)startX/(float)gameWidth)*(float)displayWidth); StartY=(int) (((float)startY/(float)gameHeight)*(float)displayHeight); Width = (int) (((float)width/(float)gameWidth)*(float)displayWidth); Height=(int) (((float)height/(float)gameHeight)*(float)displayHeight); ScreenWidth=gameWidth; ScreenHeight=gameHeight; texture=t; }
/** * 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); if (image.getTexture()!=null) image.draw(0,0); Graphics.setCurrent(this); //this means you need to call flush() after getGraphics() image.setTexture(tex); Display.makeCurrent(); } catch (Exception e) { Log.error(e); throw new SlickException("Failed to create PBuffer for dynamic image. OpenGL driver failure?"); } }
/** * 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(); if (image.getTexture()!=null) { 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); } Graphics.setCurrent(this); //this means you need to call flush() after getGraphics image.setTexture(tex); Display.makeCurrent(); } catch (Exception e) { Log.error(e); throw new SlickException("Failed to create PBuffer for dynamic image. OpenGL driver failure?"); } }
/** * 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(@Nonnull 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(); } }
/** * Draw the the given shape filled in with a texture. Only the vertices are set. * The colour has to be set independently of this method. * * @param shape The shape to texture. * @param image The image to tile across the shape * @param gen The texture coordinate generator to create coordiantes for the shape */ public static final void texture(@Nonnull final Shape shape, @Nonnull Image image, @Nonnull final TexCoordGenerator gen) { Texture t = TextureImpl.getLastBind(); image.getTexture().bind(); shape.getCenter(); fill(shape, (shape1, x, y) -> { Vector2f tex = gen.getCoordFor(x, y); GL.glTexCoord2f(tex.x, tex.y); return new float[] {x,y}; }); if (t == null) { TextureImpl.bindNone(); } else { t.bind(); } }
@Override public void update() { map = GameVar.getMap(); updateBlt(); if (travelDistance >= bulletRay.length){ Texture tex = map.blockTextures.get(blockToHit.type); // System.out.println(endPoint); if (tex != null) GameVar.tColor = Util.colorAt( (int)(endPoint.x % blockSize)/2, (int)(endPoint.y % blockSize)/2, tex); ParticleEmitter.createSmallExplosion(endPoint); if (blockToHit.isBreakable()) map.damageBlock(blockToHit, 1); // System.out.println("rem"); isDead = true; } }
public static Mesh rectangle(float x, float y, float width, float height, Texture texture){ float texHeight = 1; float texWidth = 1; if (texture != null){ texHeight = texture.getHeight(); texWidth = texture.getWidth(); } Mesh mesh = new Mesh(); Vertex[] vertices = new Vertex[] { new Vertex(x, y, 0, 0), new Vertex(x, y+height, 0, texHeight), new Vertex(x+width, y+height, texWidth, texHeight), new Vertex(x+width, y, texWidth, 0) }; int[] indices = new int[] { 0,1,3, 3,1,2 }; mesh.addVertices(vertices, indices); return mesh; }
public static void drawBackGround(){ initGL(Display.getWidth(),Display.getHeight()); try { Texture background = TextureLoader.getTexture("JPG", ResourceLoader.getResourceAsStream("imgs/Map_test_1.jpg")); background.bind(); glBegin(GL_QUADS); GL11.glTexCoord2f(0,0); GL11.glVertex2f(0,0); GL11.glTexCoord2f(1,0); GL11.glVertex2f(background.getTextureWidth(),0); GL11.glTexCoord2f(1,1); GL11.glVertex2f(background.getTextureWidth(),background.getTextureHeight()); GL11.glTexCoord2f(0,1); GL11.glVertex2f(0,background.getTextureHeight()); GL11.glBindTexture(GL_TEXTURE_2D,0); glEnd(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public static void drawSprites(String spriteLoc) { initGL(Display.getWidth(),Display.getHeight()); try { Texture sprite = TextureLoader.getTexture("JPG", ResourceLoader.getResourceAsStream("imgs/"+spriteLoc)); sprite.bind(); glBegin(GL_QUADS); GL11.glTexCoord2f(0,0); GL11.glVertex2f(0,0); GL11.glTexCoord2f(1,0); GL11.glVertex2f(sprite.getTextureWidth(),0); GL11.glTexCoord2f(1,1); GL11.glVertex2f(sprite.getTextureWidth(),sprite.getTextureHeight()); GL11.glTexCoord2f(0,1); GL11.glVertex2f(0,sprite.getTextureHeight()); GL11.glBindTexture(GL_TEXTURE_2D,0); glEnd(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }