Monday, December 7, 2009

GfxLib transparency works well

A small video. Shows two semitransparent layers interacting using GfxLib. Also shown is the boot process. Enjoy.






The quickly-written and messy source code to this simple test app is as follows:

#include <kTypes.h>
#include <errors.h>
#include <RtLib.h>
#include <GfxLib.h>



static char __x[128];
#define printf(...) do{sprintf(__x,__VA_ARGS__);_DGOS_DEBUG_TMP_printStr(__x);}while(0)
#define perr(...) do{printf(__VA_ARGS__); while(1) SchedYield();}while(0)

int _start(){

GfxImage* i;
GfxLayer* L;
GfxLayer* L2;
UInt32 iw, ih, sw = 324, sh = 484;
Int32 x = 0, y = 0, dx = 1, dy = 1;
UInt16* d;
Err e;

printf("TEST RUNNING\n");

if(!GfxLayersInit(GFX_LIB_ROTATION_NORMAL)){
perr("cannot init GfxLayers\n");
}

printf("setting color\n");
GfxLayersSetBackground(GfxColorMakeRGB(192,255,192));

printf("creating layer\n");
L2 = GfxLayerCreate(0, 0, 324, 484);
if(!L2) perr("cannot create layer with bg\n");


printf("calculating layer\n");
printf("L=0x%08x\n", L2);
printf("I=0x%08x\n", GfxLayerGetImage(L2));
printf("D=0x%08x\n", GfxImageGetData(GfxLayerGetImage(L2)));
printf("A=0x%08x\n", GfxImageGetAlpha(GfxLayerGetImage(L2)));

d = GfxImageGetData(GfxLayerGetImage(L2));
MemSet(GfxImageGetAlpha(GfxLayerGetImage(L2)), 324*484, 0xFF);

for(y = 0; y < 484; y++){
for(x = 0; x < 324; x++){
UInt32 r,g,b;

r = y * 256 / 484;
g = y * 256 / 484;
b = y * 256 / 484;

r = ((r * x) + (256 * (323 - x))) / 323;
g = ((256 * x) + (g * (323 - x))) / 323;


*d++ = (((y / 10) & 1) == ((x / 10) & 1)) ? \
GfxColorMakeRGB(r,g,b) : \
GfxColorMakeRGB(0,0,b);
}
}

printf("drawing layer\n");
GfxLayerRedraw(L2);


printf("loading img\n");

e = GfxLibLoadPng(3,L"/test.png", &i, false);
if(e) perr("cannot load image: 0x%04x\n",e);

GfxImageGetDimensions(i, &iw, &ih);

printf("img is %dx%d\n",iw,ih);

L = GfxLayerCreateWithImage(0, 0, i);
if(!L) perr("cannot create layer with image\n");


x = 0;
y = 0;

while(1){

x += dx;
y += dy;

if((x + iw >= sw) || x <0){
dx = -dx;
x += 2 * dx;
}
if((y + ih >= sh) || y < 0){
dy = -dy;
y += 2 * dy;
}

GfxLayerSetLocation(L, x, y);
}

while(1) SchedYield(); //idle well
}

12 comments:

JP said...

this is great!!! its seams that my LD its going to back to life :D

che said...

thanks you!!!!

Unknown said...

awesome!!!

Thireus said...

Nice, is your LD overclocked?

Ed said...

Great!... Nice video, awaiting a demo with eagerness!

Dmitry Grinberg said...

Overclocked? I underclocked it to 90 MHz :)

Unknown said...

I am SOOOO expecting it. checking your blog everyday. thanks for the video, hoping for more:)

Thireus said...

Thanks Dmitry, I've watched the video without sound.

Good job ;)

Unknown said...

I see nothing impressive I think we all hope to see other things!

ePalm said...

Most excellent!

Dmitry Grinberg said...

david, relax. More is to come.

Hari Seldon said...

Great work! I can't wait to see applications running.