www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/02/02/17:28:15

Date: Thu, 2 Feb 1995 15:07:43 -0500 (EST)
From: David Max <max AT SLINKY DOT CS DOT NYU DOT EDU>
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: LIBGRX for djgpp

On Thu, 2 Feb 1995, G.Mackrill wrote:

> Can you help?? I have been attempting to use to screen buffers and swap
> between them so as to remove the flicker when displaying 3d animations.
> Unfortunately i have not been able to succeed.  Can anyone tell me how this
> can be achieved using LIBGRX..
> 
Below is code that I have used to do page flipping in various ways.

David Max
New York University
WWW: http://found.cs.nyu.edu/robust.a/student/max/public-html/index.html

/***************************************************************************
 PAGEFLIP.C

 This version uses VGA calls to flip pages.
***************************************************************************/
 
#include <stdlib.h>
#include <dos.h>
#include <pc.h>
#include <grx.h>
 
GrContext *page0, *page1;      
unsigned char screenpage;
 
#define DISPIO             0x3DA
#define VRT_bit            8
#define CRTC_INDEX         0x3d4
#define START_ADDRESS_HIGH 0x0c
 
void pageflip(void)
{
   screenpage ^= 1;                
   if (screenpage) GrSetContext(page0);
   else GrSetContext(page1);
   
	outportw(CRTC_INDEX, (screenpage << 15) | START_ADDRESS_HIGH);
   
   /* Wait for Vertical Retrace before continuing */
	while (inportb(DISPIO) & VRT_bit);
   while ((inportb(DISPIO) & VRT_bit) == 0);
}
    
void opengraphics(void)
{
   GrSetMode(GR_width_height_color_graphics,320,240,256);
   page0 = GrSaveContext(page0);
   page1 = GrSaveContext(page1);
   page1->gc_baseaddr += 0x8000;
   screenpage = 0;
   pageflip();
}
 
			


/***************************************************************************
 PAGEFLIP.C

 This version uses VESA calls to set up double-buffered 1024x768x16 graphics.
 On my machine, this is using univbe with my Diamond Speedstar 24X and the
 go32 default VESA graphics.
***************************************************************************/

#include <stdlib.h>
#include <dos.h>
#include <pc.h>
#include <math.h>
#include <grx.h>
#include "pageflip.h"  /* contains function prototypes */

/* Global variables */

GrContext *page[2];
unsigned int screenpage;
union REGS reg, reg2;
      
void pageflip(void)
{
   GrSetContext(page[screenpage]);
   screenpage ^= 1;               

   reg.x.dx=768*screenpage;

   int86(0x10,&reg,&reg2);
   /* Apparently, at least on my card, this VESA call includes a 
      wait-for-retrace, so explicitly waiting for vertical retrace
      here would be redundant. */
}

void opengraphics(void)
{
    /* set up regs for the VESA call that specifies the starting scan 
       line. */
    reg.x.ax=0x4F07;
    reg.h.bh=0;
    reg.h.bl=0;
    reg.x.cx=0;
 
    GrSetMode(GR_width_height_color_graphics,1024,768,16);
    page[0] = GrSaveContext(page[0]);
    page[1] = GrSaveContext(page[1]);
    page[1]->gc_baseaddr += 0x18000;
    screenpage = 0;
    pageflip();    
}


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019