Forgot palette

This commit is contained in:
jglrxavpok 2020-08-11 23:39:10 +02:00
parent e04a4fad02
commit c0a704dc56
4 changed files with 14 additions and 14 deletions

View File

@ -68,7 +68,7 @@ public final class OpenGLRendering {
private static int boxTexture; private static int boxTexture;
static void init() { static void init() {
// GLUtil.setupDebugMessageCallback(); GLUtil.setupDebugMessageCallback();
paletteTexture = loadTexture("palette"); paletteTexture = loadTexture("palette");
boxTexture = loadTexture("box"); boxTexture = loadTexture("box");

View File

@ -12,13 +12,13 @@ import java.util.Map;
public class PaletteGenerator { public class PaletteGenerator {
public static void main(String[] args) { public static void main(String[] args) {
Map<Byte, Integer> colors = new HashMap<>(); Map<Integer, Integer> colors = new HashMap<>();
int highestIndex = 0; int highestIndex = 0;
for(MapColors c : MapColors.values()) { for(MapColors c : MapColors.values()) {
for(MapColors.Multiplier m : MapColors.Multiplier.values()) { for(MapColors.Multiplier m : MapColors.Multiplier.values()) {
byte index = m.apply(c); int index = ((int)m.apply(c)) & 0xFF;
if(((int)index & 0xFF) > highestIndex) { if(index > highestIndex) {
highestIndex = ((int)index) & 0xFF; highestIndex = index;
} }
int rgb = MapColors.PreciseMapColor.toRGB(c, m); int rgb = MapColors.PreciseMapColor.toRGB(c, m);
colors.put(index, rgb); colors.put(index, rgb);
@ -27,8 +27,8 @@ public class PaletteGenerator {
BufferedImage paletteTexture = new BufferedImage(highestIndex+1, 1, BufferedImage.TYPE_INT_ARGB); BufferedImage paletteTexture = new BufferedImage(highestIndex+1, 1, BufferedImage.TYPE_INT_ARGB);
for (int i = 0; i <= highestIndex; i++) { for (int i = 0; i <= highestIndex; i++) {
int rgb = colors.getOrDefault((byte)i, 0); int rgb = colors.getOrDefault(i, 0);
int argb = (0xFF << 24) | rgb; int argb = (0xFF << 24) | (rgb & 0xFFFFFF);
paletteTexture.setRGB(i, 0, argb); paletteTexture.setRGB(i, 0, argb);
} }

View File

@ -14,16 +14,16 @@ void main() {
// render in map colors // render in map colors
int closest = 0; int closest = 0;
float distance = 1.0f/0.0f; uint closestDistance = uint(2147483647);
for(int i = 1; i < paletteSize; i++) { for(int i = 1; i < paletteSize; i++) {
vec3 mapColor = texture(palette, vec2(i/paletteSize, 0.0)).rgb; vec3 mapColor = texture(palette, vec2(i/paletteSize, 0.0)).rgb;
float dr = mapColor.r - vertexColor.r; int dr = int((mapColor.r - vertexColor.r)*255);
float dg = mapColor.g - vertexColor.g; int dg = int((mapColor.g - vertexColor.g)*255);
float db = mapColor.b - vertexColor.b; int db = int((mapColor.b - vertexColor.b)*255);
float d = dr*dr+dg*dg+db*db; uint d = uint(dr*dr)+uint(dg*dg)+uint(db*db);
if(d < distance) { if(d < closestDistance) {
distance = d; closestDistance = d;
closest = i; closest = i;
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 876 B