コード例 #1
0
ファイル: direct.c プロジェクト: OS2World/LIB-VIDEO-MGL
/****************************************************************************
REMARKS:
Main program entry point
****************************************************************************/
int main(void)
{
	MGLDC       	*dc,*memdc;
	event_t     	evt;
	pixel_format_t	pf;
	palette_t		pal[256];
	bitmap_t    	bmpHdr;

	/* Register the ISV license file if desired */
#ifdef	ISV_LICENSE
	GA_registerLicense(OemLicense,false);
#endif

	/* Start the MGL in 640x480 256 color mode */
	dc = MGL_quickInit(640,480,8,1);

	/* Now extract the information about the device surface to our
	 * global variables and draw on it. Note that we must check that we
	 * have direct access to the surface. If it is a bank switched
	 * surface then we cannot directly write to it, and the surface
	 * pointer will be NULL.
     *
     * Note that the MGL fully supports virtualised framebuffer surfaces,
     * so in most cases it would be very rare to get a bank switched
     * surface (in fact since we did not register the bank switched
     * drivers, it would be impossible in this sample program!).
     */
    if (MGL_surfaceAccessType(dc) == MGL_NO_ACCESS)
        MGL_fatalError("This program requires a linear access surface");
    maxx = dc->mi.xRes;
    maxy = dc->mi.yRes;
    bytesPerLine = dc->mi.bytesPerLine;
    surface = dc->surface;

    /* If we are drawing to a hardware accelerated surface, we must call
     * MGL_beginDirectAccess() and MGL_endDirectAccess() before and after
     * doing any direct surface access
     */
    if (MGL_getHardwareFlags(dc) != MGL_HW_NONE)
        MGL_beginDirectAccess();

    /* Now draw directly to display surface */
    moire();

    if (MGL_getHardwareFlags(dc) != MGL_HW_NONE)
        MGL_endDirectAccess();

    /* Wait for a keypress */
    EVT_halt(&evt,EVT_KEYDOWN);

	/* Now we allocate a system memory block for a 100x100 memory
     * surface manually and attach it to our bitmap header. Then we
     * will draw directly to it and then display it on our main device
     * context. Note that we allocate it without a palette and with
     * a pixel format info block.
     */
    bmpHdr.width = 320;
    bmpHdr.height = 240;
    bmpHdr.bitsPerPixel = 8;
    bmpHdr.bytesPerLine = bmpHdr.width;
    bmpHdr.pal = NULL;
    bmpHdr.pf = NULL;
    bmpHdr.surface = malloc(bmpHdr.bytesPerLine * bmpHdr.height);
    if (bmpHdr.surface == NULL)
        MGL_fatalError("Out of memory");
	maxx = bmpHdr.width-1;
	maxy = bmpHdr.height-1;
	bytesPerLine = bmpHdr.bytesPerLine;
	surface = bmpHdr.surface;
	memset(surface,0,bytesPerLine * (maxy+1));

	/* Now draw directly to bitmap surface and display it */
	moire();
	MGL_putBitmap(dc,160,120,&bmpHdr,MGL_REPLACE_MODE);

	/* Wait for a keypress */
	EVT_halt(&evt,EVT_KEYDOWN);

	/* Now we allocate a system memory device context and draw directly
	 * onto this surface, then blit it to the display. It is similar to
	 * the above code but does not use a lightweight bitmap as the drawing
	 * surface but a full memory device context (which you can also render
	 * to using the MGL functions).
	 */
	if ((memdc = MGL_createMemoryDC(160,120,8,&pf)) == NULL)
		MGL_fatalError(MGL_errorMsg(MGL_result()));
	maxx = memdc->mi.xRes;
	maxy = memdc->mi.yRes;
	bytesPerLine = memdc->mi.bytesPerLine;
	surface = memdc->surface;
	memset(surface,0,bytesPerLine * (maxy+1));

	/* Now set the palette for the memory device to the same as the display
	 * DC so that we avoid palette remapping (you could use a different
	 * palette and it would be automatically mapped to the screen when you
	 * do a blit, but this would be slower).
	 */
	MGL_getPalette(dc,pal,256,0);
	MGL_setPalette(memdc,pal,256,0);
	MGL_realizePalette(memdc,256,0,false);

	/* Now draw directly to bitmap surface and display it */
	moire();
	MGL_bitBltCoord(dc,memdc,0,0,160,120,240,180,MGL_REPLACE_MODE);

	/* Wait for a keypress */
	EVT_halt(&evt,EVT_KEYDOWN);

	MGL_exit();
	return 0;
}
コード例 #2
0
ファイル: capture.c プロジェクト: kendallb/scitech-mgl
/****************************************************************************
REMARKS:
Does a simple overlay buffer static video capture test. The overlay will
show what is coming in via the video capture engine.
****************************************************************************/
static int staticTest(
    GA_videoFuncs *video,
    GA_videoCaptureFuncs *capture,
    GA_captureInputTypes input,
    GA_captureStandardTypes standard,
    GA_VideoCaptureInf *captureInfo)
{
    int             key,x,y,width = DEF_WIDTH,height = DEF_HEIGHT;
    int             centerX, centerY;
    ibool           done = false,freezeInput = false,newFreezeInput = false;
    GA_captureBuf   *captureBuf = NULL;
    GA_buf          *primaryVideo = NULL;
    int             outputHead = init.GetActiveHead();
    char            str[80];

    /* Draw background for video overlay */
    SetActivePage(0);
    ClearPage(0);
    moire(defcolor);
    if (maxX >= 479)
        gmoveto(80,80);
    else
        gmoveto(8,40);
    gprintf("Video capture static test");  y += 16;
    displaymodeInfo();
    gprintf("Press any key to continue");
    if (EVT_getch() == 0x1B)
        return 0x1B;

    /* Use larger overlay window for higher resolutions */
    if (modeInfo.XResolution >= 1280) {
        width *= 2;
        height *= 2;
        }
    else if (modeInfo.XResolution <= DEF_WIDTH) {
        width /= 2;
        height /= 2;
        }

    /* Allocate the source video buffer */
    if ((captureBuf = capture->AllocCaptureBuffer(width,height,captureInfo->VideoFormat,1)) == NULL) {
        displayError("Unable to allocate video capture buffer!");
        return 0x1B;
        }
    primaryVideo = captureBuf->VideoBuffers;
    centerX = (maxX - primaryVideo->Width)/2;
    centerY = (maxY - primaryVideo->Height)/2;

    /* Set up for single buffer video overlay */
    SetActiveBuffer(primaryVideo);
    ClearVideoBuffer(primaryVideo);

    /* Set the video output window */
    x = centerX;
    y = centerY;
    if (!video->SetVideoOutput(0,outputHead,primaryVideo,
            0,0,primaryVideo->Width,primaryVideo->Height,
            x,y,primaryVideo->Width,primaryVideo->Height,0)) {
        displayError("Unable to set video output window!");
        return 0x1B;
        }

    /* Set up the video capture and start it */
    capture->SetVideoInput(captureBuf,input,standard,0,false);
    capture->StartLiveVideo(captureBuf);

    /* Now loop around and display the video capture */
    sprintf(str,"%d x %d %d bit %s overlay",primaryVideo->Width,primaryVideo->Height,
        primaryVideo->BitsPerPixel,displayFormat(primaryVideo->Format));
    if (width < DEF_WIDTH)
        WriteText(8,60,displayFormat(primaryVideo->Format),defcolor);
    else
        WriteText(8,80,str,defcolor);
    while (!done) {
        if (handleKeypress(&key,&newFreezeInput))
            break;
        if (freezeInput != newFreezeInput) {
            freezeInput = newFreezeInput;
            if (freezeInput)
                capture->FreezeLiveVideo(captureBuf,gaCaptureFieldAny);
            else
                capture->StartLiveVideo(captureBuf);
            }
        }
    SetActivePage(0);
    video->DisableVideoOutput(0);
    capture->FreeCaptureBuffer(captureBuf);
    return key;
}
コード例 #3
0
ファイル: display_loop.c プロジェクト: stefanctdo/borgware-2d
void display_loop(){
//	mcuf_serial_mode();

	mode = setjmp(newmode_jmpbuf);

#ifdef JOYSTICK_SUPPORT
	// in case we get here via mode jump, we (re)enable joystick queries
	waitForFire = 1;
#endif

	oldOldmode = oldMode;

#ifdef JOYSTICK_SUPPORT
	waitForFire = 1;
#endif

	for(;;){
#ifndef MENU_SUPPORT
		clear_screen(0);
#endif
		oldMode = mode;

		switch(mode++) {

#ifdef ANIMATION_SCROLLTEXT
		case 1:
			scrolltext(scrolltext_text);

	#ifdef RANDOM_SUPPORT
			{
				char a[28];
				sprintf(a,"</# counter == %lu  ",
					(unsigned long)percnt_get(&g_reset_counter, &g_reset_counter_idx));
				scrolltext(a);
			}
	#endif
#endif
#ifdef ANIMATION_TIME
#ifndef ANIMATION_SCROLLTEXT
		case 1:
#endif
			time_anim();
			break;
#else
#ifdef ANIMATION_SCROLLTEXT
			break;
#endif
#endif

#ifdef ANIMATION_SPIRAL
#		ifndef SPIRAL_DELAY
#			define SPIRAL_DELAY 5
#		endif

		case 2:
			spiral(SPIRAL_DELAY);
			break;
#endif

#ifdef ANIMATION_JOERN1
		case 3:
			joern1();
			break;
#endif

#ifdef ANIMATION_SNAKE
		case 4:
			snake_animation();
			break;
#endif

#ifdef ANIMATION_CHECKERBOARD
		case 5:
			checkerboard(20);
			break;
#endif

#ifdef ANIMATION_FIRE
		case 6:
			fire();
			break;
#endif

#ifdef ANIMATION_TIME
		case 7:
			time_anim();
			break;
#endif

#ifdef ANIMATION_MATRIX
		case 8:
			matrix();
			break;
#endif

#ifdef ANIMATION_RANDOM_BRIGHT
		case 9:
			random_bright(30);
			break;
#endif

#ifdef ANIMATION_STONEFLY
		case 10:
			stonefly();
			break;
#endif

#ifdef ANIMATION_GAMEOFLIFE
		case 11:
			gameoflife();
			break;
#endif

#ifdef ANIMATION_FLYINGDOTS
		case 12:
			flyingdots();
			break;
#endif

#ifdef ANIMATION_BREAKOUT
		case 13:
			breakout_demo();
			break;
#endif

#ifdef ANIMATION_MHERWEG
		case 14:
			mherweg();
			break;
#endif

#ifdef ANIMATION_MOIRE
		case 15:
			moire();
			break;
#endif

#ifdef ANIMATION_TIME
		case 16:
			time_anim();
			break;
#endif

#ifdef ANIMATION_LTN_ANT
		case 17:
			ltn_ant();
			break;
#endif

#ifdef ANIMATION_LABORLOGO
		case 18:
			laborlogo();
			break;
#endif

#ifdef ANIMATION_AMPHIBIAN
		case 19:
			amphibian();
			break;
#endif

#ifdef ANIMATION_LOGO_OOS
		case 20:
			logo_OutOfSpec();
			break;
#endif

#ifdef ANIMATION_FAIRYDUST
		case 21:
			fairydust();
			break;
#endif

#ifdef ANIMATION_PLASMA
		case 22:
			plasma();
			break;
#endif

#ifdef ANIMATION_PSYCHEDELIC
		case 23:
			psychedelic();
			break;
#endif

#ifdef ANIMATION_BLACKHOLE
		case 24:
			blackhole();
			break;
#endif

#ifdef ANIMATION_SQUARES
		case 25:
			squares();
			break;
#endif

#ifdef ANIMATION_DNA
		case 26:
			dna();
			break;
#endif

#ifdef ANIMATION_TESTS
		case 31:
			test_level(1, false);
			break;

		case 32:
			test_level(2, false);
			break;

		case 33:
			test_level(3, false);
			break;

		case 35:
			test_palette(false);
			test_palette2(false);
			break;
#endif

#ifdef SMALLANIMATION_ROWWALK
		case 36:
		  rowwalk(SMALLANIMATION_ROWWALK_COUNT,SMALLANIMATION_ROWWALK_SPEED);
		  break;
#endif

#ifdef SMALLANIMATION_COLWALK
		case 37:
		  colwalk(SMALLANIMATION_COLWALK_COUNT,SMALLANIMATION_COLWALK_SPEED);
		  break;
#endif
#ifdef SMALLANIMATION_COLBOUNCE
		case 38:
		  colbounce(SMALLANIMATION_COLBOUNCE_COUNT,SMALLANIMATION_COLBOUNCE_SPEED);
		  break;
#endif
#ifdef SMALLANIMATION_ROWBOUNCE
		case 39:
		  rowbounce(SMALLANIMATION_ROWBOUNCE_COUNT,SMALLANIMATION_ROWBOUNCE_SPEED);
		  break;
#endif

#ifdef MENU_SUPPORT
		case 0xFDu:
			mode = 1;
			break;

		case 0xFEu:
			menu();
			mode = oldOldmode;
			break;
#else

		case 0xFDu:
#ifdef JOYSTICK_SUPPORT
			if (JOYISFIRE)
				mode = 0xFEu;
			else
#endif
				mode = 1;
			break;

		case 0xFEu:
#ifdef JOYSTICK_SUPPORT
			waitForFire = 0;   // avoid circular jumps
			while (JOYISFIRE); // wait until user released the fire button
#endif
			wait(25);          // wait for button to settle

#  ifdef GAME_TETRIS
			tetris();
#  endif

#  ifdef GAME_BASTET
			tetris_bastet();
#  endif

#  ifdef GAME_TETRIS_FP
			tetris_fp();
#  endif

#  ifdef GAME_SPACE_INVADERS
			borg_invaders();
#  endif

#  ifdef GAME_SNAKE
			snake_game();
#  endif

#  ifdef GAME_BREAKOUT
			borg_breakout(0);
#  endif

#ifdef JOYSTICK_SUPPORT
			while (JOYISFIRE); // avoid an unwanted restart of the game loop
#endif
			wait(25);          // wait for button to settle
			mode = oldOldmode; // restore old animation mode
#ifdef JOYSTICK_SUPPORT
			waitForFire = 1;   // reenable joystick query of the wait() function
#endif
			break;
#endif

#ifdef ANIMATION_OFF
		case 0xFFu:
			off();
			break;
#endif
		default:
			if (reverseMode) {
				if (reverseMode-- == (mode - 1)) {
					mode -= 2;
				} else {
					reverseMode = 0;
				}
			}
			break;
		}
	}
}