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