コード例 #1
0
ファイル: sdltest.c プロジェクト: alanhorizon/Transport
int main()
{
	int w = 1024;
	int h = 768;
	int bpp = 24;

	int ticks;
	int frame_delay = 0;
	int blit_delay = 0;
	int draw_delay = 0;
	int frames = 0;
	SDL_Surface *screen;
	SDL_Surface *input;
	SDL_Surface *img;

	putenv("SDL_VIDEO_WINDOW_POS");
	putenv("SDL_VIDEO_CENTERED=1");

	if(SDL_Init(SDL_INIT_VIDEO) < 0 || !SDL_GetVideoInfo()) {
		error("SDL_init");
		return -1;
	}

	/* Create base screen. */
	screen = SDL_SetVideoMode(w, h, bpp, SDL_HWSURFACE | SDL_DOUBLEBUF);
	input = SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, 0, 0, 0, 0));
	//img = SDL_DisplayFormatAlpha(IMG_Load("Missiles.jpg"));
	printf("Created video screen %dx%d@%dbpp in %s mode.\n", screen->w, screen->h, screen->format->BitsPerPixel, screen->flags & SDL_HWSURFACE ? "hardware" : "software");
	BlitTest(screen);

	boxRGBA(input, 0, 0, 600, 600, 0xff, 0, 0, 0xf0);

	while (1) {
		if (!(frames % 10)) {
			printf("%d - Frame: %d Blit: %d\n", frames, frame_delay / 10, blit_delay / 10);
			fflush(stdout);
			frame_delay = 0;
			blit_delay = 0;
			if (frames == 300) exit(0);
		}
		ticks = SDL_GetTicks();

		int x;
//		for (x = 0; x < 500; x++) {
			boxRGBA(screen, 0, 0, w, h, 0xff, 0, 0, 0xff);
//		}
//		SDL_BlitSurface(input, NULL, screen, NULL);
		//SDL_BlitSurface(img, NULL, screen, NULL);

		blit_delay += SDL_GetTicks() - ticks;
		ticks = SDL_GetTicks();

		SDL_Flip(screen);
		//SDL_UpdateRect(screen, 0, 0, 0, 0);

		frame_delay += SDL_GetTicks() - ticks;
		frames++;
	}
}
コード例 #2
0
ファイル: g2dtest.cpp プロジェクト: crystalspace/CS
void G2DTestSystemDriver::SetupFrame ()
{
  if (state_sptr == 0)
  {
    EventOutlet->Broadcast (csevQuit (object_reg));
    return;
  }

  appState curstate = state [state_sptr - 1];
  switch (curstate)
  {
    case stInit:
    case stStartup:
    case stContextInfo:
    case stWindowFixed:
    case stWindowResize:
    case stCustomCursor:
    case stCustomIcon:
    case stAlphaTest:
    case stTestUnicode1:
    case stTestUnicode2:
    case stTestFreetype:
    case stTestLineDraw:
    case stTestLinePerf:
    case stTestTextDraw:
    case stTestTextDraw2:
    case stPixelClipTest:
    case stLineClipTest:
    case stBoxClipTest:
    case stFontClipTest:
    case stBlitTest:
    {
      if (!myG3D->BeginDraw (CSDRAW_2DGRAPHICS))
        break;

      myG2D->Clear (black);
      LeaveState ();
      switch (curstate)
      {
        case stInit:
	  fontLarge = GetFont (CSFONT_LARGE);
	  fontItalic = GetFont (CSFONT_ITALIC);
	  fontCourier = GetFont (CSFONT_COURIER);
	  fontSmall = GetFont (CSFONT_SMALL);
	  {
	    csRef<iVFS> vfs = csQueryRegistry<iVFS> (object_reg);
	    csRef<iImageIO> iio = 
	      csQueryRegistry<iImageIO> (object_reg);
	    if (vfs.IsValid () && iio.IsValid ())
	    {
	      csRef<iFile> testFile = vfs->Open ("/lib/g2dtest/up.png", 
		VFS_FILE_READ);
	      if (testFile.IsValid ())
	      {
		csRef<iDataBuffer> fileData = testFile->GetAllData ();
		blitTestImage = iio->Load (fileData, CS_IMGFMT_TRUECOLOR 
		  | CS_IMGFMT_ALPHA);
	      }
	      testFile = vfs->Open ("/lib/std/cslogo2.png", VFS_FILE_READ);
	      if (testFile.IsValid ())
	      {
		csRef<iDataBuffer> fileData = testFile->GetAllData ();
		alphaBlitImage = iio->Load (fileData, CS_IMGFMT_TRUECOLOR |
		  CS_IMGFMT_ALPHA);
	      }
	    }
	  }
	  EnterState (stStartup);
	  break;
        case stStartup:
          DrawStartupScreen ();
	  EnterState (stContextInfo);
          EnterState (stPause, 5000);
          break;
        case stContextInfo:
          DrawContextInfoScreen ();
          EnterState (stWindowFixed);
          EnterState (stWaitKey);
          break;
        case stWindowFixed:
          DrawWindowScreen ();
          EnterState (stWindowResize);
          EnterState (stWaitKey);
          break;
        case stWindowResize:
          DrawWindowResizeScreen ();
          EnterState (stCustomCursor);
          EnterState (stWaitKey);
          break;
	case stCustomCursor:
          DrawCustomCursorScreen ();
	  SetCustomCursor ();
	  if (lastkey9)
            EnterState (stCustomIcon);
	  else
            EnterState (stCustomCursor);
          break;
	case stCustomIcon:
          SetNormalCursor ();
	  SetCustomIcon ();
          DrawCustomIconScreen ();
	  EnterState (stAlphaTest);
          EnterState (stWaitKey);
          break;
	case stAlphaTest:
          DrawAlphaTestScreen ();
          EnterState (stTestUnicode1);
          EnterState (stWaitKey);
          break;
	case stTestUnicode1:
	  DrawUnicodeTest1 ();
          EnterState (stTestUnicode2);
          EnterState (stWaitKey);
          break;
	case stTestUnicode2:
	  DrawUnicodeTest2 ();
          EnterState (stTestFreetype);
          EnterState (stWaitKey);
          break;
	case stTestFreetype:
	  DrawFreetypeTest ();
          EnterState (stTestLineDraw);
          EnterState (stWaitKey);
          break;
        case stTestLineDraw:
          DrawLineTest ();
          EnterState (stTestLinePerf);
          EnterState (stWaitKey);
          break;
        case stTestLinePerf:
          DrawLinePerf ();
          if (lastkey2)
            EnterState (stTestTextDraw);
          else
            EnterState (stTestLinePerf);
          break;
        case stTestTextDraw:
          DrawTextTest ();
          if (lastkey3)
            EnterState (stTestTextDraw2);
          else
            EnterState (stTestTextDraw);
          break;
        case stTestTextDraw2:
          DrawTextTest2 ();
          if (lastkey4)
            EnterState (stPixelClipTest);
          else
            EnterState (stTestTextDraw2);
          break;
        case stPixelClipTest:
          PixelClipTest ();
          if (lastkey5)
          {
            myG2D->SetClipRect(0,0,myG2D->GetWidth(), myG2D->GetHeight());
            EnterState (stLineClipTest);
          }
          else
            EnterState (stPixelClipTest);
          break;
        case stLineClipTest:
          LineClipTest ();
          if (lastkey6)
          {
            myG2D->SetClipRect(0,0,myG2D->GetWidth(), myG2D->GetHeight());
            EnterState (stBoxClipTest);
          }
          else
            EnterState (stLineClipTest);
          break;
        case stBoxClipTest:
          BoxClipTest ();
          if (lastkey7)
          {
            myG2D->SetClipRect(0,0,myG2D->GetWidth(), myG2D->GetHeight());
	    EnterState (stFontClipTest);
          }
          else
            EnterState (stBoxClipTest);
          break;
        case stFontClipTest:
          FontClipTest ();
          if (lastkey8)
	    EnterState (stBlitTest);
          else
            EnterState (stFontClipTest);
          break;
	case stBlitTest:
	  BlitTest ();
          EnterState (stWaitKey);
          break;
        default:
          break;
      }
      break;
    }
    case stPause:
      if (int (csGetTicks () - timer) > 0)
        LeaveState ();
      else
        csSleep (1);
      break;
    case stWaitKey:
      if (lastkey)
      {
        LeaveState ();
        SwitchBB = false;
      }
      else
      {
        if (SwitchBB)
        {
          myG2D->Print (0);
          csSleep (200);
        }
        else
          csSleep (1);
      }
      break;
  }
}