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;
static void init() {
// GLUtil.setupDebugMessageCallback();
GLUtil.setupDebugMessageCallback();
paletteTexture = loadTexture("palette");
boxTexture = loadTexture("box");

View File

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

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 876 B