demo.c revision 54592
130465Ssos/*- 230465Ssos * 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 1530465Ssos * derived from this software withough 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: head/share/examples/libvgl/demo.c 54592 1999-12-14 08:47:42Z billf $ 2930465Ssos */ 3030465Ssos 3130465Ssos#include <sys/types.h> 3230465Ssos#include <machine/console.h> 3354592Sbillf#include <vgl.h> 3430465Ssos 3530465Ssosint 3630465Ssosmain(int argc, char **argv) 3730465Ssos{ 3854592Sbillf int y, xsize, ysize, i,j; 3953013Syokota VGLBitmap *tmp; 4030465Ssos 4130465Ssos // set graphics mode, here 320x240 256 colors 4230465Ssos // supported modes are (from <machine/console.h>): 4330465Ssos // SW_VGA_CG320: std VGA 320x200 256 colors 4430465Ssos // SW_VGA_MODEX: Modex VGA 320x240 256 colors 4530465Ssos // SW_VGA_VG640: std VGA 640x480 16 colors 4630465Ssos VGLInit(SW_VGA_MODEX); 4730465Ssos 4830465Ssos // initialize mouse and show pointer 4930465Ssos VGLMouseInit(VGL_MOUSESHOW); 5030465Ssos 5130465Ssos // VGLDisplay is a ptr to a struct Bitmap defined and initialized by 5230465Ssos // libvgl. The Bitmap points directly to screen memory etc. 5330465Ssos xsize=VGLDisplay->Xsize; 5430465Ssos ysize=VGLDisplay->Ysize; 5530465Ssos 5653013Syokota // alloc a new bitmap 5753013Syokota tmp = VGLBitmapCreate(MEMBUF, 256, 256, NULL); 5853013Syokota VGLBitmapAllocateBits(tmp); 5953013Syokota VGLClear(tmp, 0); 6030465Ssos 6130465Ssos // fill the screen with colored lines 6230465Ssos for (y=0; y<ysize; y++) 6330465Ssos VGLLine(VGLDisplay, 0, y, xsize-1, y, y/2 % 256); 6430465Ssos 6530465Ssos // draw some lines and circles just to show off 6630465Ssos VGLLine(VGLDisplay, 0, 0, xsize-1, ysize-1, 63); 6730465Ssos VGLLine(VGLDisplay, 0, ysize-1, xsize-1, 0, 63); 6830465Ssos VGLLine(VGLDisplay, 0, 0, 0, ysize-1, 63); 6930465Ssos VGLLine(VGLDisplay, xsize-1, 0, xsize-1, ysize-1, 63); 7030465Ssos VGLEllipse(VGLDisplay, 256, 0, 256, 256, 63); 7130465Ssos VGLEllipse(VGLDisplay, 0, 256, 256, 256, 0); 7230465Ssos 7330465Ssos // some text is also usefull 7430465Ssos VGLBitmapString(VGLDisplay, 100,100, 7530465Ssos "This is text", 63, 0, 0, VGL_DIR_RIGHT); 7630465Ssos sleep(2); 7730465Ssos VGLBitmapString(VGLDisplay, 100,100, 7830465Ssos "This is text", 63, 0, 0, VGL_DIR_UP); 7930465Ssos sleep(2); 8030465Ssos VGLBitmapString(VGLDisplay, 100,100, 8130465Ssos "This is text", 63, 0, 0, VGL_DIR_LEFT); 8230465Ssos sleep(2); 8330465Ssos VGLBitmapString(VGLDisplay, 100,100, 8430465Ssos "This is text", 63, 0, 0, VGL_DIR_DOWN); 8530465Ssos sleep(2); 8630465Ssos 8730465Ssos // now show some simple bitblit 8830465Ssos for (i=0; i<256; i++) 8930465Ssos for (j=0; j<256; j++) 9053013Syokota tmp->Bitmap[i+256*j] = i%16; 9153013Syokota VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 0, 0, 128, 128); 9230465Ssos for (i=0; i<256; i++) 9330465Ssos for (j=0; j<256; j++) 9453013Syokota tmp->Bitmap[i+256*j] = j%16; 9553013Syokota VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 3, 128, 128, 128); 9630465Ssos sleep(2); 9753013Syokota VGLBitmapCopy(VGLDisplay, 237, 311, tmp, 64, 64, 128, 128); 9853013Syokota VGLBitmapCopy(tmp, 32, 32, VGLDisplay, 400, 128, 128, 128); 9930465Ssos sleep(2); 10030465Ssos VGLBitmapCopy(VGLDisplay, 300, 300, VGLDisplay, 500, 128, 128, 128); 10130465Ssos sleep(5); 10230465Ssos i=0; 10330465Ssos 10430465Ssos // loop around drawing and copying 10530465Ssos while (++i) { 10630465Ssos VGLBitmapCopy(VGLDisplay, rand()%xsize, rand()%ysize, 10730465Ssos VGLDisplay, rand()%xsize, rand()%ysize, 10830465Ssos rand()%xsize, rand()%ysize); 10930465Ssos VGLLine(VGLDisplay, rand()%xsize, rand()%ysize, 11030465Ssos rand()%xsize, rand()%ysize, rand()%256); 11130465Ssos VGLEllipse(VGLDisplay, rand()%xsize, rand()%ysize, 11230465Ssos rand()%xsize/2, rand()%ysize/2, rand()%256); 11330465Ssos rand(); 11430465Ssos if (i > 1000) break; 11530465Ssos } 11630465Ssos 11730465Ssos // restore screen to its original mode 11830465Ssos VGLEnd(); 11930465Ssos return 0; 12030465Ssos} 12130465Ssos 122