/* $Id: vtest.c,v 1.1 1999/02/17 14:27:51 brianp Exp $ */

/*
 * Test SVGA/Mesa interface in 32K color mode.
 *
 * Compile with:  gcc vtest.c -I../include -L../lib -lMesaGL -lX11 -lXext
 *   -lvga -lm -o vtest
 *
 * This program is in the public domain.
 * Brian Paul, January 1996
 */



#include <vga.h>
#include "GL/svgamesa.h"
#include "GL/gl.h"


SVGAMesaContext vmc;



void setup( void )
{
   vga_init();

   vga_setmode(G800x600x32K);
/*   gl_setcontextvga(G800x600x32K);*/

   vmc = SVGAMesaCreateContext( GL_FALSE );  /* single buffered */
   SVGAMesaMakeCurrent( vmc );
}


void test( void )
{
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
   glMatrixMode(GL_MODELVIEW);

   glClear( GL_COLOR_BUFFER_BIT );

   glBegin( GL_LINES );
   glColor3f( 1.0, 0.0, 0.0 );
   glVertex2f( -0.5, 0.5 );
   glVertex2f(  0.5, 0.5 );
   glColor3f( 0.0, 1.0, 0.0 );
   glVertex2f( -0.5, 0.25 );
   glVertex2f(  0.5, 0.25 );
   glColor3f( 0.0, 0.0, 1.0 );
   glVertex2f( -0.5, 0.0 );
   glVertex2f(  0.5, 0.0 );
   glEnd();

   glBegin( GL_POLYGON );
   glColor3f( 1.0, 0.0, 0.0 );
   glVertex2f( 0.0, 0.7 );
   glColor3f( 0.0, 1.0, 0.0 );
   glVertex2f( -0.5, -0.5 );
   glColor3f( 0.0, 0.0, 1.0 );
   glVertex2f(  0.5, -0.5 );
   glEnd();

   sleep(3);
}

void end( void )
{
   SVGAMesaDestroyContext( vmc );

   vga_setmode( TEXT );
}


int main( int argc, char *argv[] )
{
   setup();
   test();
   end();
   return 0;
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               /* $Id: xdemo.c,v 3.0 1998/02/21 02:16:54 brianp Exp $ */


/*
 * Very simple demo of how to use the Mesa/X11 interface instead of the
 * glx, tk or aux toolkits.  I highly recommend using the GLX interface
 * instead of the X/Mesa interface, however.
 *
 * This program is in the public domain.
 *
 * Brian Paul
 */


/*
 * $Log: xdemo.c,v $
 * Revision 3.0  1998/02/21 02:16:54  brianp
 * initial rev
 *
 */



#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "GL/xmesa.h"
#include "GL/gl.h"



static GLint Black, Red, Green, Blue;



static void make_window( char *title, int color_flag )
{
   int x = 10, y = 10, width = 400, height = 300;
   Display *dpy;
   int scr;
   Window root, win;
   Colormap cmap;
   XColor xcolor;
   int attr_flags;
   XVisualInfo *visinfo;
   XSetWindowAttributes attr;
   XTextProperty tp;
   XSizeHints sh;
   XEvent e;
   XMesaContext context;
   XMesaVisual visual;
   XMesaBuffer buffer;


   /*
    * Do the usual X things to make a window.
    */

   dpy = XOpenDisplay(NULL);
   if (!dpy) {
      printf("Couldn't open default display!\n");
      exit(1);
   }

   scr = DefaultScreen(dpy);
   root = RootWindow(dpy, scr);

   /* alloc visinfo struct */
   visinfo = (XVisualInfo *) malloc( sizeof(XVisualInfo) );

   /* Get a visual and colormap */
   if (color_flag) {
      /* Open TrueColor window */

/*
      if (!XMatchVisualInfo( dpy, scr, 24, TrueColor, visinfo )) {
	 printf("Couldn't get 24-bit TrueColor visual!\n");
	 exit(1);
      }
*/
      if (!XMatchVisualInfo( dpy, scr, 8, PseudoColor, visinfo )) {
	 printf("Couldn't get 8-bit PseudoColor visual!\n");
	 exit(1);
      }

      cmap = XCreateColormap( dpy, root, visinfo->visual, AllocNone );
      Black = Red = Green = Blue = 0;
   }
   else {
      /* Open color index window */

      if (!XMatchVisualInfo( dpy, scr, 8, PseudoColor, visinfo )) {
	 printf("Couldn't get 8-bit PseudoColor visual\n");
	 exit(1);
      }

      cmap = XCreateColormap( dpy, root, visinfo->visual, AllocNone );

      /* Allocate colors */
      xcolor.red   = 0x0;
      xcolor.green = 0x0;
      xcolor.blue  = 0x0;
      xcolor.flags = DoRed | DoGreen | DoBlue;
      if (!XAllocColor( dpy, cmap, &xcolor )) {
	 printf("Couldn't allocate black!\n");
	 exit(1);
      }
      Black = xcolor.pixel;

      xcolor.red   = 0xffff;
      xcolor.green = 0x0;
      xcolor.blue  = 0x0;
      xcolor.flags = DoRed | DoGreen | DoBlue;
      if (