Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add default palette and blending
  • Loading branch information
DarthJDG committed Dec 9, 2012
1 parent a53ffdd commit 2831be7
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/org/openprince/Main.java
Expand Up @@ -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());
Expand All @@ -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);
Expand All @@ -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
Expand Down
26 changes: 17 additions & 9 deletions src/org/openprince/dat/ImageResource.java
Expand Up @@ -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;
Expand All @@ -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--;
}
Expand All @@ -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--;

Expand Down
17 changes: 17 additions & 0 deletions src/org/openprince/dat/PaletteResource.java
Expand Up @@ -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;
Expand Down
6 changes: 2 additions & 4 deletions src/org/openprince/dat/Reader.java
Expand Up @@ -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);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/org/openprince/dat/Resource.java
Expand Up @@ -22,6 +22,11 @@ public Resource(Resource res) {
buffer = res.buffer;
}

public Resource() {
id = 0;
buffer = null;
}

public ResourceType getType() {
return ResourceType.BINARY;
}
Expand Down

0 comments on commit 2831be7

Please sign in to comment.