]> hackdaworld.org Git - physik/morpheus.git/commitdiff
dfb api ready.
authorhackbard <hackbard>
Tue, 25 Mar 2003 17:43:54 +0000 (17:43 +0000)
committerhackbard <hackbard>
Tue, 25 Mar 2003 17:43:54 +0000 (17:43 +0000)
defines.h
display.c
main.c

index 19ce139ab03129112d39b7265552db205e3c12ab..45be196df5773629bfc3e3990ea1bb3ea6c37cbe 100644 (file)
--- 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
index 62612e7d100a8bb5fae68bb88acf005635ae20e2..4ef95460664cbee2e34749e3c2a28be400f1b3f3 100644 (file)
--- 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_x<display_faktor_y) display_faktor_y=display_faktor_x;
+ // if(display_faktor_y<display_faktor_x) display_faktor_x=display_faktor_y;
 
+ /* draw x-z surface */
+ y_c=y;
+ for(x_c=0;x_c<display->max_x;x_c++)
+ {
+  for(z_c=0;z_c<display->max_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_c<display->max_y;y_c++)
+ {
+  for(z_c=0;z_c<display->max_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_c<display->max_x;x_c++)
+ {
+  for(y_c=0;y_c<display->max_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 190955cdde5b26e93aa6e285a8f1a3837f124eca..b7ce8674d05f41d9e24a2aaea0c6e7809e883874 100644 (file)
--- 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;
 }