private void reloadHeightmap() { logger.info("Reading height map '{}'", configuration.heightMap); ResourceUrn urn = new ResourceUrn("core", configuration.heightMap); Texture texture = Assets.getTexture(urn).get(); ByteBuffer[] bb = texture.getData().getBuffers(); IntBuffer intBuf = bb[0].asIntBuffer(); mapWidth = texture.getWidth(); mapHeight = texture.getHeight(); heightmap = new float[mapWidth][mapHeight]; while (intBuf.position() < intBuf.limit()) { int pos = intBuf.position(); long val = intBuf.get() & 0xFFFFFFFFL; heightmap[pos % mapWidth][pos / mapWidth] = val / (256 * 256 * 256 * 256f); } }
public static BufferedImage convertToImage(TextureRegion textureRegion) { final int width = textureRegion.getWidth(); final int height = textureRegion.getHeight(); final Rect2i pixelRegion = textureRegion.getPixelRegion(); final Texture texture = textureRegion.getTexture(); ByteBuffer textureBytes = texture.getData().getBuffers()[0]; int stride = texture.getWidth() * 4; int posX = pixelRegion.minX(); int posY = pixelRegion.minY(); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int r = UnsignedBytes.toInt(textureBytes.get((posY + y) * stride + (posX + x) * 4)); int g = UnsignedBytes.toInt(textureBytes.get((posY + y) * stride + (posX + x) * 4 + 1)); int b = UnsignedBytes.toInt(textureBytes.get((posY + y) * stride + (posX + x) * 4 + 2)); int a = UnsignedBytes.toInt(textureBytes.get((posY + y) * stride + (posX + x) * 4 + 3)); int argb = (a << 24) + (r << 16) + (g << 8) + b; image.setRGB(x, y, argb); } } return image; }
ByteBuffer byteBuffer = texData.getBuffers()[0]; byteBuffer.asIntBuffer().put(data);
final int index = x * strideX + z * strideZ + strideY * y; alignedBuffer.put(data.getBuffers()[0].get(index)); alignedBuffer.put(data.getBuffers()[0].get(index + 1)); alignedBuffer.put(data.getBuffers()[0].get(index + 2)); alignedBuffer.put(data.getBuffers()[0].get(index + 3)); resources.loadedTextureInfo = new LoadedTextureInfo(width, height, 1, data); if (resources.id == 0) { resources.graphicsManager.createTexture2D(data.getBuffers(), getWrapMode(), getFilterMode(), width, height, (newId) -> { synchronized (this) { if (resources.id != 0) { resources.graphicsManager.reloadTexture2D(resources.id, data.getBuffers(), getWrapMode(), getFilterMode(), width, height);
public static MeshData generateIconMeshData(TextureRegion tex, int alphaLimit, boolean withContour, Vector4f colorContour) { ByteBuffer buffer = tex.getTexture().getData().getBuffers()[0];
@Test public void testColorTextures() { Random r = new FastRandom(123456); for (int i = 0; i < 10; i++) { int rgba = r.nextInt(); Color red = new Color(rgba); ResourceUrn textureUriForColor = TextureUtil.getTextureUriForColor(red); String simpleString = textureUriForColor.toString(); Optional<Texture> tex = Assets.getTexture(simpleString); assertTrue(tex.isPresent()); ByteBuffer dataBuffer = tex.get().getData().getBuffers()[0]; int firstPixel = dataBuffer.asIntBuffer().get(0); Assert.assertEquals(rgba, firstPixel); } }
private void testRepeatedColorInDataTexture(Color expectedColor, int expectedRed, int expectedGreen, int expectedBlue, int expectedAlpha) { TextureData textureData = TextureDataFactory.newInstance(expectedColor); ByteBuffer[] buffers = textureData.getBuffers(); assertEquals(1, buffers.length); ByteBuffer buffer = buffers[0]; for (int offsetCounter = 0; offsetCounter < 4 * 16; offsetCounter++) { int offset = offsetCounter * 4; assertEquals(expectedRed, buffer.get(0 + offset)); assertEquals(expectedGreen, buffer.get(1 + offset)); assertEquals(expectedBlue, buffer.get(2 + offset)); assertEquals(expectedAlpha, buffer.get(3 + offset)); } assertEquals(16, textureData.getWidth()); assertEquals(16, textureData.getHeight()); assertEquals(FilterMode.NEAREST, textureData.getFilterMode()); assertEquals(WrapMode.REPEAT, textureData.getWrapMode()); assertEquals(Texture.Type.TEXTURE2D, textureData.getType()); } }