main() { char *p; float tdir = TRANS; float scal = 1.0 + SCAL; int but, nplanes; int x, y, i, n; short val; int bf = 1; int fill = 1; prefsize(500L, 500L); vinit("mswin"); winopen("lcube"); unqdevice(INPUTCHANGE); qdevice(SKEY); qdevice(XKEY); qdevice(YKEY); qdevice(ZKEY); qdevice(EQUALKEY); qdevice(MINUSKEY); qdevice(ESCKEY); qdevice(QKEY); qdevice(FKEY); qdevice(BKEY); /* * Wait for REDRAW event ... */ while (qread(&val) != REDRAW) ; window(-800.0, 800.0, -800.0, 800.0, -800.0, 800.0); lookat(0.0, 0.0, 1500.0, 0.0, 0.0, 0.0, 0); if ((nplanes = getplanes()) == 1) makecubes(0); makecubes(1); backface(1); doublebuffer(); gconfig(); /* * Doublebuffer does a backbuffer(TRUE).... */ while(1) { x = 500 - (int)getvaluator(MOUSEX); y = 500 - (int)getvaluator(MOUSEY); x *= 3; y *= 3; pushmatrix(); rotate(x, 'y'); rotate(y, 'x'); color(BLACK); clear(); callobj((Object)3); if (nplanes == 1) callobj((Object)2); popmatrix(); swapbuffers(); if (qtest()) { but = qread(&val); but = qread(&val); /* swallow up event */ switch (but) { case SKEY: scale(scal, scal, scal); break; case XKEY: translate(tdir, 0.0, 0.0); break; case YKEY: translate(0.0, tdir, 0.0); break; case ZKEY: translate(0.0, 0.0, tdir); break; case MINUSKEY: tdir = -tdir; if (scal < 1.0) scal = 1.0 + SCAL; else scal = 1.0 - SCAL; break; case EQUALKEY: tdir = TRANS; break; case BKEY: bf = !bf; backface(bf); break; case FKEY: fill = !fill; if (fill) polymode(PYM_FILL); else polymode(PYM_LINE); break; case ESCKEY: case QKEY: gexit(); exit(0); default: ; } } } }
/* init_matplot: initialises distmat plotting. The matrix size should * be Row x Col (which is the min. size in pixels). Title is put on the top * of the window by the window manager. Xorig and Yorig specify * the lower left corner position of the window: if either of them * is negative, then the window will be positioned interactively. * Return value: the 'gid' window ID number. */ long init_matplot(unsigned int Row, unsigned int Col, char *Title, long Xorig, long Yorig) { const unsigned int MINSIZE=500; long Gid, Xsize, Ysize, Xmax, Ymax; float Xmagnif, Ymagnif; unsigned int Rs, Cs; if (!Row) Row=MINSIZE; if (!Col) Col=MINSIZE; Xmagnif=(float)Col/MINSIZE; Ymagnif=(float)Row/MINSIZE; Rs=Row; Cs=Col; if (Col<=Row) { if (Xmagnif<1.0) { Cs=MINSIZE; Rs=round_id(Row/Xmagnif); } } else { if (Ymagnif<1.0) { Rs=MINSIZE; Cs=round_id(Col/Ymagnif); } } foreground(); /* enable signal catch etc. */ Xmax=getgdesc(GD_XPMAX); Ymax=getgdesc(GD_YPMAX); keepaspect(Col, Row); /* Xmax,Ymax: the maximal screen coordinates */ Xmax=getgdesc(GD_XPMAX); Ymax=getgdesc(GD_YPMAX); if (Xorig+Cs>Xmax) Xorig=Xmax-Cs; if (Yorig+Rs>Ymax) Yorig=Ymax-Rs; if (Xorig>=0 && Yorig>=0) prefposition(Xorig, Xorig+Cs, Yorig, Yorig+Rs); iconsize(84, 67); Gid=winopen(Title); /* create window */ RGBmode(); /* check if double buffering is available */ if (Dblbuffer=getgdesc(GD_BITS_NORM_DBL_BLUE)) { doublebuffer(); gconfig(); } else fputs("init_matplot: single-buffer mode\n", stderr); /* enable resize */ winconstraints(); keepaspect(Col, Row); winconstraints(); getsize(&Xsize, &Ysize); /* scale drawing into window */ Xmagnif=(float)Xsize/Col; Ymagnif=(float)Ysize/Row; pushmatrix(); scale(Xmagnif, Ymagnif, 1.0); cpack(RGB_BLACK); clear(); /* clears window to black */ if (Dblbuffer) { swapbuffers(); cpack(RGB_BLACK); clear(); } /* queue input events */ qdevice(ESCKEY); qdevice(WINFREEZE); qdevice(WINTHAW); qdevice(REDRAWICONIC); qdevice(WINQUIT); return(Gid); }
main() { int i, itest, dobackface, dofill, dodouble; char buf[100]; float H; short idata; int xr, yr; vinit("mswin"); winopen("piston"); /* * Wait for REDRAW event ... */ while (qread(&idata) != REDRAW) ; doublebuffer(); gconfig(); unqdevice(INPUTCHANGE); qdevice(QKEY); qdevice(FKEY); qdevice(BKEY); qdevice(ESCKEY); qdevice(REDRAW); makecyl(); polymode(PYM_FILL); backface(1); /* * set up a perspective projection with a field of view of * 40.0 degrees, aspect ratio of 1.0, near clipping plane 0.1, * and the far clipping plane at 1000.0. */ perspective(400, 1.5, 0.1, 600.0); lookat(0.0, -6.0, 4., 0.0, 0.0, 0.0, 0); /* * here we loop back here adnaseum until someone hits a key */ xr = yr = 0; while(1) { for (i = 0; i < 360; i += 5) { color(BLACK); clear(); color(RED); H = 1.0 + cos(2.0 * 3.14159265*i / 180.0); yr = 500 - (int)getvaluator(MOUSEY); xr = 500 - (int)getvaluator(MOUSEX); yr = 500 - (int)getvaluator(MOUSEY); xr *= 3; yr *= 3; pushmatrix(); rotate(xr, 'x'); rotate(yr, 'y'); piston(H); popmatrix(); if (dodouble) swapbuffers(); if (qtest()) { itest = qread(&idata); itest = qread(&idata); /* Zap Up event */ if (itest == BKEY) { dobackface = !dobackface; backface(dobackface); } else if (itest == FKEY) { dofill = !dofill; if (dofill) polymode(PYM_FILL); else polymode(PYM_LINE); } else if(itest == QKEY || itest == ESCKEY) { gexit(); exit(0); } } } } }
int gfxengine_t::show() { log_printf(DLOG, "Opening screen...\n"); int flags = 0; if(!is_open) return -1; if(is_showing) return 0; // if(_centered && !_fullscreen) // SDL_putenv((char *)"SDL_VIDEO_CENTERED=1"); if(!SDL_WasInit(SDL_INIT_VIDEO)) if(SDL_InitSubSystem(SDL_INIT_VIDEO) == -1) { log_printf(ELOG, "Failed to initialize SDL!\n"); return -2; } switch(_driver) { case GFX_DRIVER_SDL2D: break; case GFX_DRIVER_GLSDL: if(!_doublebuf) { log_printf(WLOG, "Only double buffering is supported" " with OpenGL drivers!\n"); doublebuffer(1); } if(_shadow) { log_printf(WLOG, "Shadow buffer not supported" " with OpenGL drivers!\n"); shadow(0); } break; } switch(_driver) { case GFX_DRIVER_SDL2D: /* Nothing extra */ break; case GFX_DRIVER_GLSDL: flags |= SDL_GLSDL; break; } if(_doublebuf) flags |= SDL_DOUBLEBUF | SDL_HWSURFACE; else { if(!_shadow) flags |= SDL_HWSURFACE; } if(_fullscreen){ flags |= SDL_WINDOW_FULLSCREEN; } glSDL_VSync(_vsync); flags |= xflags; // SDL_WM_SetCaption(_title, _icontitle); // screen_surface = SDL_SetVideoMode(_width, _height, _depth, flags); if(SDL_CreateWindowAndRenderer(0, 0, 0, &myscreen, &renderer) < 0) exit(2); sdlTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, _width, _height); screen_surface = SDL_CreateRGBSurface(0, _width, _height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); // myscreen = SDL_CreateWindow("SDL2 Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, _width, _height, flags); // screen_surface = SDL_GetWindowSurface(myscreen); if(!screen_surface) { log_printf(ELOG, "Failed to open display! %i, %i, %i\n", _width, _height, flags); return -3; } if(_driver != GFX_DRIVER_GLSDL) { if((screen_surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { if(!_doublebuf) { log_printf(WLOG, "Could not get" " single buffered display.\n"); doublebuffer(1); } } else { if(_doublebuf) { log_printf(WLOG, "Could not get" " double buffered display.\n"); doublebuffer(0); } } } if((screen_surface->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { if(_shadow) { softbuf = SDL_CreateRGBSurface(SDL_SWSURFACE, _width, _height, screen_surface->format->BitsPerPixel, screen_surface->format->Rmask, screen_surface->format->Gmask, screen_surface->format->Bmask, screen_surface->format->Amask); if(!softbuf) { log_printf(WLOG, "Failed to create shadow buffer! " "Trying direct rendering.\n"); shadow(0); } } } else { if(_shadow) log_printf(WLOG, "Shadow buffer requested; " "relying on SDL's shadow buffer.\n"); else { log_printf(WLOG, "Could not get h/w display surface.\n"); shadow(0); //...which means we're using SDL's shadow. } } // SDL_WM_SetCaption(_title, _icontitle); SDL_ShowCursor(_cursor); cs_engine_set_size(csengine, _width, _height); csengine->filter = use_interpolation; dither(_dither); noalpha(alpha_threshold); is_showing = 1; fullwin = new window_t; fullwin->init(this); fullwin->place(0, 0, (int)(_width / xscale()), (int)(_height / yscale())); clear(); return 0; }