#include "GLCanvas.h" #include #include #include /*************************************************************************** S A V E G L S T A C K S T A T E S ***************************************************************************/ Matrix gSaveViewing; Matrix gSaveProjection; void saveGLStackStates(void) { long origmode; origmode=getmmode(); mmode(MVIEWING); getmatrix(gSaveViewing); mmode(MPROJECTION); getmatrix(gSaveProjection); mmode(origmode); } /*************************************************************************** R E S T O R E G L S T A C K S T A T E S ***************************************************************************/ void restoreGLStackStates(void) { long origmode; origmode=getmmode(); mmode(MVIEWING); loadmatrix(gSaveViewing); mmode(MPROJECTION); loadmatrix(gSaveProjection); mmode(origmode); } /*************************************************************************** D R A W C A N V A S ***************************************************************************/ void drawCanvas(GLCanvas *canvas) /*!*/ { long totalx; long totaly; long winx; long winy; long xcorner; long ycorner; long xcenter; long ycenter; long halfx,halfy; long left,right,bottom,top; saveGLStackStates(); lrectwrite(0, 0, canvas->width-1, canvas->height-1, (unsigned long *)canvas->pixels); restoreGLStackStates(); /***/ /* Stick a return; right here to skip all the funky stuff */ /***/ return; getsize(&winx,&winy); /*if (winxwidth) totalx=winx; else totalx=canvas->width;*/ /*if (winyheight) totaly=winy; else totaly=canvas->height;*/ totalx=winx; totaly=winy; totalx=totalx/(long)canvas->sizemultiplier; totaly=totaly/(long)canvas->sizemultiplier; halfx=totalx/2; halfy=totaly/2; xcenter=canvas->width / 2; ycenter=canvas->height / 2; left=xcenter-halfx; right=xcenter+halfx; top=ycenter+halfx; bottom=ycenter-halfx; if (left<0) left=0; if (right>winx-1) right=winx-1; if (bottom<0) bottom=0; if (top>winy-1) top=winy-1; rectzoom(canvas->sizemultiplier,canvas->sizemultiplier); rectcopy(left,top,right,bottom,0,0); xcorner=(xcenter-totalx/2); ycorner=(ycenter-totaly/2); rectzoom(1.0,1.0); } /*************************************************************************** I N V E R T C A N V A S ***************************************************************************/ void invertcanvas(struct GLCanvas *canvas) /*!*/ { struct GLCanvas ac; int size; int i; unsigned int *newloc; unsigned int *oldloc; size = canvas->width * canvas->height; ac.width = canvas->width; ac.height = canvas->height; ac.pixels = (unsigned int *) malloc (size * sizeof(int)); for (i=0;ipixels + (i*canvas->width); memcpy(newloc,oldloc,ac.width*sizeof(int)); } free(canvas->pixels); canvas->pixels=ac.pixels; }