130465Ssos/*-
2222175Suqs * Copyright (c) 1991-1997 S��ren Schmidt
330465Ssos * All rights reserved.
430465Ssos *
530465Ssos * Redistribution and use in source and binary forms, with or without
630465Ssos * modification, are permitted provided that the following conditions
730465Ssos * are met:
830465Ssos * 1. Redistributions of source code must retain the above copyright
930465Ssos *    notice, this list of conditions and the following disclaimer
1030465Ssos *    in this position and unchanged.
1130465Ssos * 2. Redistributions in binary form must reproduce the above copyright
1230465Ssos *    notice, this list of conditions and the following disclaimer in the
1330465Ssos *    documentation and/or other materials provided with the distribution.
1430465Ssos * 3. The name of the author may not be used to endorse or promote products
1597748Sschweikh *    derived from this software without specific prior written permission
1630465Ssos *
1730465Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1830465Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1930465Ssos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2030465Ssos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2130465Ssos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2230465Ssos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2330465Ssos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2430465Ssos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2530465Ssos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2630465Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2730465Ssos *
2850476Speter * $FreeBSD$
2930465Ssos */
3030465Ssos
3130465Ssos#include <sys/types.h>
3266834Sphk#include <sys/fbio.h>
3366834Sphk#include <sys/kbio.h>
3466834Sphk#include <sys/consio.h>
3554592Sbillf#include <vgl.h>
3630465Ssos
3730465Ssosint
3830465Ssosmain(int argc, char **argv)
3930465Ssos{
4054592Sbillf  int y, xsize, ysize, i,j;
4153013Syokota  VGLBitmap *tmp;
4230465Ssos
4330465Ssos  // set graphics mode, here 320x240 256 colors
4466834Sphk  // supported modes are (from <sys/consio.h>):
45222175Suqs  // SW_VGA_CG320:      std VGA 320x200 256 colors
46222175Suqs  // SW_VGA_MODEX:      Modex VGA 320x240 256 colors
47222175Suqs  // SW_VGA_VG640:      std VGA 640x480 16 colors
4830465Ssos  VGLInit(SW_VGA_MODEX);
4930465Ssos
5030465Ssos  // initialize mouse and show pointer
5130465Ssos  VGLMouseInit(VGL_MOUSESHOW);
5230465Ssos
53222175Suqs  // VGLDisplay is a ptr to a struct Bitmap defined and initialized by
5430465Ssos  // libvgl. The Bitmap points directly to screen memory etc.
5530465Ssos  xsize=VGLDisplay->Xsize;
5630465Ssos  ysize=VGLDisplay->Ysize;
5730465Ssos
5853013Syokota  // alloc a new bitmap
5953013Syokota  tmp = VGLBitmapCreate(MEMBUF, 256, 256, NULL);
6053013Syokota  VGLBitmapAllocateBits(tmp);
6153013Syokota  VGLClear(tmp, 0);
6230465Ssos
6330465Ssos  // fill the screen with colored lines
64222175Suqs  for (y=0; y<ysize; y++)
6530465Ssos    VGLLine(VGLDisplay, 0, y, xsize-1, y, y/2 % 256);
6630465Ssos
6730465Ssos  // draw some lines and circles just to show off
6830465Ssos  VGLLine(VGLDisplay, 0, 0, xsize-1, ysize-1, 63);
6930465Ssos  VGLLine(VGLDisplay, 0, ysize-1, xsize-1, 0, 63);
7030465Ssos  VGLLine(VGLDisplay, 0, 0, 0, ysize-1, 63);
7130465Ssos  VGLLine(VGLDisplay, xsize-1, 0, xsize-1, ysize-1, 63);
7230465Ssos  VGLEllipse(VGLDisplay, 256, 0, 256, 256, 63);
7330465Ssos  VGLEllipse(VGLDisplay, 0, 256, 256, 256, 0);
7430465Ssos
75222175Suqs  // some text is also useful
7630465Ssos  VGLBitmapString(VGLDisplay, 100,100,
7730465Ssos    "This is text", 63, 0, 0, VGL_DIR_RIGHT);
7830465Ssos  sleep(2);
7930465Ssos  VGLBitmapString(VGLDisplay, 100,100,
8030465Ssos    "This is text", 63, 0, 0, VGL_DIR_UP);
8130465Ssos  sleep(2);
8230465Ssos  VGLBitmapString(VGLDisplay, 100,100,
8330465Ssos    "This is text", 63, 0, 0, VGL_DIR_LEFT);
8430465Ssos  sleep(2);
8530465Ssos  VGLBitmapString(VGLDisplay, 100,100,
8630465Ssos    "This is text", 63, 0, 0, VGL_DIR_DOWN);
8730465Ssos  sleep(2);
8830465Ssos
89222175Suqs  // now show some simple bitblit
9030465Ssos  for (i=0; i<256; i++)
9130465Ssos    for (j=0; j<256; j++)
9253013Syokota      tmp->Bitmap[i+256*j] = i%16;
9353013Syokota  VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 0, 0, 128, 128);
9430465Ssos  for (i=0; i<256; i++)
9530465Ssos    for (j=0; j<256; j++)
9653013Syokota      tmp->Bitmap[i+256*j] = j%16;
9753013Syokota  VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 3, 128, 128, 128);
9830465Ssos  sleep(2);
9953013Syokota  VGLBitmapCopy(VGLDisplay, 237, 311, tmp, 64, 64, 128, 128);
10053013Syokota  VGLBitmapCopy(tmp, 32, 32, VGLDisplay, 400, 128, 128, 128);
10130465Ssos  sleep(2);
10230465Ssos  VGLBitmapCopy(VGLDisplay, 300, 300, VGLDisplay, 500, 128, 128, 128);
10330465Ssos  sleep(5);
10430465Ssos  i=0;
10530465Ssos
10630465Ssos  // loop around drawing and copying
10730465Ssos  while (++i) {
10830465Ssos    VGLBitmapCopy(VGLDisplay, rand()%xsize, rand()%ysize,
109222175Suqs                  VGLDisplay, rand()%xsize, rand()%ysize,
110222175Suqs                  rand()%xsize, rand()%ysize);
11130465Ssos    VGLLine(VGLDisplay,  rand()%xsize, rand()%ysize,
11230465Ssos            rand()%xsize, rand()%ysize, rand()%256);
11330465Ssos    VGLEllipse(VGLDisplay, rand()%xsize, rand()%ysize,
114222175Suqs               rand()%xsize/2, rand()%ysize/2, rand()%256);
11530465Ssos    rand();
11630465Ssos    if (i > 1000) break;
11730465Ssos  }
11830465Ssos
11930465Ssos  // restore screen to its original mode
12030465Ssos  VGLEnd();
12130465Ssos  return 0;
12230465Ssos}
123