/share/examples/libvgl/demo.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 122 lines · 66 code · 12 blank · 44 comment · 7 complexity · 4ad6ea3c4bf37783e53a2aa487c57192 MD5 · raw file

  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$
  29. */
  30. #include <sys/types.h>
  31. #include <sys/fbio.h>
  32. #include <sys/kbio.h>
  33. #include <sys/consio.h>
  34. #include <vgl.h>
  35. int
  36. main(int argc, char **argv)
  37. {
  38. int y, xsize, ysize, i,j;
  39. VGLBitmap *tmp;
  40. // set graphics mode, here 320x240 256 colors
  41. // supported modes are (from <sys/consio.h>):
  42. // SW_VGA_CG320: std VGA 320x200 256 colors
  43. // SW_VGA_MODEX: Modex VGA 320x240 256 colors
  44. // SW_VGA_VG640: std VGA 640x480 16 colors
  45. VGLInit(SW_VGA_MODEX);
  46. // initialize mouse and show pointer
  47. VGLMouseInit(VGL_MOUSESHOW);
  48. // VGLDisplay is a ptr to a struct Bitmap defined and initialized by
  49. // libvgl. The Bitmap points directly to screen memory etc.
  50. xsize=VGLDisplay->Xsize;
  51. ysize=VGLDisplay->Ysize;
  52. // alloc a new bitmap
  53. tmp = VGLBitmapCreate(MEMBUF, 256, 256, NULL);
  54. VGLBitmapAllocateBits(tmp);
  55. VGLClear(tmp, 0);
  56. // fill the screen with colored lines
  57. for (y=0; y<ysize; y++)
  58. VGLLine(VGLDisplay, 0, y, xsize-1, y, y/2 % 256);
  59. // draw some lines and circles just to show off
  60. VGLLine(VGLDisplay, 0, 0, xsize-1, ysize-1, 63);
  61. VGLLine(VGLDisplay, 0, ysize-1, xsize-1, 0, 63);
  62. VGLLine(VGLDisplay, 0, 0, 0, ysize-1, 63);
  63. VGLLine(VGLDisplay, xsize-1, 0, xsize-1, ysize-1, 63);
  64. VGLEllipse(VGLDisplay, 256, 0, 256, 256, 63);
  65. VGLEllipse(VGLDisplay, 0, 256, 256, 256, 0);
  66. // some text is also useful
  67. VGLBitmapString(VGLDisplay, 100,100,
  68. "This is text", 63, 0, 0, VGL_DIR_RIGHT);
  69. sleep(2);
  70. VGLBitmapString(VGLDisplay, 100,100,
  71. "This is text", 63, 0, 0, VGL_DIR_UP);
  72. sleep(2);
  73. VGLBitmapString(VGLDisplay, 100,100,
  74. "This is text", 63, 0, 0, VGL_DIR_LEFT);
  75. sleep(2);
  76. VGLBitmapString(VGLDisplay, 100,100,
  77. "This is text", 63, 0, 0, VGL_DIR_DOWN);
  78. sleep(2);
  79. // now show some simple bitblit
  80. for (i=0; i<256; i++)
  81. for (j=0; j<256; j++)
  82. tmp->Bitmap[i+256*j] = i%16;
  83. VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 0, 0, 128, 128);
  84. for (i=0; i<256; i++)
  85. for (j=0; j<256; j++)
  86. tmp->Bitmap[i+256*j] = j%16;
  87. VGLBitmapCopy(tmp, 0, 0, VGLDisplay, 3, 128, 128, 128);
  88. sleep(2);
  89. VGLBitmapCopy(VGLDisplay, 237, 311, tmp, 64, 64, 128, 128);
  90. VGLBitmapCopy(tmp, 32, 32, VGLDisplay, 400, 128, 128, 128);
  91. sleep(2);
  92. VGLBitmapCopy(VGLDisplay, 300, 300, VGLDisplay, 500, 128, 128, 128);
  93. sleep(5);
  94. i=0;
  95. // loop around drawing and copying
  96. while (++i) {
  97. VGLBitmapCopy(VGLDisplay, rand()%xsize, rand()%ysize,
  98. VGLDisplay, rand()%xsize, rand()%ysize,
  99. rand()%xsize, rand()%ysize);
  100. VGLLine(VGLDisplay, rand()%xsize, rand()%ysize,
  101. rand()%xsize, rand()%ysize, rand()%256);
  102. VGLEllipse(VGLDisplay, rand()%xsize, rand()%ysize,
  103. rand()%xsize/2, rand()%ysize/2, rand()%256);
  104. rand();
  105. if (i > 1000) break;
  106. }
  107. // restore screen to its original mode
  108. VGLEnd();
  109. return 0;
  110. }