From: hackbard Date: Tue, 25 Mar 2003 17:43:54 +0000 (+0000) Subject: dfb api ready. X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a41ec558b235239b4a544297456369d818660543;p=physik%2Fmorpheus.git dfb api ready. --- diff --git a/defines.h b/defines.h index 19ce139..45be196 100644 --- a/defines.h +++ b/defines.h @@ -40,6 +40,7 @@ typedef struct __display { #ifdef USE_DFB_API IDirectFB *dfb; /* pointer to dfb main construct */ IDirectFBSurface *primary_surface; /* pointer to dfb primary surface */ + IDirectFBFont *font; /* the font */ #endif int screen_height,screen_width; /* screen dimensions */ } display; @@ -51,6 +52,9 @@ typedef struct __display { #define DISPLAY_X_FREE 15 #define DISPLAY_Y_FREE 15 + +#define DISPLAY_FONT "/usr/share/DFBSee/decker.ttf" +#define MAX_TXT 20 /* masks for u32 cell */ #define AMORPH 0x00000001 diff --git a/display.c b/display.c index 62612e7..4ef9546 100644 --- a/display.c +++ b/display.c @@ -9,17 +9,17 @@ #include "defines.h" #ifdef USE_DFB_API -static IDirectFB *dfb=NULL; -static IDirectFBSurface *primary_surface=NULL; -static int screen_width=0; -static int screen_height=0; +// static IDirectFB *dfb=NULL; +// static IDirectFBSurface *primary_surface=NULL; +// static IDirectFBFont *font=NULL; +// static int screen_width=0; +// static int screen_height=0; #endif int display_init(int x,int y,int z,display *display,void *cell,int *argc,char **argv) { #ifdef USE_DFB_API DFBSurfaceDescription surface_dsc; - // DFBFontDescription font_dsc; #endif /* store dimensions */ @@ -32,39 +32,112 @@ int display_init(int x,int y,int z,display *display,void *cell,int *argc,char ** /* the api(s) */ #ifdef USE_DFB_API DirectFBInit(argc,&argv); - DirectFBCreate(&dfb); - dfb->SetCooperativeLevel(dfb,DFSCL_FULLSCREEN); + DirectFBCreate(&(display->dfb)); + display->dfb->SetCooperativeLevel(display->dfb,DFSCL_FULLSCREEN); surface_dsc.flags=DSDESC_CAPS; surface_dsc.caps=DSCAPS_PRIMARY|DSCAPS_FLIPPING; - dfb->CreateSurface(dfb,&surface_dsc,&primary_surface); - primary_surface->GetSize(primary_surface,&screen_width,&screen_height); - display->dfb=dfb; - display->primary_surface=primary_surface; - display->screen_width=screen_width; - display->screen_height=screen_height; + display->dfb->CreateSurface(display->dfb,&surface_dsc,&(display->primary_surface)); + display->primary_surface->GetSize(display->primary_surface,&(display->screen_width),&(display->screen_height)); + #endif return 23; } +int display_release(display *display) +{ +#ifdef USE_DFB_API + display->primary_surface->Release(display->primary_surface); + display->dfb->Release(display->dfb); +#endif + + return 23; +} + +#ifdef USE_DFB_API +int dfb_choose_color(u32 *cell_p,unsigned char *r,unsigned char *g,unsigned char *b) +{ + if((*cell_p&AMORPH)==AMORPH) + { + *r=0xff; + *g=0x00; + *b=0x00; + } else + { + *r=0x00; + *g=0x00; + *b=0xff; + } + return 23; +} +#endif + int display_draw(display *display,int x,int y,int z) { #ifdef USE_DFB_API - int x_c,y_c; + int menu_x,menu_y,menu_w,menu_h; /* for the yellow box */ + int x_c,y_c,z_c; + unsigned char r,g,b,a; int display_faktor_x,display_faktor_y; + a=0xff; /* no alpha blending */ if(((display->max_x+display->max_y+DISPLAY_X_FREE)>=display->screen_width)| ((display->max_y+display->max_z+DISPLAY_Y_FREE)>=display->screen_height)) { puts("resolution too low!"); return -23; } - display_faktor_x=display->screen_width/(display->max_x+display->max_y); - display_faktor_y=display->screen_height/(display->max_z+display->max_y); - /* draw x-z surface */ - // for(x_c=1;x_c<=display->max_x,x_c++) - // { - - + display_faktor_x=display->screen_width/(display->max_x+display->max_y+DISPLAY_X_FREE); + display_faktor_y=display->screen_height/(display->max_z+display->max_y+DISPLAY_Y_FREE); + // if(display_faktor_xmax_x;x_c++) + { + for(z_c=0;z_cmax_z;z_c++) + { + dfb_choose_color((u32 *)(display->cell_p+x_c+y_c*(display->max_x-1)+z_c*(display->max_x-1)*(display->max_y-1)),&r,&g,&b); + display->primary_surface->SetColor(display->primary_surface,r,g,b,a); + display->primary_surface->DrawRectangle(display->primary_surface,x_c*display_faktor_x+DISPLAY_X_FREE/3,z_c*display_faktor_y+DISPLAY_Y_FREE/3,display_faktor_x,display_faktor_y); + } + } + /* draw y-z surface */ + x_c=x; + for(y_c=0;y_cmax_y;y_c++) + { + for(z_c=0;z_cmax_z;z_c++) + { + dfb_choose_color((u32 *)(display->cell_p+x_c+y_c*(display->max_x-1)+z_c*(display->max_x-1)*(display->max_y-1)),&r,&g,&b); + display->primary_surface->SetColor(display->primary_surface,r,g,b,a); + display->primary_surface->DrawRectangle(display->primary_surface,(y_c+display->max_x)*display_faktor_x+2*DISPLAY_X_FREE/3,z_c*display_faktor_y+DISPLAY_Y_FREE/3,display_faktor_x,display_faktor_y); + } + } + /* draw x-y surface */ + z_c=z; + for(x_c=0;x_cmax_x;x_c++) + { + for(y_c=0;y_cmax_y;y_c++) + { + dfb_choose_color((u32 *)(display->cell_p+x_c+y_c*(display->max_x-1)+z_c*(display->max_x-1)*(display->max_y-1)),&r,&g,&b); + display->primary_surface->SetColor(display->primary_surface,r,g,b,a); + display->primary_surface->DrawRectangle(display->primary_surface,x_c*display_faktor_x+DISPLAY_X_FREE/3,(y_c+display->max_z)*display_faktor_y+2*DISPLAY_Y_FREE/3,display_faktor_x,display_faktor_y); + } + } + /* display info window */ + r=0xff; + g=0xff; + b=0x00; + a=0xff; + menu_x=2*DISPLAY_X_FREE/3+display->max_x*display_faktor_x; + menu_y=2*DISPLAY_Y_FREE/3+display->max_z*display_faktor_y; + menu_w=display->max_y*display_faktor_x; + menu_h=display->max_y*display_faktor_y; + display->primary_surface->SetColor(display->primary_surface,0,0,0,0); + display->primary_surface->FillRectangle(display->primary_surface,menu_x,menu_y,menu_w,menu_h); + display->primary_surface->SetColor(display->primary_surface,r,g,b,a); + display->primary_surface->DrawRectangle(display->primary_surface,menu_x,menu_y,menu_w,menu_h); + /* flip all to surface */ + display->primary_surface->Flip(display->primary_surface,NULL,0); #endif return 23; } diff --git a/main.c b/main.c index 190955c..b7ce867 100644 --- a/main.c +++ b/main.c @@ -57,7 +57,7 @@ int process_cell(u32 *cell) { /* tag it ... testing! */ make_amorph(cell); - + return 23; } @@ -149,6 +149,7 @@ int main(int argc,char **argv) /* testing ... */ /* allocate cells */ + printf("malloc will free %d bytes now ...\n",x_cell*y_cell*z_cell*sizeof(u32)); if((cell_p=malloc(x_cell*y_cell*z_cell*sizeof(u32)))==NULL) { puts("failed allocating memory for cells\n"); @@ -171,12 +172,8 @@ int main(int argc,char **argv) process_cell((u32 *)(cell_p+x+y*(x_cell-1)+z*(x_cell-1)*(y_cell-1))); /* display stuff */ - if((i%display_refresh_rate)==0) - { - puts("refreshing display ..."); - // display_draw(&display,display_x,display_y,display_z); - } - /* */ + if((i%display_refresh_rate)==0) + display_draw(&display,display_x,display_y,display_z); } /* display again and quit when button hit */ @@ -184,5 +181,7 @@ int main(int argc,char **argv) puts("hit button to quit ..."); getchar(); + display_release(&display); + return 23; }