Ejemplo n.º 1
0
Archivo: draw.c Proyecto: descent/jmcce
bool screen_init (void)
{
#ifdef LINUXFB
  use_fb = 1;
  if (fb_init ()) 
  {
    use_fb = 0;
    return false;
  }
#endif

#ifdef VGALIB
  use_fb = 0;
  vga_init ();
  vga_setmode(DEFAULT_VGA_MODE);
  gl_setcontextvga(DEFAULT_VGA_MODE);
  physical_screen = gl_allocatecontext();
  gl_getcontext(physical_screen);

  gl_setcontextvgavirtual(DEFAULT_VGA_MODE);
  virtual_screen = gl_allocatecontext();
  gl_getcontext(virtual_screen);

  gl_setcontext(virtual_screen);
  //vga_ext_set(VGA_EXT_SET,  VGA_CLUT8);

// color table:
// http://en.wikipedia.org/wiki/ANSI_escape_code#Colors 

  gl_setpalettecolor(BLUE, 0, 0, 63); // blue
  gl_setpalettecolor(BLACK, 0, 0, 0); // black
  gl_setpalettecolor(GREEN, 0, 63, 0); 
  gl_setpalettecolor(RED, 63, 0, 0); 
  gl_setpalettecolor(BROWN, 170/4, 85/4, 0);
  gl_setpalettecolor(MAGENTA, 170/4, 0, 170/4);
  gl_setpalettecolor(CYAN, 0, 170/4, 170/4); 
  gl_setpalettecolor(GRAY, 48, 48, 48);

  gl_setpalettecolor(LIGHTBLACK, 85/4, 85/4, 85/4); 
  gl_setpalettecolor(LIGHTBLUE, 85/4, 85/4, 255/4); 
  gl_setpalettecolor(LIGHTGREEN, 85/4, 255/4, 85/4); 
  gl_setpalettecolor(LIGHTCYAN, 85/4, 255/4, 255/4); 
  gl_setpalettecolor(LIGHTRED, 25/45/4, 85/4, 85/4); 
  gl_setpalettecolor(LIGHTMAGENTA, 255/4, 85/4, 255/4); 
  gl_setpalettecolor(LIGHTBROWN, 255/4, 255/4, 85/4); 

#endif

  active_console = 1;
  return true;
}
Ejemplo n.º 2
0
void initscreen(void)
{
	int vgamode;

	vga_init();

	vgamode = G640x480x16;

	if (!vga_hasmode(vgamode)) {
		printf("Mode not available.\n");
		exit(-1);
	}
	vga_setmode(vgamode);

	/* Create virtual screen. */
	gl_setcontextvgavirtual(vgamode);
	backscreen = gl_allocatecontext();
	gl_getcontext(backscreen);

	/* Physical screen context. */
	vga_setmode(vgamode);
	gl_setcontextvga(vgamode);
	physicalscreen = gl_allocatecontext();
	gl_getcontext(physicalscreen);

	gl_setcontext(backscreen);
	/*drawgraypalette(); */

	gl_clearscreen(0);

//    gl_setcontextvga(vgamode);
	gl_enableclipping();
	gl_setclippingwindow(0, 0, 639, 479);
	gl_setwritemode(WRITEMODE_OVERWRITE | FONT_COMPRESSED);
	gl_setfont(8, 8, gl_font8x8);
	gl_setfontcolors(0, 1);
}
Ejemplo n.º 3
0
void demo3(void)
{
    int x, y;
    int targetx, targety;
    int count, startclock;
    GraphicsContext *virtualscreen;
    GraphicsContext *physicalscreen;

    /* Window coordinate initially at center. */
    x = VWIDTH / 2 - WINWIDTH / 2;
    y = VHEIGHT / 2 - WINHEIGHT / 2;
    targetx = x;
    targety = y;

    virtualscreen = gl_allocatecontext();
    gl_getcontext(virtualscreen);
    gl_setcontextvga(G320x200x256);
    physicalscreen = gl_allocatecontext();
    gl_getcontext(physicalscreen);
    gl_setcontext(virtualscreen);

    count = 0;
    startclock = clock();

    for (;;) {
        vga_waitretrace();
	/* Copy window to screen. */
	gl_copyboxtocontext(x, y, WINWIDTH, WINHEIGHT, physicalscreen,
			    0, 0);

	if (x == targetx && y == targety) {
	    /* Create new target. */
	    targetx = rand() % (VWIDTH - WINWIDTH);
	    targety = rand() % (VHEIGHT - WINHEIGHT);
	}
	/* Move towards target. */
	if (x < targetx)
	    x++;
	if (x > targetx)
	    x--;
	if (y < targety)
	    y++;
	if (y > targety)
	    y--;

	/* Boundary checks. */
	if (x < 0)
	    x = 0;
	if (x > VWIDTH - WINWIDTH)
	    x = VWIDTH - WINWIDTH;
	if (y < 0)
	    y = 0;
	if (y > VHEIGHT - WINHEIGHT)
	    y = VHEIGHT - WINHEIGHT;

	if (vga_getkey())
	    break;

	count++;
    }

    printf("Method 3: frame rate %ld\n", count * CLOCKS_PER_SEC
	   / (clock() - startclock));
}
Ejemplo n.º 4
0
int main() {
   int maxCols = 1024;
   int maxRows = 768;
   int maxIterations = 2048;
   int maxSize = 4;
   float Xmin = -2.0;
   float Xmax = 1.2;
   float Ymin = -1.2;
   float Ymax = 1.2;
 
   double X, Y;
   double Xsquare, Ysquare;
   double currentP;
   double currentQ[767];
   double deltaP, deltaQ;
   int color;
   int currentRow, currentCol;
 
   deltaP = (Xmax - Xmin)/(double)maxCols;
 
   deltaQ = (Ymax - Ymin)/(double)maxRows;
 
   currentQ[0] = Ymax;
   for (currentRow = 1; currentRow < maxRows; currentRow++) {
      currentQ[currentRow] = currentQ[currentRow-1] - deltaQ;
   }
   currentP = Xmin;
 
   vga_init();
   vga_setmode(G1024x768x256);
   gl_setcontextvga(G1024x768x256);
   physicalscreen = gl_allocatecontext();
   gl_getcontext(physicalscreen);
   gl_setcontextvgavirtual(G1024x768x256);
   virtualscreen = gl_allocatecontext();
   gl_getcontext(virtualscreen);
   gl_setcontext(virtualscreen);
 
   for (currentCol = 0; currentCol < maxCols; currentCol++) {
      for (currentRow = 0; currentRow < maxRows; currentRow++) {
         X = 0.0;
         Y = 0.0;
         Xsquare = 0.0;
         Ysquare = 0.0;
         color = 0;
         while ((color <= maxIterations) && (Xsquare + Ysquare <= maxSize)) {
            Xsquare = X * X;
            Ysquare = Y * Y;
            Y = (2*X*Y) + currentQ[currentRow];
            X = (Xsquare - Ysquare) + currentP;
            color++;
         }
             gl_setpixel(currentCol, currentRow, color % 256);
      }
      currentP = currentP + deltaP;
      gl_copyscreen(physicalscreen);
   }
   vga_getch();
   gl_clearscreen(0);
   vga_setmode(TEXT);
 
   return 0;
}
Ejemplo n.º 5
0
void test(void)
{
    int i, j;
    unsigned char *bitmap;
    GraphicsContext *savedcontext;

    if (VIRTUAL)
	gl_setcontext(backscreen);

    gl_clearscreen(0);
    for (i = 0; i < 5; i++) {
	gl_clearscreen(0);
	for (j = 0; j < 20000; j++)
	    gl_setpixel(random() % WIDTH, random() % HEIGHT,
			random() % COLORS);
    }

    if (VIRTUAL)
	gl_copyscreen(physicalscreen);

    gl_clearscreen(0);
    for (i = 0; i < 5000; i++) {
	int x, y;
	x = random() % (WIDTH - 1);
	y = random() % (HEIGHT - 1);
	gl_fillbox(x, y, random() % (WIDTH - x), random()
		   % (HEIGHT - y), random() % COLORS);
    }

    if (VIRTUAL)
	gl_copyscreen(physicalscreen);

    gl_clearscreen(0);
    for (i = 0; i < 4000; i++)
	gl_line(random() % WIDTH, random() % HEIGHT,
		random() % WIDTH, random() % HEIGHT,
		random() % COLORS);

    if (VIRTUAL)
	gl_copyscreen(physicalscreen);

    /* Create bitmap. */
    bitmap = malloc(64 * 64 * BYTESPERPIXEL);
    /* Create temporary graphics context to create bitmap in. */
    savedcontext = gl_allocatecontext();
    gl_getcontext(savedcontext);
    gl_setcontextvirtual(64, 64, BYTESPERPIXEL, BITSPERPIXEL, bitmap);
    /* The rgb functions can be used to create nice bitmaps easily for */
    /* hicolor/truecolor modes. The 256 color 'emulated' truecolor */
    /* looks less impressive. */
    for (i = 0; i < 32; i++)
	for (j = 0; j < 32; j++) {
	    int c;
	    c = 255 - (i + j) * 4;
	    gl_setpixelrgb(31 - i, 31 - j, c, 0, 0);
	    gl_setpixelrgb(32 + i, 31 - j, c, c, 0);
	    gl_setpixelrgb(31 - i, 32 + j, c, 0, c);
	    gl_setpixelrgb(32 + i, 32 + j, c, c, c);
	}
    /* Restore previous context. */
    gl_setcontext(savedcontext);

    gl_clearscreen(0);
    for (i = 0; i < 4000; i++) {
	int x, y;
	x = random() % (WIDTH - 64 + 1);
	y = random() % (HEIGHT - 64 + 1);
	gl_putbox(x, y, 64, 64, bitmap);
    }

    free(bitmap);

    if (VIRTUAL)
	gl_copyscreen(physicalscreen);
}