1 /*- 2 * Copyright (c) 1991-1997 Søren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer 10 * in this position and unchanged. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $FreeBSD: src/share/examples/libvgl/demo.c,v 1.4 1999/12/14 08:47:42 billf Exp $ 29 * $DragonFly: src/share/examples/libvgl/demo.c,v 1.4 2008/05/18 03:02:53 pavalos Exp $ 30 */ 31 32 #include <sys/types.h> 33 #include <machine/console.h> 34 #include <vgl.h> 35 36 int 37 main(int argc, char **argv) 38 { 39 int y, xsize, ysize, i,j; 40 VGLBitmap *tmp; 41 42 // set graphics mode, here 320x240 256 colors 43 // supported modes are (from <sys/fbio.h>): 44 // M_VGA_CG320: std VGA 320x200 256 colors 45 // M_VGA_MODEX: Modex VGA 320x240 256 colors 46 // M_VGA_CG640: std VGA 640x480 16 colors 47 VGLInit(M_VGA_MODEX); 48 49 // initialize mouse and show pointer 50 VGLMouseInit(VGL_MOUSESHOW); 51 52 // VGLDisplay is a ptr to a struct Bitmap defined and initialized by 53 // libvgl. The Bitmap points directly to screen memory etc. 54 xsize=VGLDisplay->Xsize; 55 ysize=VGLDisplay->Ysize; 56 57 // alloc a new bitmap 58 tmp = VGLBitmapCreate(MEMBUF, 256, 256, NULL); 59 VGLBitmapAllocateBits(tmp); 60 VGLClear(tmp, 0); 61 62 // fill the screen with colored lines 63 for (y=0; y<ysize; y++) 64 VGLLine(VGLDisplay, 0, y, xsize-1, y, y/2 % 256); 65 66 // draw some lines and circles just to show off 67 VGLLine(VGLDisplay, 0, 0, xsize-1, ysize-1, 63); 68 VGLLine(VGLDisplay, 0, ysize-1, xsize-1, 0, 63); 69 VGLLine(VGLDisplay, 0, 0, 0, ysize-1, 63); 70 VGLLine(VGLDisplay, xsize-1, 0, xsize-1, ysize-1, 63); 71 VGLEllipse(VGLDisplay, 256, 0, 256, 256, 63); 72 VGLEllipse(VGLDisplay, 0, 256, 256, 256, 0); 73 74 // some text is also useful 75 VGLBitmapString(VGLDisplay, 100,100, 76 "This is text", 63, 0, 0, VGL_DIR_RIGHT); 77 sleep(2); 78 VGLBitmapString(VGLDisplay, 100,100, 79 "This is text", 63, 0, 0, VGL_DIR_UP); 80 sleep(2); 81 VGLBitmapString(VGLDisplay, 100,100, 82 "This is text", 63, 0, 0, VGL_DIR_LEFT); 83 sleep(2); 84 VGLBitmapString(VGLDisplay, 100,100, 85 "This is text", 63, 0, 0, VGL_DIR_DOWN); 86 sleep(2); 87 88 // now show some simple bitblit 89 for (i=0; i<256; i++) 90 for (j=0; j<256; j++) 91 tmp->Bitmap[i+256*j] = i%16; 92 VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 0, 0, 128, 128); 93 for (i=0; i<256; i++) 94 for (j=0; j<256; j++) 95 tmp->Bitmap[i+256*j] = j%16; 96 VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 3, 128, 128, 128); 97 sleep(2); 98 VGLBitmapCopy(VGLDisplay, 237, 311, tmp, 64, 64, 128, 128); 99 VGLBitmapCopy(tmp, 32, 32, VGLDisplay, 400, 128, 128, 128); 100 sleep(2); 101 VGLBitmapCopy(VGLDisplay, 300, 300, VGLDisplay, 500, 128, 128, 128); 102 sleep(5); 103 i=0; 104 105 // loop around drawing and copying 106 while (++i) { 107 VGLBitmapCopy(VGLDisplay, rand()%xsize, rand()%ysize, 108 VGLDisplay, rand()%xsize, rand()%ysize, 109 rand()%xsize, rand()%ysize); 110 VGLLine(VGLDisplay, rand()%xsize, rand()%ysize, 111 rand()%xsize, rand()%ysize, rand()%256); 112 VGLEllipse(VGLDisplay, rand()%xsize, rand()%ysize, 113 rand()%xsize/2, rand()%ysize/2, rand()%256); 114 rand(); 115 if (i > 1000) break; 116 } 117 118 // restore screen to its original mode 119 VGLEnd(); 120 return 0; 121 } 122 123