Java Code Examples for org.newdawn.slick.Image#getColor()
The following examples show how to use
org.newdawn.slick.Image#getColor() .
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: CurveRenderState.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
/** * Reads the first row of the slider gradient texture and upload it as * a 1D texture to OpenGL if it hasn't already been done. */ public void initGradient() { if (gradientTexture == 0) { Image slider = GameImage.SLIDER_GRADIENT.getImage().getScaledCopy(1.0f / GameImage.getUIscale()); staticState.gradientTexture = GL11.glGenTextures(); ByteBuffer buff = BufferUtils.createByteBuffer(slider.getWidth() * 4); for (int i = 0; i < slider.getWidth(); ++i) { Color col = slider.getColor(i, 0); buff.put((byte) (255 * col.b)); buff.put((byte) (255 * col.b)); // I know this looks strange... buff.put((byte) (255 * col.b)); buff.put((byte) (255 * col.a)); } buff.flip(); GL11.glBindTexture(GL11.GL_TEXTURE_1D, gradientTexture); GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0, GL11.GL_RGBA, slider.getWidth(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buff); EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_1D); } }
Example 2
Source File: LegacyCurveRenderState.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Reads the first row of the slider gradient texture and upload it as * a 1D texture to OpenGL if it hasn't already been done. */ public void initGradient() { if (gradientTexture == 0) { Image slider = GameImage.SLIDER_GRADIENT_EXPERIMENTAL.getImage().getScaledCopy(1.0f / GameImage.getUIscale()); staticState.gradientTexture = GL11.glGenTextures(); ByteBuffer buff = BufferUtils.createByteBuffer(slider.getWidth() * 4); for (int i = 0; i < slider.getWidth(); ++i) { Color col = slider.getColor(i, 0); buff.put((byte) (255 * col.r)); buff.put((byte) (255 * col.g)); buff.put((byte) (255 * col.b)); buff.put((byte) (255 * col.a)); } buff.flip(); GL11.glBindTexture(GL11.GL_TEXTURE_1D, gradientTexture); GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0, GL11.GL_RGBA, slider.getWidth(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buff); EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_1D); } }
Example 3
Source File: CurveRenderState.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Reads the first row of the slider gradient texture and upload it as * a 1D texture to OpenGL if it hasn't already been done. */ public void initGradient() { if (gradientTexture == 0) { Image slider = GameImage.SLIDER_GRADIENT.getImage().getScaledCopy(1.0f / GameImage.getUIscale()); staticState.gradientTexture = GL11.glGenTextures(); ByteBuffer buff = BufferUtils.createByteBuffer(slider.getWidth() * 4); for (int i = 0; i < slider.getWidth(); ++i) { Color col = slider.getColor(i, 0); buff.put((byte) (255 * col.r)); buff.put((byte) (255 * col.g)); buff.put((byte) (255 * col.b)); buff.put((byte) (255 * col.a)); } buff.flip(); GL11.glBindTexture(GL11.GL_TEXTURE_1D, gradientTexture); GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0, GL11.GL_RGBA, slider.getWidth(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buff); ContextCapabilities capabilities = GLContext.getCapabilities(); if (capabilities.OpenGL30) { GL30.glGenerateMipmap(GL11.GL_TEXTURE_1D); } else if (capabilities.GL_EXT_framebuffer_object) { EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_1D); } else { GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE); } } }
Example 4
Source File: ImageReadTest.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */ public void init(GameContainer container) throws SlickException { image = new Image("testdata/testcard.png"); read[0] = image.getColor(0, 0); read[1] = image.getColor(30, 40); read[2] = image.getColor(55, 70); read[3] = image.getColor(80, 90); }
Example 5
Source File: TGAWriter.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * @see org.newdawn.slick.imageout.ImageWriter#saveImage(org.newdawn.slick.Image, java.lang.String, java.io.OutputStream, boolean) */ public void saveImage(Image image, String format, OutputStream output, boolean writeAlpha) throws IOException { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(output)); // ID Length out.writeByte((byte) 0); // Color Map out.writeByte((byte) 0); // Image Type out.writeByte((byte) 2); // Color Map - Ignored out.writeShort(flipEndian((short) 0)); out.writeShort(flipEndian((short) 0)); out.writeByte((byte) 0); // X, Y Offset out.writeShort(flipEndian((short) 0)); out.writeShort(flipEndian((short) 0)); // Width, Height, Depth out.writeShort(flipEndian((short) image.getWidth())); out.writeShort(flipEndian((short) image.getHeight())); if (writeAlpha) { out.writeByte((byte) 32); // Image Descriptor (can't be 0 since we're using 32-bit TGAs) // needs to not have 0x20 set to indicate it's not a flipped image out.writeByte((byte) 1); } else { out.writeByte((byte) 24); // Image Descriptor (must be 0 since we're using 24-bit TGAs) // needs to not have 0x20 set to indicate it's not a flipped image out.writeByte((byte) 0); } // Write out the image data Color c; for (int y = image.getHeight()-1; y <= 0; y--) { for (int x = 0; x < image.getWidth(); x++) { c = image.getColor(x, y); out.writeByte((byte) (c.b * 255.0f)); out.writeByte((byte) (c.g * 255.0f)); out.writeByte((byte) (c.r * 255.0f)); if (writeAlpha) { out.writeByte((byte) (c.a * 255.0f)); } } } out.close(); }