Skip to content

Commit

Permalink
Anisotropic Filtering missing texture generator
Browse files Browse the repository at this point in the history
Closes #24. This code isn't the same as the code used by Minecraft to generate this texture, but the end result is identical.
  • Loading branch information
NeRdTheNed committed Oct 14, 2023
1 parent 4425423 commit 874fbb2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public abstract class AbstractTextureGenerator {
/** The size of a standard image in pixels. */
static final int STANDARD_IMAGE_SIZE = 16 * STANDARD_IMAGE_SIZE_MULTIPLIER;

/** Twice the size of a standard image in pixels. */
static final int STANDARD_IMAGE_SIZE_2X = STANDARD_IMAGE_SIZE * 2;

/** A bit mask of the size of a standard image. */
static final int STANDARD_IMAGE_SIZE_BITMASK = STANDARD_IMAGE_SIZE - 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ private static TextureGroup missingTextureCheckerboard(String name, int colorOne
return new TextureGroup("Missing_Texture_" + name, missingTexture);
}

/**
* Generates a "checkerboard" texture with the provided colors, with twice the usual image resolution.
*
* @param name the name of the returned texture group
* @param colorOne the first color
* @param colorTwo the second color
* @return the generated "checkerboard" texture
*/
private static TextureGroup missingTextureCheckerboard2x(String name, int colorOne, int colorTwo) {
final BufferedImage missingTexture = new BufferedImage(STANDARD_IMAGE_SIZE_2X, STANDARD_IMAGE_SIZE_2X, BufferedImage.TYPE_INT_RGB);
final int[] textureData = ((DataBufferInt) missingTexture.getRaster().getDataBuffer()).getData();

for (int xPixel = 0; xPixel < STANDARD_IMAGE_SIZE_2X; ++xPixel) {
for (int yPixel = 0; yPixel < STANDARD_IMAGE_SIZE_2X; ++yPixel) {
textureData[xPixel + (yPixel * STANDARD_IMAGE_SIZE_2X)] = (xPixel % STANDARD_IMAGE_SIZE < (STANDARD_IMAGE_SIZE / 2)) ^ (yPixel % STANDARD_IMAGE_SIZE < (STANDARD_IMAGE_SIZE / 2)) ? colorOne : colorTwo;
}
}

return new TextureGroup("Missing_Texture_2x_" + name, missingTexture);
}

/**
* Generates a text-based texture with the provided text.
* The generated TextureGroup is JVM / system dependent:
Expand Down Expand Up @@ -135,7 +156,8 @@ public TextureGroup[] getTextureGroups() {
missingTextureText("Java_b1_4_to_13w01b", false, new String[] { "missingtex" }),
missingTextureText("Java_13w02a_to_13w17a", true, new String[] { "missing", "texture"}),
missingTextureCheckerboard("Java_13w18a_to_1_12_2", 0x000000, 0xF800F8),
missingTextureCheckerboard("Java_17w43a_to_current", 0xF800F8, 0x000000)
missingTextureCheckerboard("Java_17w43a_to_current", 0xF800F8, 0x000000),
missingTextureCheckerboard2x("Java_13w38a_to_14w21b", 0x000000, 0xF800F8)
};
}

Expand Down

0 comments on commit 874fbb2

Please sign in to comment.