Permalink
Browse files

Add default palette and blending

  • Loading branch information...
DarthJDG committed Dec 9, 2012
1 parent a53ffdd commit 2831be790758b9bd5619a37e490f210bac4ab8fd
@@ -25,7 +25,7 @@ public static void main(String[] args) {
Reader dat = null;
try {
dat = new Reader("data/kid.dat");
dat = new Reader("data/prince.dat");
dat.allocateSprites();
System.out.println("Sheets: " + dat.sheets.size());
@@ -44,6 +44,8 @@ public static void main(String[] args) {
}
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
int texId = GL11.glGenTextures();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);
@@ -52,7 +54,7 @@ public static void main(String[] args) {
GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER,
GL11.GL_LINEAR);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, 512, 512, 0,
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, 512, 512, 0,
GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, dat.sheets.get(0).buffer);
// init OpenGL
@@ -156,6 +156,10 @@ public void renderToSheet(SpriteSheet sheet, PaletteResource pal, int sx,
sheetX = sx;
sheetY = sy;
if (pal == null) {
pal = new PaletteResource();
}
try {
int bits = 0;
int val = 0;
@@ -181,11 +185,13 @@ public void renderToSheet(SpriteSheet sheet, PaletteResource pal, int sx,
val >>= bpp;
bits -= bpp;
sheet.drawPixel(xoffs + sx + x, sy + y,
pal.r.get(pixel)
.byteValue(), pal.g.get(pixel)
.byteValue(),
pal.b.get(pixel).byteValue());
if (pixel > 0) {
sheet.drawPixel(xoffs + sx + x, sy + y,
pal.r.get(pixel)
.byteValue(), pal.g.get(pixel)
.byteValue(),
pal.b.get(pixel).byteValue());
}
xoffs--;
}
@@ -209,10 +215,12 @@ public void renderToSheet(SpriteSheet sheet, PaletteResource pal, int sx,
val >>= bpp;
bits -= bpp;
sheet.drawPixel(xoffs + sx + x, sy + y, pal.r
.get(pixel)
.byteValue(), pal.g.get(pixel).byteValue(),
pal.b.get(pixel).byteValue());
if (pixel > 0) {
sheet.drawPixel(xoffs + sx + x, sy + y, pal.r
.get(pixel)
.byteValue(), pal.g.get(pixel).byteValue(),
pal.b.get(pixel).byteValue());
}
xoffs--;
@@ -19,6 +19,23 @@ public PaletteResource(Resource res) {
getPalette();
}
public PaletteResource() {
super();
// Create default palette
r = new ArrayList<Integer>();
g = new ArrayList<Integer>();
b = new ArrayList<Integer>();
r.add(0);
g.add(0);
b.add(0);
r.add(255);
g.add(255);
b.add(255);
}
@Override
public ResourceType getType() {
return ResourceType.PALETTE;
@@ -93,10 +93,8 @@ public void allocateSprites() {
Definition def = dm.getById(filename, res.id);
if (def != null) {
PaletteResource pal = (PaletteResource) getById(def.pal);
if (pal != null) {
image.renderToSheet(selectedSheet, pal, rect.x1,
rect.y1);
}
image.renderToSheet(selectedSheet, pal, rect.x1,
rect.y1);
}
}
}
@@ -22,6 +22,11 @@ public Resource(Resource res) {
buffer = res.buffer;
}
public Resource() {
id = 0;
buffer = null;
}
public ResourceType getType() {
return ResourceType.BINARY;
}

0 comments on commit 2831be7

Please sign in to comment.