Alpha pixel blending completed

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
gpu
sigonasr2 2 years ago
parent 61814de77e
commit d9847a5fa6
  1. 10
      src/sig/JavaProjectTemplate.java
  2. 45
      src/sig/engine/Panel.java

@ -60,7 +60,7 @@ public class JavaProjectTemplate {
game.Draw(100,20,Color.BLACK); game.Draw(100,20,Color.BLACK);
game.Draw_Line(10,10,35,35,Color.BLACK); game.Draw_Line(10,10,35,35,Color.BLACK);
game.Draw_Sprite(450,75,bookSpr); game.Draw_Sprite(450,75,bookSpr,Color.GREEN);
game.Draw_Sprite(450,75+bookSpr.getHeight(),bookSpr,Transform.VERTICAL); game.Draw_Sprite(450,75+bookSpr.getHeight(),bookSpr,Transform.VERTICAL);
game.Draw_Animated_Sprite(pl.x,pl.y,pl.spr,pl.animationFrame); game.Draw_Animated_Sprite(pl.x,pl.y,pl.spr,pl.animationFrame);
@ -68,7 +68,7 @@ public class JavaProjectTemplate {
game.Draw_Text(10,40,"Hello World!",Font.PROFONT_12); game.Draw_Text(10,40,"Hello World!",Font.PROFONT_12);
game.Draw_Text_Ext(10,52,"Hello World 2!",Font.PROFONT_36,Color.MAGENTA); game.Draw_Text_Ext(10,52,"Hello World 2!",Font.PROFONT_36,Color.MAGENTA);
game.Fill_Triangle(160,160,190,190,50,250,Color.RED); game.Fill_Triangle(160,160,190,190,50,250,new Color(255,0,0,150));
game.FillTexturedTriangle( game.FillTexturedTriangle(
List.of( List.of(
@ -83,9 +83,9 @@ public class JavaProjectTemplate {
) )
, ,
List.of( List.of(
Color.BLUE, new Color(0,0,0,0),
Color.BLUE, Color.WHITE,
Color.BLUE Color.RED
), bookSpr); ), bookSpr);
} }

@ -375,8 +375,12 @@ public class Panel extends JPanel implements Runnable,KeyListener {
} }
void Draw(int index, int col) { void Draw(int index, int col) {
if (((col>>>24)&0xff)!=255) {
pixel[index]=ColorLerpNoAlpha(new Color(pixel[index]),new Color(col),((col>>>24)&0xff)/255f).getColor();
} else {
pixel[index]=col; pixel[index]=col;
} }
}
@Override @Override
public void run() { public void run() {
@ -536,33 +540,36 @@ public class Panel extends JPanel implements Runnable,KeyListener {
} }
public void Draw_Sprite(double x, double y, Sprite sprite){ public void Draw_Sprite(double x, double y, Sprite sprite){
Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,Transform.NONE ); Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,Color.WHITE,Transform.NONE);
} }
public void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex){ public void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex){
Rectangle frameRectangle=sprite.getFrame((int)frameIndex); Rectangle frameRectangle=sprite.getFrame((int)frameIndex);
Draw_Sprite_Partial(x,y,frameRectangle.getX(),frameRectangle.getY(),frameRectangle.getWidth(),frameRectangle.getHeight(),sprite,frameIndex,Transform.NONE); Draw_Sprite_Partial(x,y,frameRectangle.getX(),frameRectangle.getY(),frameRectangle.getWidth(),frameRectangle.getHeight(),sprite,frameIndex,Color.WHITE,Transform.NONE);
} }
public void Draw_Sprite(double x, double y, Sprite sprite, Color col){
Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,col,Transform.NONE);
}
public void Draw_Sprite(double x, double y, Sprite sprite, Transform transform){ public void Draw_Sprite(double x, double y, Sprite sprite, Transform transform){
Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,transform); Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,Color.WHITE,transform);
} }
public void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex, Transform transform){ public void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex, Color col, Transform transform){
Rectangle frameRectangle=sprite.getFrame((int)frameIndex); Rectangle frameRectangle=sprite.getFrame((int)frameIndex);
Draw_Sprite_Partial(x,y,frameRectangle.getX(),frameRectangle.getY(),frameRectangle.getWidth(),frameRectangle.getHeight(),sprite,frameIndex, transform); Draw_Sprite_Partial(x,y,frameRectangle.getX(),frameRectangle.getY(),frameRectangle.getWidth(),frameRectangle.getHeight(),sprite,frameIndex,col,transform);
} }
public void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Transform transform){ public void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Color col, Transform transform){
Draw_Sprite_Partial_Ext(x,y,xOffset,yOffset,w,h,sprite,frame_index, Color.WHITE,transform); Draw_Sprite_Partial_Ext(x,y,xOffset,yOffset,w,h,sprite,frame_index, col,transform);
} }
public void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Transform transform){ public void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Color col, Transform transform){
Draw_Sprite_Partial_Ext(x, y, xOffset, yOffset, w, h, sprite, 0, Color.WHITE, transform); Draw_Sprite_Partial_Ext(x, y, xOffset, yOffset, w, h, sprite, 0, col, transform);
} }
public void Draw_Animated_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, AnimatedSprite sprite, double frameIndex, Transform transform){ public void Draw_Animated_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, AnimatedSprite sprite, double frameIndex, Color col, Transform transform){
Rectangle frameRectangle=sprite.getFrame((int)frameIndex); Rectangle frameRectangle=sprite.getFrame((int)frameIndex);
Draw_Sprite_Partial_Ext(x, y, frameRectangle.getX(), frameRectangle.getY(), frameRectangle.getWidth(), frameRectangle.getHeight(), sprite, 0, Color.WHITE, transform); Draw_Sprite_Partial_Ext(x, y, frameRectangle.getX(), frameRectangle.getY(), frameRectangle.getWidth(), frameRectangle.getHeight(), sprite, 0, col, transform);
} }
public void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Color col, Transform transform){ public void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Color col, Transform transform){
@ -585,7 +592,17 @@ public class Panel extends JPanel implements Runnable,KeyListener {
if (((sprite.getImg().getRGB(X,Y)>>>24)&0xFF)==0||index<0||index>=pixel.length) { if (((sprite.getImg().getRGB(X,Y)>>>24)&0xFF)==0||index<0||index>=pixel.length) {
continue; continue;
} else { } else {
Draw(index,(col==Color.WHITE)?sprite.getImg().getRGB(X,Y):col.getColor()); if (col==Color.WHITE) {
Draw(index,sprite.getImg().getRGB(X,Y));
} else {
Color img = new Color(sprite.getImg().getRGB(X,Y));
Draw(index,new Color(
(int)Math.min(255.0f,Math.max(0,(float)img.r * col.r / 255.0f)),
(int)Math.min(255.0f,Math.max(0,(float)img.g * col.g / 255.0f)),
(int)Math.min(255.0f,Math.max(0,(float)img.b * col.b / 255.0f)),
(int)Math.min(255.0f,Math.max(0,(float)img.a * col.a / 255.0f))).getColor()
);
}
} }
} }
} }
@ -994,6 +1011,10 @@ public class Panel extends JPanel implements Runnable,KeyListener {
{ return new Color((int)((c2.r * t) + c1.r * (1.0f - t)),(int)((c2.g * t) + c1.g * (1.0f - t)),(int)((c2.b * t) + c1.b * (1.0f - t)),(int)((c2.a * t) + c1.a * (1.0f - t))); } { return new Color((int)((c2.r * t) + c1.r * (1.0f - t)),(int)((c2.g * t) + c1.g * (1.0f - t)),(int)((c2.b * t) + c1.b * (1.0f - t)),(int)((c2.a * t) + c1.a * (1.0f - t))); }
Color ColorLerpNoAlpha(Color c1, Color c2, float t)
{ return new Color((int)((c2.r * t) + c1.r * (1.0f - t)),(int)((c2.g * t) + c1.g * (1.0f - t)),(int)((c2.b * t) + c1.b * (1.0f - t))); }
public void Clear(Color col){ public void Clear(Color col){
for (int y=0;y<JavaProjectTemplate.WINDOW_HEIGHT;y++) { for (int y=0;y<JavaProjectTemplate.WINDOW_HEIGHT;y++) {
for (int x=0;x<JavaProjectTemplate.WINDOW_WIDTH;x++) { for (int x=0;x<JavaProjectTemplate.WINDOW_WIDTH;x++) {

Loading…
Cancel
Save