Hello.

It was some time since I last did anything with GGI, but today I found
an old Amiga/Atari hack that I thought would be fun to port to
Unix. It wants a pointer to a palette based fb, so I thought that
might be possible to fix easily by setting up a memvisual and acquire a
directbuffer from it. I'm not sure about the directbuffer part yet
because I've only glanced over API documentation for it, but that is
not the point of this letter. 

The question I would like to ask is: How do I crossblit from a
memvisual to a normal visual. It's very embarrassing, but I can't even
get that to work. Please take a look at this example code and tell me
where I went wrong:


--8<------------------
#include <ggi/ggi.h>

ggi_visual_t *vis;
ggi_visual_t *memvis;
ggi_mode mode;
ggi_mode memmode;

#define DRAWAREA memvis
#define DEST     vis
void play_with_visuals()
{
  ggi_color black  = { 0x0000, 0x0000, 0x0000 };
  ggi_color white  = { 0xffff, 0xffff, 0xffff };
  ggi_pixel blackpixel = ggiMapColor(DRAWAREA, &black);
  ggi_pixel whitepixel = ggiMapColor(DRAWAREA, &white);

  ggiSetGCBackground(DRAWAREA, blackpixel);
  ggiSetGCForeground(DRAWAREA, whitepixel);

  ggiPuts(DRAWAREA, 0, 10, "Hello.");
  ggiPutPixel(DRAWAREA, 200, 200, whitepixel);

  ggiFlush(DRAWAREA);

  /* Crossblit slightly down to the right so we can see if it works
     with the same visual */
  if(ggiCrossBlit(DRAWAREA, 0,0,600,40, DEST, 40,40) != 0)
    ggiPanic("Crossblit failed!\n");

  ggiFlush(DEST);
}

void setup_ggi()
{
  if (ggiInit() < 0)
    ggiPanic("Cannot initalize LibGGI!\n");

  /* First we setup the real visual */
  ggiParseMode("", &mode);   // sets all fields to GGI_AUTO
  
  if( (vis=ggiOpen(NULL)) == NULL )
    ggiPanic("Unable to open default visual, exiting.\n");

  if (ggiSetMode(vis, &mode) != 0)
    ggiPanic("Cannot set mode!\n");

  /* Then set up a memory target in palette mode we can crossblit from */
  ggiParseMode("640x480[GT_8BIT]", &memmode);

  if( (memvis = ggiOpen("display-memory",NULL)) == NULL )
    ggiPanic("Unable to open memory visual, exiting.\n");

  if (ggiSetMode(memvis, &memmode) != 0)
    ggiPanic("Cannot set memvis mode!\n");

  /* Just me being paranoid. */
  ggiGetMode(memvis, &memmode);
  ggiPrintMode( &memmode );
  printf("\n");
}

int main(int argc, char **argv)
{
  setup_ggi();

  play_with_visuals();

  /* sleep() doesn't work. I remember there being a reason for this,
     but damn if I can remember what it was. Wait for input instead. */
  ggiGetc(vis);

  ggiClose(vis);
  ggiClose(memvis);
  ggiExit();  
  exit(0);
}
--8<------------------------------

If DRAWAREA is defined to vis (thus blitting to and from the same vis)
it will work as it should, but it will refuse to work from memvis.

-- 
Peter Bortas                   http://peter.bortas.org
Roxen IS                       http://www.roxen.com

Reply via email to