コード例 #1
0
ファイル: SDL_compat.c プロジェクト: Blitzoreo/pcsx2-online
void
SDL_WM_SetCaption(const char *title, const char *icon)
{
    if (wm_title) {
        SDL_free(wm_title);
    }
    if (title) {
        wm_title = SDL_strdup(title);
    } else {
        wm_title = NULL;
    }
    SDL_SetWindowTitle(SDL_VideoWindow, wm_title);
}
コード例 #2
0
ファイル: window.c プロジェクト: Firew0lf/Engine
int window_getFps(void) {
	static int second;
	if (second != time(NULL)) {
		fpsNumber = fpsCounter;
		fpsCounter = 0;
		char *title = malloc(strlen(mainTitle)+20);
		sprintf(title, "%s | %d FPS", mainTitle, fpsNumber);
		SDL_SetWindowTitle(windowMain, title);
		free(title);
		second = time(NULL);
	}
	return fpsNumber;
}
コード例 #3
0
ファイル: AdScreen.cpp プロジェクト: srmeier/Avocado
//-----------------------------------------------------------------------------
void AdScreen::Present(void) {
    int pitch;
    void* pixels;

    SDL_LockTexture(s_pTexture, NULL, &pixels, &pitch);

    SDL_ConvertPixels(
        s_pScreen->w,
        s_pScreen->h,
        s_pScreen->format->format,
        s_pScreen->pixels,
        s_pScreen->pitch,
        SDL_PIXELFORMAT_RGBA8888,
        pixels, pitch
    );

    SDL_UnlockTexture(s_pTexture);

    SDL_RenderCopy(GetRenderer(), s_pTexture, NULL, NULL);
    SDL_RenderPresent(GetRenderer());

    s_iFrames++;

    s_uiCurrentCount = SDL_GetPerformanceCounter();
    s_uiDiffCount    = (s_uiCurrentCount-s_uiLastCount);
    s_uiCountFreq    = SDL_GetPerformanceFrequency();

    s_fElapsedTime = ((float) s_uiDiffCount/(float) s_uiCountFreq);

    if((1.0f/60.0f)-s_fElapsedTime > 0) {
        // NOTE: without this there seems to be a more consistent framerate
        // but on older computers sometimes the vsync doesn't work right
        //SDL_Delay((uint32_t) (1000.0f*((1.0f/60.0f)-s_fElapsedTime)));

        s_fTotTime += 1.0f/60.0f;
    } else {
        s_fTotTime += s_fElapsedTime;
    }

    s_uiLastCount = s_uiCurrentCount;

    if(s_fTotTime >= 1.0f) {
        char strTitle[0x20] = "";
        sprintf(strTitle, "%s, FPS: %d", WINDOW_TITLE, s_iFrames);

        SDL_SetWindowTitle(GetWindow(), strTitle);

        s_fTotTime  = 0;
        s_iFrames = 0;
    }
}
コード例 #4
0
void SDLHardwareRenderDevice::updateTitleBar() {
	if (title) free(title);
	title = NULL;
	if (titlebar_icon) SDL_FreeSurface(titlebar_icon);
	titlebar_icon = NULL;

	if (!window) return;

	title = strdup(msg->get(WINDOW_TITLE).c_str());
	titlebar_icon = IMG_Load(mods->locate("images/logo/icon.png").c_str());

	if (title) SDL_SetWindowTitle(window, title);
	if (titlebar_icon) SDL_SetWindowIcon(window, titlebar_icon);
}
コード例 #5
0
ファイル: main.cpp プロジェクト: aranasaurus/bamgp-exercises
void ex3() {
    SDL_SetWindowTitle( SDL_GL_GetCurrentWindow(), "ex3" );
    SDL_Rect sprite1;
    SDL_Rect sprite2;

    sprite1.x = WIN_W/2;
    sprite1.y = WIN_H/2;
    sprite2.x = sprite1.x + 10;
    sprite2.y = sprite1.y + 10;

    SDL_BlitSurface( Background, NULL, backBuffer, NULL );
    SDL_BlitSurface( SpriteImage, NULL, backBuffer, &sprite1 );
    SDL_BlitSurface( SpriteImage, NULL, backBuffer, &sprite2 );
}
コード例 #6
0
ファイル: gamebase.cpp プロジェクト: mockthebear/bearshader
void Game::UpdateTitleAsFps(float w8){

    if (nextUpdate <= SDL_GetTicks()){
        char Buff[100];
        FPS = frames;
        sprintf(Buff,"%s (FPS: %f) = %f  = %f",title,frames*1000.0/(1000.0-(SDL_GetTicks()-olt)),GetDeltaTime(),w8);
        SDL_SetWindowTitle(window, Buff);
        olt = SDL_GetTicks()+1000;
        nextUpdate = olt;
        updateFPS=true;
        frames = 0;
    }else{
        updateFPS= false;
    }
}
コード例 #7
0
ファイル: sdl2_gfx.c プロジェクト: dankcushions/RetroArch
static bool sdl2_gfx_frame(void *data, const void *frame, unsigned width,
      unsigned height, uint64_t frame_count,
      unsigned pitch, const char *msg, video_frame_info_t *video_info)
{
   sdl2_video_t *vid = (sdl2_video_t*)data;
   char title[128];

   if (vid->should_resize)
      sdl_refresh_viewport(vid);

   if (frame && video_info->libretro_running)
   {
      static struct retro_perf_counter sdl_copy_frame = {0};

      SDL_RenderClear(vid->renderer);
      sdl_refresh_input_size(vid, false, vid->video.rgb32, width, height, pitch);

      performance_counter_init(sdl_copy_frame, "sdl_copy_frame");
      performance_counter_start_plus(video_info->is_perfcnt_enable, sdl_copy_frame);

      SDL_UpdateTexture(vid->frame.tex, NULL, frame, pitch);

      performance_counter_stop_plus(video_info->is_perfcnt_enable, sdl_copy_frame);
   }

   SDL_RenderCopyEx(vid->renderer, vid->frame.tex, NULL, NULL, vid->rotation, NULL, SDL_FLIP_NONE);

#ifdef HAVE_MENU
   menu_driver_frame(video_info);
#endif

   if (vid->menu.active)
      SDL_RenderCopy(vid->renderer, vid->menu.tex, NULL, NULL);

   if (msg)
      sdl2_render_msg(vid, msg);

   SDL_RenderPresent(vid->renderer);

   title[0] = '\0';

   video_driver_get_window_title(title, sizeof(title));

   if (title[0])
      SDL_SetWindowTitle(vid->window, title);

   return true;
}
コード例 #8
0
ファイル: SDLFramework.cpp プロジェクト: ZealousV/ART
//Show the error in the caption
//With the message and the code
void Error::CaptionError(std::string message, int code,SDL_Window* win)
{
#ifdef ERROR
	std::string str=message;
	if (code!=0)//Add code if non-zero
	{
		str+="   ";
		std::stringstream integer;
		if (code<0){integer<<"-";code=-code;}  
		integer<<code;
		str+=integer.str();
	}
	if (win!=0)
	{SDL_SetWindowTitle(win,message.c_str());};
#endif
}; 
コード例 #9
0
ファイル: viewflif.c プロジェクト: mkadunc/FLIF
uint32_t progressive_render(int32_t quality, int64_t bytes_read) {
    while (drawing) {SDL_Delay(50);}
    drawing = 1;
    printf("%lli bytes read, rendering at quality=%.2f%%\n",(unsigned long long int) bytes_read, 0.01*quality);
    animation = (flif_decoder_num_images(d) > 1);
    FLIF_IMAGE* image = flif_decoder_get_image(d, 0);
    if (!image) { printf("Error: No decoded image found\n"); return 1; }
    uint32_t w = flif_image_get_width(image);
    uint32_t h = flif_image_get_height(image);
    if (!window) { printf("Error: Could not create window\n"); return 2; }
    SDL_SetWindowSize(window,w,h);
    char title[100];
    sprintf(title,"%ix%i FLIF image [read %lli bytes, quality=%.2f%%]",w,h,(unsigned long long int) bytes_read, 0.01*quality);
    SDL_SetWindowTitle(window,title);
    for (int f = 0; f< flif_decoder_num_images(d); f++) {
        FLIF_IMAGE* image = flif_decoder_get_image(d, f);
        if (!image) { printf("Error: No decoded image found\n"); return 1; }
        uint32_t w = flif_image_get_width(image);
        uint32_t h = flif_image_get_height(image);
        frame_delay[f] = flif_image_get_frame_delay(image);
        if (!surf[f]) surf[f] = SDL_CreateRGBSurface(0,w,h,32,0x000000FF,0x0000FF00,0x00FF0000,0xFF000000);
        if (!surf[f]) { printf("Error: Could not create surface\n"); return 1; }
        if (!tmpsurf) tmpsurf = SDL_CreateRGBSurface(0,w,h,32,0x000000FF,0x0000FF00,0x00FF0000,0xFF000000);
        if (!tmpsurf) { printf("Error: Could not create surface\n"); return 1; }
        char* pp =(char*) tmpsurf->pixels;
        for (uint32_t r=0; r<h; r++) {
            flif_image_read_row_RGBA8(image, r, pp, w * sizeof(RGBA));
            pp += tmpsurf->pitch;
        }
        if (flif_image_get_nb_channels(image) > 3) {
          if (!bgsurf) {
            bgsurf = SDL_CreateRGBSurface(0,w,h,32,0x000000FF,0x0000FF00,0x00FF0000,0xFF000000);
            // Draw checkerboard background for image with alpha channel
            SDL_Rect sq; sq.w=20; sq.h=20;
            for (sq.y=0; sq.y<h; sq.y+=sq.h) for (sq.x=0; sq.x<w; sq.x+=sq.w)
              SDL_FillRect(bgsurf,&sq,((sq.y/sq.h + sq.x/sq.w)&1 ? 0xFF606060 : 0xFFA0A0A0));
          }
          SDL_BlitSurface(bgsurf,NULL,surf[f],NULL);
        }
        SDL_BlitSurface(tmpsurf,NULL,surf[f],NULL);
    }
    drawing = 0;
    draw_image();
//    SDL_Delay(1000);
    if (quit) return 0; // stop decoding
    return quality + 1000; // call me back when you have at least 10.00% better quality
}
コード例 #10
0
ファイル: render.c プロジェクト: AndrewBurian/ParticlePhysics
struct renderstate *renderstateInit(const char *title, int width, int height)
{

	// int i;
	struct renderstate *render =
	    (struct renderstate *)malloc(sizeof(struct renderstate));

	memset(render, 0, sizeof(struct renderstate));

	if (SDL_Init(SDL_INIT_EVERYTHING)) {
		return 0;
	}

	if (TTF_Init() == -1) {
		return 0;
	}

	if (SDL_CreateWindowAndRenderer
	    (width, height,
	     SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN,
	     &render->window, &render->renderer) != 0) {
		return 0;
	}

	SDL_SetWindowTitle(render->window, title);
	SDL_GL_SetSwapInterval(1);

	render->font_small = TTF_OpenFont("font.ttf", 8);
	render->font_large = TTF_OpenFont("font.ttf", 12);
	if (render->font_small == 0 || render->font_large == 0) {
		return 0;
	}

	render->points =
	    (SDL_Point *) malloc(sizeof(SDL_Point) * width * height);
	render->scale = 1.0f;
	render->xPos = 0;
	render->yPos = 0;
	render->width = width;
	render->height = height;
	render->frames = 0;
	render->fps = 0;
	render->last_frame = SDL_GetTicks();

	return render;
}
コード例 #11
0
	void graphics_system::end(float delta_time) noexcept {
		const auto smooth_factor = 0.1f;
		static auto delta_time_smoothed = 0.f;
		static auto time_since_last_fps_output = 0.f;

		delta_time_smoothed = ( 1.0f - smooth_factor) * delta_time_smoothed + smooth_factor * delta_time;

		time_since_last_fps_output += delta_time;
		if(time_since_last_fps_output >= 1.0f){
			time_since_last_fps_output = 0.0f;
			std::ostringstream osstr;
			osstr << name_ << " (" << (int((1.0f / delta_time_smoothed) * 10.0f) / 10.0f) << " FPS, ";
			osstr << (int(delta_time_smoothed * 10000.0f) / 10.0f) << " ms / frame)";
			SDL_SetWindowTitle(window_.get(), osstr.str().c_str());
		}
		SDL_GL_SwapWindow(window_.get());
	}
コード例 #12
0
ファイル: sdlwindow.cpp プロジェクト: RoadToExclusivity/PP
 void swap_buffers(std::shared_ptr<TGAImage> &pImage)
 {
     std::swap(pImage, m_pImage);
     if (!m_pImage)
     {
         init_framebuffer();
     }
     else
     {
         ++m_framesCount;
         int averageFrameTime = (SDL_GetTicks() - m_startTicks) / m_framesCount;
         char title[1024];
         sprintf(title, "Rendered %d frames, average time %d ms", m_framesCount, averageFrameTime);
         SDL_SetWindowTitle(m_pWindow, title);
         SDL_UpdateWindowSurface(m_pWindow);
     }
 }
コード例 #13
0
ファイル: window.cpp プロジェクト: PhilCK/sdl-wrapper
bool
window::set_title(const std::string &str)
{
  {
    std::lock_guard<std::mutex> lock(m_lock);
    SDL_SetWindowTitle(m_sdl_window, str.c_str());
  }
  
  if(get_title() != str)
  {
    assert(false);
    sdl::log_debug_error_check();
    return false;
  }
	
	return true;
}
コード例 #14
0
ファイル: main.cpp プロジェクト: aranasaurus/bamgp-exercises
void ex2() {
    SDL_SetWindowTitle( SDL_GL_GetCurrentWindow(), "ex2" );
    SDL_Color c;
    c.r = 40;
    c.g = 225;
    c.b = 40;
    c.a = 255;

    SDL_Rect rects[10];

    for ( int i = 0; i < 10; i++ ) {
        SDL_Rect r;
        r.x = rand()%WIN_W;
        r.y = rand()%WIN_H;
        r.w = 50;
        r.h = 100;

        bool colliding = false;
        for ( int j = i-1; j >= 0; j-- ) {
            SDL_Rect r2 = rects[j];
            int cx1 = r.x + (r.w/2);
            int cx2 = r2.x + (r2.w/2);
            int cy1 = r.y + (r.y/2);
            int cy2 = r2.y + (r2.y/2);

            int xDist = abs( cx1 - cx2 );
            int yDist = abs( cy1 - cy2 );
            int touchDistX = (r.w/2) + (r2.w/2);
            int touchDistY = (r.h/2) + (r2.h/2);

            if ( xDist <= touchDistX || yDist <= touchDistY ) {
                colliding = true;
                break;
            }
        }

        if ( colliding ) {
            i--;
        } else {
            rects[i] = r;
        }
    }

    SDL_FillRects( backBuffer, rects, 10, SDL_MapRGB( backBuffer->format, c.r, c.g, c.b ) );
}
コード例 #15
0
ファイル: sdl2_gfx.c プロジェクト: AirBrowse/RetroArch
static bool sdl2_gfx_frame(void *data, const void *frame, unsigned width,
                           unsigned height, unsigned pitch, const char *msg)
{
   char buf[128];
   sdl2_video_t *vid = (sdl2_video_t*)data;
   runloop_t *runloop = rarch_main_get_ptr();
   driver_t *driver = driver_get_ptr();

   if (vid->should_resize)
      sdl_refresh_viewport(vid);

   if (frame)
   {
      sdl_refresh_input_size(vid, false, vid->video.rgb32, width, height, pitch);

      RARCH_PERFORMANCE_INIT(sdl_copy_frame);
      RARCH_PERFORMANCE_START(sdl_copy_frame);

      SDL_UpdateTexture(vid->frame.tex, NULL, frame, pitch);

      RARCH_PERFORMANCE_STOP(sdl_copy_frame);
   }

   SDL_RenderCopyEx(vid->renderer, vid->frame.tex, NULL, NULL, vid->rotation, NULL, SDL_FLIP_NONE);

#ifdef HAVE_MENU
   if (runloop->is_menu)
      menu_driver_frame();
#endif

   if (vid->menu.active)
      SDL_RenderCopy(vid->renderer, vid->menu.tex, NULL, NULL);

   if (msg)
      sdl2_render_msg(vid, msg);

   SDL_RenderPresent(vid->renderer);

   if (video_monitor_get_fps(buf, sizeof(buf), NULL, 0))
      SDL_SetWindowTitle(vid->window, buf);

   vid->frame_count++;

   return true;
}
コード例 #16
0
ファイル: sdl_gl_ctx.c プロジェクト: RobLoach/RetroArch
static void sdl_ctx_update_title(void *data, void *data2)
{
   char title[128];

   title[0] = '\0';

   video_driver_get_window_title(title, sizeof(title));

#ifdef HAVE_SDL2
   gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data;

   if (sdl && title[0])
      SDL_SetWindowTitle(sdl->g_win, title);
#else
   if (title[0])
      SDL_WM_SetCaption(title, NULL);
#endif
}
コード例 #17
0
ファイル: random_map_call.c プロジェクト: ptitmax/42
void	ft_print_fps(t_env *env)
{
	double	frameswag;
	char	*str;
	char	*nb;

	env->old_time = env->a_time;
	env->a_time = SDL_GetTicks();
	frameswag = 1 / ((env->a_time - env->old_time) / 1000.0);
	if (frameswag > 60.0)
		frameswag = 60;
	SDL_RenderPresent(env->img);
	nb = ft_itoa((int)frameswag);
	str = ft_strjoin("Wolf3D FPS Counter:", nb);
	SDL_SetWindowTitle(env->window, str);
	free(nb);
	free(str);
}
コード例 #18
0
ファイル: app.cpp プロジェクト: stephanreiter/muli3d
void CApp::FrameMove()
{
#ifdef WIN32
	if( pGetInput()->bKeyDown( DIK_ESCAPE ) )
		PostQuitMessage( 0 );
#endif

	if( iGetFrameIdent() % 12 == 0 )
	{
		#ifdef __amigaos4__
		static
		#endif
		char szCaption[256];
		sprintf( szCaption, "Bubble, FPS: %3.1f", fGetFPS() );
		#ifdef WIN32
		SetWindowText( hGetWindowHandle(), szCaption );
		#endif
		#ifdef LINUX_X11
		SDL_SetWindowTitle( pWindow(), szCaption );
		#endif
		#ifdef __amigaos4__
		IIntuition->SetWindowTitles( hGetWindowHandle(), szCaption, szCaption );
		#endif
	}

	if( pGetInput()->bButtonDown( 0 ) )
	{
		// rotate camera around the bubble
		static float32 fRotX = 0.0f, fRotY = 0.0f;

		int32 iDeltaX, iDeltaY;

		pGetInput()->GetMovement( &iDeltaX, &iDeltaY );
		fRotX += -0.1f * iDeltaX * fGetInvFPS();
		fRotY += 0.1f * iDeltaY * fGetInvFPS();

		const float32 fCamPosX = -100.0f * sinf( fRotX );
		const float32 fCamPosY = -50.0f * sinf( fRotY );
		const float32 fCamPosZ = -100.0f * cosf( fRotX );
		m_pCamera->SetPosition( vector3( fCamPosX, fCamPosY, fCamPosZ ) );
		m_pCamera->SetLookAt( vector3( 0, 0, 0 ), vector3( 0, 1, 0 ) );
		m_pCamera->CalculateView();
	}
}
コード例 #19
0
ファイル: Window.c プロジェクト: marron-akanishi/DxPortLib
int PL_Window_SetTitle(const DXCHAR *titleString) {
    if (s_windowTitle != NULL) {
        DXFREE(s_windowTitle);
        s_windowTitle = NULL;
    }
    
    if (titleString != NULL) {
        char utf8Buf[2048];
        
        if (PL_Text_DxStringToString(titleString, utf8Buf, 2048, DX_CHARSET_EXT_UTF8) > 0) {
            s_windowTitle = SDL_strdup(utf8Buf);
            
            if (s_initialized == DXTRUE) {
                SDL_SetWindowTitle(s_window, s_windowTitle);
            }
        }
    }
    return 0;
}
コード例 #20
0
ファイル: screen.cpp プロジェクト: nyanpasu/harvest-rogue
Screen::Screen() {
   SDL_Init(SDL_INIT_EVERYTHING);
   IMG_Init(IMG_INIT_PNG);
   Mix_Init(MIX_INIT_OGG);

   SDL_CreateWindowAndRenderer(1280, 720, SDL_WindowFlags::SDL_WINDOW_SHOWN, &window, &renderer);
   SDL_SetWindowTitle(window, "Harvest-Rogue - Graphical Mode");

   int w, h;
   fontTexture = IMG_LoadTexture(renderer, "media/font16.png");
   SDL_QueryTexture(fontTexture, NULL, NULL, &w, &h);
   TextTilesPerRow = w / TileSize;

   tileTexture = IMG_LoadTexture(renderer, "media/tileset16.png");
   SDL_QueryTexture(tileTexture, NULL, NULL, &w, &h);
   GfxTilesPerRow = w / TileSize;

   SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
}
コード例 #21
0
ファイル: window.cpp プロジェクト: xacce/vdrift
void WINDOW_SDL::Init(
	const std::string & windowcaption,
	unsigned int resx, unsigned int resy,
	unsigned int bpp, unsigned int depthbpp,
	bool fullscreen, unsigned int antialiasing,
	std::ostream & info_output,
	std::ostream & error_output)
{
	Uint32 sdl_flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK;
#if SDL_VERSION_ATLEAST(2,0,0)
	sdl_flags |= SDL_INIT_HAPTIC;
#endif
	if (SDL_Init(sdl_flags) < 0)
	{
		error_output << "SDL initialization failed: " << SDL_GetError() << std::endl;
		assert(0);
	}

	ChangeDisplay(resx, resy, bpp, depthbpp, fullscreen, antialiasing, info_output, error_output);

#if SDL_VERSION_ATLEAST(2,0,0)
	SDL_SetWindowTitle(window, windowcaption.c_str());
#else
	SDL_WM_SetCaption(windowcaption.c_str(), NULL);
#endif

	// initialize GLEW
	GLenum glew_err = glewInit();
	if (glew_err != GLEW_OK)
	{
		error_output << "GLEW failed to initialize: " << glewGetErrorString(glew_err) << std::endl;
		assert(glew_err == GLEW_OK);
		initialized = false;
	}
	else
	{
		info_output << "Using GLEW " << glewGetString(GLEW_VERSION) << std::endl;
		initialized = true;
	}

	LogOpenGLInfo(info_output);
}
コード例 #22
0
ファイル: io.c プロジェクト: taiyu-len/chip8
int io_init (
    struct chip8 *chip,
    const char   *name
) {
    SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO);
    atexit(SDL_Quit);
    //Create window
    SDL_CreateWindowAndRenderer (
        GFXWIDTH * SCALE,
        GFXHEIGHT* SCALE,
        0, &window, &renderer
    );
    //Initilize Event handling
    SDL_SetEventFilter(EventFilter, chip);

    char title[128];
    sprintf(title,"CHIP8: %s",name);
    SDL_SetWindowTitle(window, title);
    return 0;
}
コード例 #23
0
ファイル: Engine.cpp プロジェクト: sampyxis/EntityGameEngine
void Engine::InitSDL(void) {
//	SDL_Surface* Engine::backdrop = NULL;
	//screen = NULL;	 
	//temp = NULL;
	//SDL_Rect rcSprite;
	//SDL_Event event;
	//SDL_Rect source;

	// Setup the screen now
	SDL_Init( SDL_INIT_EVERYTHING );    
	//screen = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE | SDL_DOUBLEBUF  );
	//Create window
	gWindow = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);

	SDL_SetWindowTitle(gWindow, "Title - temp" );
	//Get window surface
	screen = SDL_GetWindowSurface(gWindow);
	//SDL_WM_SetCaption( windowTitle, 0 );

}
コード例 #24
0
ファイル: tunnel.c プロジェクト: Cheeseness/hidden-star
 /* Init and start */
int setup(){
	if (SDL_Init(SDL_INIT_VIDEO) <0){
		 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s", SDL_GetError());
		return 3;
	}

	if (SDL_CreateWindowAndRenderer(resX*scale, resY*scale, SDL_WINDOW_RESIZABLE, &window, &renderer)) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window and renderer: %s", SDL_GetError());
		return 3;
    }

    SDL_RenderSetLogicalSize(renderer, resX, resY);
	SDL_SetWindowTitle(window, "Travel");
    atexit(SDL_Quit);

	srand(time(NULL));
	set_default(0);

	return 0;
}
コード例 #25
0
ファイル: WindowSDL.cpp プロジェクト: dreadk2002/pioneer
WindowSDL::WindowSDL(const Graphics::Settings &vs, const std::string &name)
{
	bool ok;

	// attempt sequence is:
	// 1- requested mode
	ok = CreateWindowAndContext(name.c_str(), vs.width, vs.height, vs.fullscreen, vs.hidden, vs.requestedSamples, 24);

	// 2- requested mode with no anti-aliasing (skipped if no AA was requested anyway)
	//    (skipped if no AA was requested anyway)
	if (!ok && vs.requestedSamples) {
		Output("Failed to set video mode. (%s). Re-trying without multisampling.\n", SDL_GetError());
		ok = CreateWindowAndContext(name.c_str(), vs.width, vs.height, vs.fullscreen, vs.hidden, 0, 24);
	}

	// 3- requested mode with 16 bit depth buffer
	if (!ok) {
		Output("Failed to set video mode. (%s). Re-trying with 16-bit depth buffer\n", SDL_GetError());
		ok = CreateWindowAndContext(name.c_str(), vs.width, vs.height, vs.fullscreen, vs.hidden, vs.requestedSamples, 16);
	}

	// 4- requested mode with 16-bit depth buffer and no anti-aliasing
	//    (skipped if no AA was requested anyway)
	if (!ok && vs.requestedSamples) {
		Output("Failed to set video mode. (%s). Re-trying with 16-bit depth buffer and no multisampling\n", SDL_GetError());
		ok = CreateWindowAndContext(name.c_str(), vs.width, vs.height, vs.fullscreen, vs.hidden, 0, 16);
	}

	// 5- abort!
	if (!ok) {
		Error("Failed to set video mode: %s", SDL_GetError());
	}

	SDLSurfacePtr surface = LoadSurfaceFromFile(vs.iconFile);
	if (surface)
		SDL_SetWindowIcon(m_window, surface.Get());

	SDL_SetWindowTitle(m_window, vs.title);
	SDL_ShowCursor(0);
}
コード例 #26
0
void DisplayManager::update(){

	SDL_GL_SwapWindow(window);
	
	long currentFrameTime = SDL_GetTicks();
	delta = (float) (currentFrameTime - lastFrameTime); //delta in millseconds
	/*
	if (fpsCap > delta) {
		SDL_Delay(fpsCap - delta);
	} */
	
	framecount++;
	time1 += delta;
	if (time1 > 1000){
		std::string title = std::to_string(framecount);
		SDL_SetWindowTitle(window, title.c_str());
		framecount = 0;
		time1 = 0;
	}
	lastFrameTime = currentFrameTime;
	
}
コード例 #27
0
ファイル: Engine.cpp プロジェクト: exnotime/KlurifaxRay
bool Engine::Run()
{
	m_Graphics->Draw(m_RenderQueue, &g_LightEngine);
	m_RenderQueue->Clear();
	if (m_Game->Update(static_cast<float>(m_Timer->DeltaTime()))){
		return false;
	}
	g_LightEngine.UpdateBuffers();
	m_Game->Draw(m_RenderQueue);
	
	//m_SoundEngine->Update();
	if (SDL_PollEvent(&m_Event) > 0){
		if (m_Event.type == SDL_KEYDOWN){
			if (m_Event.key.keysym.sym == SDLK_ESCAPE){
				SDL_Quit();
				return false;
			}
		}
		if (m_Event.type == SDL_QUIT){
			SDL_Quit();
			return false;
		}
	}
	m_EventSystem->ClearEvents();
	if (m_FPSTimer->Time() >= 1.0f){
		string windowName = string("OpenKlurifax : FPS: ");
		std::stringstream ss;
		ss << windowName;
		ss << m_FrameCounter;
		ss << " Frametime : ";
		ss << m_FPSTimer->Time() / m_FrameCounter;
		SDL_SetWindowTitle(m_Graphics->GetWindow(), ss.str().c_str());
		m_FrameCounter = 0;
		m_FPSTimer->Restart();
	}
	m_FrameCounter++;
	
	return true;
}
コード例 #28
0
ファイル: Video.cpp プロジェクト: martin-macak/duel6r
	SDL_Window* Video::createWindow(const std::string& name, const std::string& icon, const ScreenParameters& params, Console& console)
	{
		Uint32 flags = 0;
		
		flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_INPUT_GRABBED;
		if (params.isFullScreen())
		{
			flags |= SDL_WINDOW_FULLSCREEN;
		}

		console.printLine(Format("...Creating SDL window: {0}x{1}") << params.getClientWidth() << params.getClientHeight());
		SDL_Window* sdlWin = SDL_CreateWindow(name.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, params.getClientWidth(), params.getClientHeight(), flags);
		if (sdlWin == nullptr)
		{
			D6_THROW(VideoException, std::string("Unable to create application window: ") + SDL_GetError());
		}

		SDL_SetWindowTitle(sdlWin, name.c_str());
		SDL_SetWindowIcon(sdlWin, SDL_LoadBMP(icon.c_str()));

		return sdlWin;
	}
コード例 #29
0
ファイル: sdl_gl_ctx.c プロジェクト: heuripedes/RetroArch
static void sdl_ctx_update_window_title(void *data)
{
    char buf[128]           = {0};
    char buf_fps[128]       = {0};
    settings_t *settings    = config_get_ptr();
    gfx_ctx_sdl_data_t *sdl = (gfx_ctx_sdl_data_t*)data;

    if (!sdl)
        return;

    if (video_monitor_get_fps(buf, sizeof(buf),
                              buf_fps, sizeof(buf_fps)))
    {
#ifdef HAVE_SDL2
        SDL_SetWindowTitle(sdl->g_win, buf);
#else
        SDL_WM_SetCaption(buf, NULL);
#endif
    }
    if (settings->fps_show)
        runloop_msg_queue_push(buf_fps, 1, 1, false);
}
コード例 #30
0
ファイル: Window.cpp プロジェクト: anonymous31173/Projects
void Window::CreateMyWindow(const std::string & name_of_window, Uint32 flags)
{
	SDL_CreateWindowAndRenderer(
		m_width,
		m_height,
		flags,
		&m_window,
		&m_renderer
		);

	if (m_window == nullptr)
	{
		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
			"SDL Error!",
			"Error While calling SDL_CreateWindow",
			nullptr);
		running = false;
	}
	m_windowName = name_of_window;

	SDL_SetWindowTitle(m_window, m_windowName.c_str ());
	
	m_image = IMG_LoadTexture(m_renderer, "bg.png");
	SDL_SetTextureBlendMode(m_image, SDL_BLENDMODE_NONE);

	if (m_image == nullptr)
	{
		std::stringstream ss;
		// generate our error message
		ss << "Error: " << IMG_GetError();
		SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
			"Loading The bg image",
			ss.str().c_str(),
			nullptr);
		exit(-1);
	}

}