int main(int argc, char *argv[]) { vga_init(); if(argc>=2) { timescale=atoi(argv[1]); if(timescale<1)timescale=1; } VGAMODE = vga_getdefaultmode(); if (VGAMODE == -1) VGAMODE = G320x200x256; /* Default mode. */ if (!vga_hasmode(VGAMODE)) { printf("Mode not available.\n"); exit(-1); } VIRTUAL = 0; /* No virtual screen. */ if (vga_getmodeinfo(VGAMODE)->colors == 16 || (vga_getmodeinfo(VGAMODE)->flags & IS_MODEX)) /* These modes are supported indirectly by vgagl. */ VIRTUAL = 1; if (VIRTUAL) { /* Create virtual screen. */ gl_setcontextvgavirtual(VGAMODE); backscreen = gl_allocatecontext(); gl_getcontext(backscreen); } vga_setmode(VGAMODE); gl_setcontextvga(VGAMODE); /* Physical screen context. */ physicalscreen = gl_allocatecontext(); gl_getcontext(physicalscreen); if (COLORS == 256) gl_setrgbpalette(); if(argc==3)sleep(2); test(); /* Now do the same with clipping enabled. */ gl_clearscreen(0); gl_setclippingwindow(WIDTH / 4, HEIGHT / 4, WIDTH - WIDTH / 4 - 1, HEIGHT - HEIGHT / 4 - 1); test(); gl_disableclipping(); if (COLORS == 256) /* Show the logo if using 256 color mode. */ logotest(); getchar(); if (VIRTUAL) gl_freecontext(backscreen); vga_setmode(TEXT); exit(0); }
/* * Term hook * Initialize a new term */ static void term_init_svgalib(term *t) { int vgamode; /* Only one term */ (void) t; vga_init(); /* The palette is 256x3 bytes big (RGB). */ C_MAKE(pal, 768, byte); #ifdef USE_GRAPHICS /* Hardwire this mode in for now */ vgamode = G1024x768x256; /* Set up the bitmap buffer context */ gl_setcontextvgavirtual(vgamode); buffer = gl_allocatecontext(); gl_getcontext(buffer); /* Load bitmap into virtual screen */ term_load_bitmap(); #endif /* USE_GRAPHICS */ /* Hardwire this mode in for now */ vgamode = G640x480x256; /* Set up the physical screen context */ if (vga_setmode(vgamode) < 0) { quit("Graphics mode not available!"); } gl_setcontextvga(vgamode); screen = gl_allocatecontext(); gl_getcontext(screen); /* Is this needed? */ gl_enablepageflipping(screen); /* Set up palette colors */ setpal(); /* Load the character font data */ initfont(); /* Color 0 isn't transparent */ gl_setwritemode(WRITEMODE_OVERWRITE); }
bool screen_init (void) { #ifdef LINUXFB use_fb = 1; if (fb_init ()) { use_fb = 0; return false; } #endif #ifdef VGALIB use_fb = 0; vga_init (); vga_setmode(DEFAULT_VGA_MODE); gl_setcontextvga(DEFAULT_VGA_MODE); physical_screen = gl_allocatecontext(); gl_getcontext(physical_screen); gl_setcontextvgavirtual(DEFAULT_VGA_MODE); virtual_screen = gl_allocatecontext(); gl_getcontext(virtual_screen); gl_setcontext(virtual_screen); //vga_ext_set(VGA_EXT_SET, VGA_CLUT8); // color table: // http://en.wikipedia.org/wiki/ANSI_escape_code#Colors gl_setpalettecolor(BLUE, 0, 0, 63); // blue gl_setpalettecolor(BLACK, 0, 0, 0); // black gl_setpalettecolor(GREEN, 0, 63, 0); gl_setpalettecolor(RED, 63, 0, 0); gl_setpalettecolor(BROWN, 170/4, 85/4, 0); gl_setpalettecolor(MAGENTA, 170/4, 0, 170/4); gl_setpalettecolor(CYAN, 0, 170/4, 170/4); gl_setpalettecolor(GRAY, 48, 48, 48); gl_setpalettecolor(LIGHTBLACK, 85/4, 85/4, 85/4); gl_setpalettecolor(LIGHTBLUE, 85/4, 85/4, 255/4); gl_setpalettecolor(LIGHTGREEN, 85/4, 255/4, 85/4); gl_setpalettecolor(LIGHTCYAN, 85/4, 255/4, 255/4); gl_setpalettecolor(LIGHTRED, 25/45/4, 85/4, 85/4); gl_setpalettecolor(LIGHTMAGENTA, 255/4, 85/4, 255/4); gl_setpalettecolor(LIGHTBROWN, 255/4, 255/4, 85/4); #endif active_console = 1; return true; }
//! [1] bool SvgalibScreen::initDevice() { if (vga_init() != 0) { qCritical("SvgalibScreen::initDevice(): unable to initialize svgalib"); return false; } int mode = vga_getdefaultmode(); if (vga_setmode(mode) == -1) { qCritical("SvgalibScreen::initialize(): unable to set graphics mode"); return false; } if (gl_setcontextvga(mode) != 0) { qCritical("SvgalibScreen::initDevice(): unable to set vga context"); return false; } context = gl_allocatecontext(); gl_getcontext(context); vga_modeinfo *modeinfo = vga_getmodeinfo(mode); if (modeinfo->flags & IS_LINEAR) QScreen::data = vga_getgraphmem(); initColorMap(); QScreenCursor::initSoftwareCursor(); return true; }
void initscreen(void) { int vgamode; vga_init(); vgamode = G640x480x16; if (!vga_hasmode(vgamode)) { printf("Mode not available.\n"); exit(-1); } vga_setmode(vgamode); /* Create virtual screen. */ gl_setcontextvgavirtual(vgamode); backscreen = gl_allocatecontext(); gl_getcontext(backscreen); /* Physical screen context. */ vga_setmode(vgamode); gl_setcontextvga(vgamode); physicalscreen = gl_allocatecontext(); gl_getcontext(physicalscreen); gl_setcontext(backscreen); /*drawgraypalette(); */ gl_clearscreen(0); // gl_setcontextvga(vgamode); gl_enableclipping(); gl_setclippingwindow(0, 0, 639, 479); gl_setwritemode(WRITEMODE_OVERWRITE | FONT_COMPRESSED); gl_setfont(8, 8, gl_font8x8); gl_setfontcolors(0, 1); }
void configure(void) { int allowed[GLASTMODE + 1]; for (;;) { int i; int m; for (i = G320x200x16; i <= GLASTMODE; i++) { allowed[i] = 0; if (vga_hasmode(i)) { printf("%2d %s\n", i, vga_getmodename(i)); allowed[i] = 1; } } printf("\nWhich mode? "); scanf("%d", &m); getchar(); printf("\n"); if (m >= G320x200x16 && m <= GLASTMODE) { VGAMODE = m; if (vga_getmodeinfo(m)->bytesperpixel >= 1) USEGL = 1; else USEGL = 0; break; } } vga_setmode(VGAMODE); #ifdef LINEAR_ADDRESSING vga_setlinearaddressing(); #endif if (USEGL) { gl_setcontextvga(VGAMODE); physicalscreen = gl_allocatecontext(); gl_getcontext(physicalscreen); } }
void demo3(void) { int x, y; int targetx, targety; int count, startclock; GraphicsContext *virtualscreen; GraphicsContext *physicalscreen; /* Window coordinate initially at center. */ x = VWIDTH / 2 - WINWIDTH / 2; y = VHEIGHT / 2 - WINHEIGHT / 2; targetx = x; targety = y; virtualscreen = gl_allocatecontext(); gl_getcontext(virtualscreen); gl_setcontextvga(G320x200x256); physicalscreen = gl_allocatecontext(); gl_getcontext(physicalscreen); gl_setcontext(virtualscreen); count = 0; startclock = clock(); for (;;) { vga_waitretrace(); /* Copy window to screen. */ gl_copyboxtocontext(x, y, WINWIDTH, WINHEIGHT, physicalscreen, 0, 0); if (x == targetx && y == targety) { /* Create new target. */ targetx = rand() % (VWIDTH - WINWIDTH); targety = rand() % (VHEIGHT - WINHEIGHT); } /* Move towards target. */ if (x < targetx) x++; if (x > targetx) x--; if (y < targety) y++; if (y > targety) y--; /* Boundary checks. */ if (x < 0) x = 0; if (x > VWIDTH - WINWIDTH) x = VWIDTH - WINWIDTH; if (y < 0) y = 0; if (y > VHEIGHT - WINHEIGHT) y = VHEIGHT - WINHEIGHT; if (vga_getkey()) break; count++; } printf("Method 3: frame rate %ld\n", count * CLOCKS_PER_SEC / (clock() - startclock)); }
int main() { int maxCols = 1024; int maxRows = 768; int maxIterations = 2048; int maxSize = 4; float Xmin = -2.0; float Xmax = 1.2; float Ymin = -1.2; float Ymax = 1.2; double X, Y; double Xsquare, Ysquare; double currentP; double currentQ[767]; double deltaP, deltaQ; int color; int currentRow, currentCol; deltaP = (Xmax - Xmin)/(double)maxCols; deltaQ = (Ymax - Ymin)/(double)maxRows; currentQ[0] = Ymax; for (currentRow = 1; currentRow < maxRows; currentRow++) { currentQ[currentRow] = currentQ[currentRow-1] - deltaQ; } currentP = Xmin; vga_init(); vga_setmode(G1024x768x256); gl_setcontextvga(G1024x768x256); physicalscreen = gl_allocatecontext(); gl_getcontext(physicalscreen); gl_setcontextvgavirtual(G1024x768x256); virtualscreen = gl_allocatecontext(); gl_getcontext(virtualscreen); gl_setcontext(virtualscreen); for (currentCol = 0; currentCol < maxCols; currentCol++) { for (currentRow = 0; currentRow < maxRows; currentRow++) { X = 0.0; Y = 0.0; Xsquare = 0.0; Ysquare = 0.0; color = 0; while ((color <= maxIterations) && (Xsquare + Ysquare <= maxSize)) { Xsquare = X * X; Ysquare = Y * Y; Y = (2*X*Y) + currentQ[currentRow]; X = (Xsquare - Ysquare) + currentP; color++; } gl_setpixel(currentCol, currentRow, color % 256); } currentP = currentP + deltaP; gl_copyscreen(physicalscreen); } vga_getch(); gl_clearscreen(0); vga_setmode(TEXT); return 0; }
void test(void) { int i, j; unsigned char *bitmap; GraphicsContext *savedcontext; if (VIRTUAL) gl_setcontext(backscreen); gl_clearscreen(0); for (i = 0; i < 5; i++) { gl_clearscreen(0); for (j = 0; j < 20000; j++) gl_setpixel(random() % WIDTH, random() % HEIGHT, random() % COLORS); } if (VIRTUAL) gl_copyscreen(physicalscreen); gl_clearscreen(0); for (i = 0; i < 5000; i++) { int x, y; x = random() % (WIDTH - 1); y = random() % (HEIGHT - 1); gl_fillbox(x, y, random() % (WIDTH - x), random() % (HEIGHT - y), random() % COLORS); } if (VIRTUAL) gl_copyscreen(physicalscreen); gl_clearscreen(0); for (i = 0; i < 4000; i++) gl_line(random() % WIDTH, random() % HEIGHT, random() % WIDTH, random() % HEIGHT, random() % COLORS); if (VIRTUAL) gl_copyscreen(physicalscreen); /* Create bitmap. */ bitmap = malloc(64 * 64 * BYTESPERPIXEL); /* Create temporary graphics context to create bitmap in. */ savedcontext = gl_allocatecontext(); gl_getcontext(savedcontext); gl_setcontextvirtual(64, 64, BYTESPERPIXEL, BITSPERPIXEL, bitmap); /* The rgb functions can be used to create nice bitmaps easily for */ /* hicolor/truecolor modes. The 256 color 'emulated' truecolor */ /* looks less impressive. */ for (i = 0; i < 32; i++) for (j = 0; j < 32; j++) { int c; c = 255 - (i + j) * 4; gl_setpixelrgb(31 - i, 31 - j, c, 0, 0); gl_setpixelrgb(32 + i, 31 - j, c, c, 0); gl_setpixelrgb(31 - i, 32 + j, c, 0, c); gl_setpixelrgb(32 + i, 32 + j, c, c, c); } /* Restore previous context. */ gl_setcontext(savedcontext); gl_clearscreen(0); for (i = 0; i < 4000; i++) { int x, y; x = random() % (WIDTH - 64 + 1); y = random() % (HEIGHT - 64 + 1); gl_putbox(x, y, 64, 64, bitmap); } free(bitmap); if (VIRTUAL) gl_copyscreen(physicalscreen); }
int gr_set_mode(u_int32_t mode) { unsigned int w, h; char vgamode[16]; vga_modeinfo *modeinfo; int modenum, rowsize; void *framebuffer; #ifdef NOGRAPH return 0; #endif if (mode<=0) return 0; w=SM_W(mode); h=SM_H(mode); gr_palette_clear(); sprintf(vgamode, "G%dx%dx256", w, h); modenum = vga_getmodenumber(vgamode); vga_setmode(modenum); #ifdef SVGALIB_INPUT mouse_seteventhandler(mouse_handler); #endif modeinfo = vga_getmodeinfo(modenum); if (modeinfo->flags & CAPABLE_LINEAR) { usebuffer = 0; vga_setlinearaddressing(); // Set up physical screen only gl_setcontextvga(modenum); physicalscreen = gl_allocatecontext(); gl_getcontext(physicalscreen); screenbuffer = physicalscreen; framebuffer = physicalscreen->vbuf; rowsize = physicalscreen->bytewidth; } else { usebuffer = 1; // Set up the physical screen gl_setcontextvga(modenum); physicalscreen = gl_allocatecontext(); gl_getcontext(physicalscreen); // Set up the virtual screen gl_setcontextvgavirtual(modenum); screenbuffer = gl_allocatecontext(); gl_getcontext(screenbuffer); framebuffer = screenbuffer->vbuf; rowsize = screenbuffer->bytewidth; } memset(grd_curscreen, 0, sizeof(grs_screen)); grd_curscreen->sc_mode = mode; grd_curscreen->sc_w = w; grd_curscreen->sc_h = h; grd_curscreen->sc_aspect = fixdiv(grd_curscreen->sc_w*3,grd_curscreen->sc_h*4); grd_curscreen->sc_canvas.cv_bitmap.bm_x = 0; grd_curscreen->sc_canvas.cv_bitmap.bm_y = 0; grd_curscreen->sc_canvas.cv_bitmap.bm_w = w; grd_curscreen->sc_canvas.cv_bitmap.bm_h = h; grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = rowsize; grd_curscreen->sc_canvas.cv_bitmap.bm_type = BM_LINEAR; grd_curscreen->sc_canvas.cv_bitmap.bm_data = framebuffer; gr_set_current_canvas(NULL); gamefont_choose_game_font(w,h); return 0; }