当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_InitSubSystem函数代码示例

本文整理汇总了C++中SDL_InitSubSystem函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_InitSubSystem函数的具体用法?C++ SDL_InitSubSystem怎么用?C++ SDL_InitSubSystem使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_InitSubSystem函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: endSound

/**
 * initSound(): Initialize sound.
 * @return 1 on success; -1 if sound was already initialized; 0 on error.
 */
int Audio_SDL::initSound(void)
{
	int i;
	int videoLines;
	
	if (m_soundInitialized)
		return -1;
	
	// Make sure sound is ended first.
	endSound();
	
	switch (m_soundRate)
	{
		case 11025:
			m_segLength = (CPU_Mode ? 220 : 184);
			break;
		case 22050:
			m_segLength = (CPU_Mode ? 441 : 368);
			break;
		case 44100:
			m_segLength = (CPU_Mode ? 882 : 735);
			break;
	}
	
	videoLines = (CPU_Mode ? 312 : 262);
	for (i = 0; i < videoLines; i++)
	{
		Sound_Extrapol[i][0] = ((m_segLength * i) / videoLines);
		Sound_Extrapol[i][1] = (((m_segLength * (i + 1)) / videoLines) - Sound_Extrapol[i][0]);
	}
	for (i = 0; i < m_segLength; i++)
		Sound_Interpol[i] = ((videoLines * i) / m_segLength);
	
	// Clear the segment buffers.
	memset(Seg_L, 0, m_segLength << 2);
	memset(Seg_R, 0, m_segLength << 2);
	
	// Attempt to initialize SDL audio.
	if (SDL_InitSubSystem(SDL_INIT_AUDIO) == -1)
		return 0;
	
	// Allocate the segment buffer.
	pMsndOut = static_cast<unsigned char*>(malloc(m_segLength << 2));
	
	// Set up the SDL audio specification.
	SDL_AudioSpec spec;
	spec.freq = m_soundRate;
	spec.format = AUDIO_S16SYS;
	spec.channels = !m_stereo ? 1 : 2; // TODO: Initializing 1 channel seems to double-free if it's later changed...
	spec.samples = 1024;
	spec.callback = AudioCallback;
	audiobuf = static_cast<unsigned char*>(malloc((spec.samples * spec.channels * 2 * 4) * sizeof(short)));
	
	// "user" parameter for the callback function is a pointer to this object.
	spec.userdata = this;
	
	memset(audiobuf, 0, (spec.samples * spec.channels * 2 * 4) * sizeof(short));
	if (SDL_OpenAudio(&spec, 0) != 0)
		return 0;
	SDL_PauseAudio(0);
	
	// Sound is initialized.
	m_soundInitialized = true;
	return 1;
}
开发者ID:chipsoftwaretester,项目名称:OpenEmu,代码行数:69,代码来源:audio_sdl.cpp

示例2: Init

static int Init()
{
	nInitedSubsytems = SDL_WasInit(SDL_INIT_VIDEO);

	if (!(nInitedSubsytems & SDL_INIT_VIDEO)) {
		SDL_InitSubSystem(SDL_INIT_VIDEO);
	}

	nGamesWidth = nVidImageWidth;
	nGamesHeight = nVidImageHeight;

	nRotateGame = 0;

	if (bDrvOkay) {
		// Get the game screen size
		BurnDrvGetVisibleSize(&nGamesWidth, &nGamesHeight);

		if (BurnDrvGetFlags() & BDF_ORIENTATION_VERTICAL) {
			printf("Vertical\n");
			nRotateGame = 1;
		}

		if (BurnDrvGetFlags() & BDF_ORIENTATION_FLIPPED) {
			printf("Flipped\n");
			bFlipped = true;
		} 
	}

	if (!nRotateGame) {
		nTextureWidth = GetTextureSize(nGamesWidth);
		nTextureHeight = GetTextureSize(nGamesHeight);
	} else {
		nTextureWidth = GetTextureSize(nGamesHeight);
		nTextureHeight = GetTextureSize(nGamesWidth);
	}

	nSize = 2;
	bVidScanlines = 0;

	RECT test_rect;
	test_rect.left = 0;
	test_rect.right = nGamesWidth;
	test_rect.top = 0;
	test_rect.bottom = nGamesHeight;

	printf("correctx before %d, %d\n", test_rect.right, test_rect.bottom);
	VidSScaleImage(&test_rect);
	printf("correctx after %d, %d\n", test_rect.right, test_rect.bottom);

	screen = SDL_SetVideoMode(test_rect.right * nSize,
				  test_rect.bottom * nSize, 32, SDL_OPENGL);
	SDL_WM_SetCaption("FB Alpha", NULL);

	// Initialize the buffer surfaces
	BlitFXInit();

	// Init opengl
	init_gl();

	return 0;
}
开发者ID:spectrenoir06,项目名称:libretro-fba,代码行数:61,代码来源:vid_sdlopengl.cpp

示例3: main

int main(int argc, char * * argv)
{
  const SDL_VideoInfo *videoInfo;
  Uint32 videoFlags = 0;
   
  /* Initialize SDL */
  printf("(II) Initializing SDL video subsystem...\n");
  if(SDL_InitSubSystem(SDL_INIT_VIDEO) == -1)
  {
    printf("(EE) Error initializing SDL video subsystem: %s\n", SDL_GetError());
    return -1;
  }
   
  /* Video Info */
  printf("(II) Getting video info...\n");
  if(!(videoInfo = SDL_GetVideoInfo()))
  {
    printf("(EE) Video query failed: %s\n", SDL_GetError());
    SDL_QuitSubSystem(SDL_INIT_VIDEO);
    return -1;
  }
   
  /* Setting the video mode */
  videoFlags |= SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE;
  
  if(videoInfo->hw_available)
    videoFlags |= SDL_HWSURFACE;
  else
    videoFlags |= SDL_SWSURFACE;
  
  if(videoInfo->blit_hw)
    videoFlags |= SDL_HWACCEL;
  
  //videoFlags |= SDL_FULLSCREEN;

  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  //SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16);
//   SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
//   SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
//   SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
//   SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
//   SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
  //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
   
  printf("(II) Setting video mode %dx%d...\n", screen_width, screen_height);
  if(!(sdl_Screen = SDL_SetVideoMode(screen_width, screen_height, 0, videoFlags)))
  {
    printf("(EE) Error setting videomode %dx%d: %s\n", screen_width, screen_height, SDL_GetError());
    SDL_QuitSubSystem(SDL_INIT_VIDEO);
    return -1;
  }
   
  char caption[500];
  sprintf(caption, "z64, LLE video plugin by Ziggy");
  SDL_WM_SetCaption(caption, caption);



  static char pixels[256*256*4];
  ilInit();
  glewInit();

  ilLoadImage("tex1.png");
  glBindTexture(GL_TEXTURE_2D, 1);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE,
               ilGetData());
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                   GL_LINEAR );
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
                   GL_LINEAR );
  ilLoadImage("tex2.png");
  glBindTexture(GL_TEXTURE_2D, 2);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE,
               ilGetData());
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                   GL_LINEAR );
  glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
                   GL_LINEAR );

  glDisable(GL_DEPTH_TEST);
  glDisable(GL_BLEND);

  glViewport(0, 0, screen_width, screen_height);

  glLoadIdentity();
  glScalef(2, 2, 1);
  glTranslatef(-0.5, -0.5, 0);

  rglShader_t * shader = rglCreateShader(
    "void main()                                                    \n"
    "{                                                              \n"
    "  gl_Position = ftransform();                                  \n"
    "  gl_FrontColor = gl_Color;                                    \n"
    "  gl_TexCoord[0] = gl_MultiTexCoord0;                          \n"
    "}                                                              \n"
    ,
    "uniform sampler2D texture0;       \n"
    "uniform sampler2D texture1;       \n"
    "                                  \n"
    "void main()                       \n"
//.........这里部分代码省略.........
开发者ID:cxd4,项目名称:z64,代码行数:101,代码来源:gltest.cpp

示例4: SNDDMA_Init

qboolean SNDDMA_Init (dma_t *dma)
{
	SDL_AudioSpec desired, obtained;
	int		tmp, val;
	char	drivername[128];

	if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
	{
		Con_Printf("Couldn't init SDL audio: %s\n", SDL_GetError());
		return false;
	}

	/* Set up the desired format */
	desired.freq = tmp = snd_mixspeed.value;
	desired.format = (loadas8bit.value) ? AUDIO_U8 : AUDIO_S16SYS;
	desired.channels = 2; /* = desired_channels; */
	if (desired.freq <= 11025)
		desired.samples = 256;
	else if (desired.freq <= 22050)
		desired.samples = 512;
	else if (desired.freq <= 44100)
		desired.samples = 1024;
	else if (desired.freq <= 56000)
		desired.samples = 2048; /* for 48 kHz */
	else
		desired.samples = 4096; /* for 96 kHz */
	desired.callback = paint_audio;
	desired.userdata = NULL;

	/* Open the audio device */
	if (SDL_OpenAudio(&desired, &obtained) == -1)
	{
		Con_Printf("Couldn't open SDL audio: %s\n", SDL_GetError());
		SDL_QuitSubSystem(SDL_INIT_AUDIO);
		return false;
	}

	/* Make sure we can support the audio format */
	switch (obtained.format)
	{
	case AUDIO_S8:		/* maybe needed by AHI */
	case AUDIO_U8:
	case AUDIO_S16SYS:
		/* Supported */
		break;
	default:
		Con_Printf ("Unsupported audio format received (%u)\n", obtained.format);
		SDL_CloseAudio();
		SDL_QuitSubSystem(SDL_INIT_AUDIO);
		return false;
	}

	memset ((void *) dma, 0, sizeof(dma_t));
	shm = dma;

	/* Fill the audio DMA information block */
	shm->samplebits = (obtained.format & 0xFF); /* first byte of format is bits */
	shm->signed8 = (obtained.format == AUDIO_S8);
	if (obtained.freq != tmp)
		Con_Printf ("Warning: Rate set (%d) didn't match requested rate (%d)!\n", obtained.freq, tmp);
	shm->speed = obtained.freq;
	shm->channels = obtained.channels;
	tmp = (obtained.samples * obtained.channels) * 10;
	if (tmp & (tmp - 1))
	{	/* make it a power of two */
		val = 1;
		while (val < tmp)
			val <<= 1;

		tmp = val;
	}
	shm->samples = tmp;
	shm->samplepos = 0;
	shm->submission_chunk = 1;

	Con_Printf ("SDL audio spec  : %d Hz, %d samples, %d channels\n",
			obtained.freq, obtained.samples, obtained.channels);
	{
		const char *driver = SDL_GetCurrentAudioDriver();
		const char *device = SDL_GetAudioDeviceName(0, SDL_FALSE);
		q_snprintf(drivername, sizeof(drivername), "%s - %s",
			driver != NULL ? driver : "(UNKNOWN)",
			device != NULL ? device : "(UNKNOWN)");
	}
	buffersize = shm->samples * (shm->samplebits / 8);
	Con_Printf ("SDL audio driver: %s, %d bytes buffer\n", drivername, buffersize);

	shm->buffer = (unsigned char *) calloc (1, buffersize);
	if (!shm->buffer)
	{
		SDL_CloseAudio();
		SDL_QuitSubSystem(SDL_INIT_AUDIO);
		shm = NULL;
		Con_Printf ("Failed allocating memory for SDL audio\n");
		return false;
	}

	SDL_PauseAudio(0);

	return true;
//.........这里部分代码省略.........
开发者ID:Darktori,项目名称:vkQuake,代码行数:101,代码来源:snd_sdl.c

示例5: Log

	bool Graphics::Initialize(int width, int height, unsigned int bpp, bool fullScreen)
	{ 
		Log("****Initializing Graphics****");
		Log("Initializing Screen...");
		if(SDL_InitSubSystem(SDL_INIT_VIDEO) == -1)
		{
			Error("Unable to initialize Screen");
			return false;
		}

		m_width = width;
		m_height = height;
		m_fullScreen = fullScreen;
		m_bitsPerPixel = bpp;

		unsigned int flags = SDL_HWSURFACE | SDL_OPENGL;

		if(fullScreen)
		{
			flags |= SDL_FULLSCREEN;
		}

		m_buffer = SDL_SetVideoMode(m_width, m_height, m_bitsPerPixel, flags);

		if(!m_buffer)
		{
			if(fullScreen)
			{
				Warning("Unable to set up full screen");

				flags = SDL_HWSURFACE;

				m_buffer = 
					SDL_SetVideoMode(m_width, m_height, m_bitsPerPixel, flags);

				if(!m_buffer)
				{
					Error("Unable to set up screen buffer");
					return false;
				}
			}
			else
			{
				Error("Unable to set up screen buffer");
				return false;
			}
		} 
		Log("width:" + ToString(m_width) + " height:" + ToString(m_height) + 
			" bpp:" + ToString(m_bitsPerPixel) + " fullscreen:" + (m_fullScreen ? "true" : "false"));

		Log("Initializing GL Extensions...");

		GLenum glewInitCode = glewInit();
		if(glewInitCode != GLEW_OK) 
		{
			std::string error = "Unable to initialize GL Extensions";
			switch(glewInitCode)
			{
			case 1:
				error += " no GL ver"; 
				break;
			case 2:
				error += " OGL ver < 1.1";
				break;
			case 3:
				error += " GLX ver < 1.2";
				break;
			default:
				error += " unknown error";
			}

			Error(error);
		}

		Log("GL Extensions Initialized");
		Log(" ");

		return true;
	}
开发者ID:mrfriedfish,项目名称:sae-aiproject,代码行数:79,代码来源:Graphics.cpp

示例6: sdl_event_thread

/*
 * This thread will read the buttons in an interrupt like fashion, and
 * also initializes SDL_INIT_VIDEO and the surfaces
 *
 * it must be done in the same thread (at least on windows) because events only
 * work in the thread which called SDL_Init(SubSystem) with SDL_INIT_VIDEO
 *
 * This is an SDL thread and relies on preemptive behavoir of the host
 **/
static int sdl_event_thread(void * param)
{
    SDL_InitSubSystem(SDL_INIT_VIDEO);

    SDL_Surface *picture_surface;
    int width, height;

    /* Try and load the background image. If it fails go without */
    if (background) {
        picture_surface = SDL_LoadBMP("UI256.bmp");
        if (picture_surface == NULL) {
            background = false;
            DEBUGF("warn: %s\n", SDL_GetError());
        }
    }
    
    /* Set things up */
    if (background)
    {
        width = UI_WIDTH;
        height = UI_HEIGHT;
    } 
    else 
    {
#ifdef HAVE_REMOTE_LCD
        if (showremote)
        {
            width = SIM_LCD_WIDTH > SIM_REMOTE_WIDTH ? SIM_LCD_WIDTH : SIM_REMOTE_WIDTH;
            height = SIM_LCD_HEIGHT + SIM_REMOTE_HEIGHT;
        }
        else
#endif
        {
            width = SIM_LCD_WIDTH;
            height = SIM_LCD_HEIGHT;
        }
    }
   
    
    if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) {
        panicf("%s", SDL_GetError());
    }

    SDL_WM_SetCaption(UI_TITLE, NULL);

    if (background && picture_surface != NULL)
        SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL);

    /* let system_init proceed */
    SDL_SemPost((SDL_sem *)param);

    /*
     * finally enter the button loop */
    while(gui_message_loop());

    /* Order here is relevent to prevent deadlocks and use of destroyed
       sync primitives by kernel threads */
    sim_thread_shutdown();
    sim_kernel_shutdown();

    return 0;
}
开发者ID:eisnerd,项目名称:rockbox,代码行数:71,代码来源:system-sdl.c

示例7: main

/**
 * @brief The entry point of Naev.
 *
 *    @param[in] argc Number of arguments.
 *    @param[in] argv Array of argc arguments.
 *    @return EXIT_SUCCESS on success.
 */
int main( int argc, char** argv )
{
   char buf[PATH_MAX];

   /* Save the binary path. */
   binary_path = strdup(argv[0]);

   /* Print the version */
   LOG( " "APPNAME" v%s", naev_version(0) );
#ifdef GIT_COMMIT
   DEBUG( " git HEAD at " GIT_COMMIT );
#endif /* GIT_COMMIT */

   /* Initializes SDL for possible warnings. */
   SDL_Init(0);

   /* Initialize the threadpool */
   threadpool_init();

   /* Set up debug signal handlers. */
   debug_sigInit();

   /* Must be initialized before input_init is called. */
   if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) {
      WARN("Unable to initialize SDL Video: %s", SDL_GetError());
      return -1;
   }

   /* Get desktop dimensions. */
#if SDL_VERSION_ATLEAST(1,2,10)
   const SDL_VideoInfo *vidinfo = SDL_GetVideoInfo();
   gl_screen.desktop_w = vidinfo->current_w;
   gl_screen.desktop_h = vidinfo->current_h;
#else /* #elif SDL_VERSION_ATLEAST(1,2,10) */
   gl_screen.desktop_w = 0;
   gl_screen.desktop_h = 0;
#endif /* #elif SDL_VERSION_ATLEAST(1,2,10) */

   /* We'll be parsing XML. */
   LIBXML_TEST_VERSION
   xmlInitParser();

   /* Input must be initialized for config to work. */
   input_init();

   conf_setDefaults(); /* set the default config values */

   /*
    * Attempts to load the data path from datapath.lua
    * At this early point in the load process, the binary path
    * is the only place likely to be checked.
    */
   conf_loadConfigPath();

   /* Parse the user data path override first. */
   conf_parseCLIPath( argc, argv );

   /* Create the home directory if needed. */
   if (nfile_dirMakeExist("%s", nfile_configPath()))
      WARN("Unable to create config directory '%s'", nfile_configPath());

   /* Set the configuration. */
   nsnprintf(buf, PATH_MAX, "%s"CONF_FILE, nfile_configPath());

#if HAS_UNIX
   /* TODO get rid of this cruft ASAP. */
   int oldconfig = 0;
   if (!nfile_fileExists( buf )) {
      char *home, buf2[PATH_MAX];
      home = SDL_getenv( "HOME" );
      if (home != NULL) {
         nsnprintf( buf2, PATH_MAX, "%s/.naev/"CONF_FILE, home );
         if (nfile_fileExists( buf2 ))
            oldconfig = 1;
      }
   }
#endif /* HAS_UNIX */

   conf_loadConfig(buf); /* Lua to parse the configuration file */
   conf_parseCLI( argc, argv ); /* parse CLI arguments */

   /* Enable FPU exceptions. */
#if defined(HAVE_FEENABLEEXCEPT) && defined(DEBUGGING)
   if (conf.fpu_except)
      feenableexcept( FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW );
#endif /* defined(HAVE_FEENABLEEXCEPT) && defined(DEBUGGING) */

   /* Open data. */
   if (ndata_open() != 0)
      ERR("Failed to open ndata.");

   /* Load the start info. */
   if (start_load())
//.........这里部分代码省略.........
开发者ID:Jazzkovsky,项目名称:naev,代码行数:101,代码来源:naev.c

示例8: main

int
main ()
{
	SDL_Rect r;
	SDL_Event ev;

	if (SDL_Init (SDL_INIT_VIDEO) < 0) {
		fprintf (stderr, "SDL_Init error\n");
		exit (1);
	}


	if (SDL_InitSubSystem (SDL_INIT_AUDIO < 0)) {
		printf ("no audio\n");
	} else {
		printf ("audio initialized\n");
		have_audio = 1;
	}

	if ((sur = SDL_SetVideoMode (320, 200, 24, SDL_HWSURFACE | SDL_DOUBLEBUF)) == NULL) {
		fprintf (stderr, "error in SDL_SetVideoMode\n");
		exit (1);
	}

	SDL_EnableUNICODE (1);

	audio_desired.freq = 11025;
	audio_desired.format = AUDIO_U8;
	audio_desired.channels = 1;
	audio_desired.samples = 8192;
	audio_desired.callback = audio_callback;

	if (SDL_OpenAudio (&audio_desired, &audio_obtained) < 0) {
		fprintf (stderr, "error in SDL_OpenAudio\n");
		exit (1);
	}

	test_music ();
	SDL_PauseAudio (0);

	while (1) {
		while (SDL_PollEvent (&ev)) {
			switch (ev.type) {
			case SDL_QUIT:
				exit (0);
				break;
			case SDL_KEYDOWN:
				printf ("got key %d\n", ev.key.keysym.unicode);
				break;

				/* ignore these events */
			case SDL_KEYUP:
			case SDL_ACTIVEEVENT:
			case SDL_MOUSEMOTION:
				break;
			default:
				printf ("got uknown event %d\n", ev.type);
				break;
			}
		}

		r.x = 0; r.y = 0; r.w = 320; r.h = 200;
		SDL_FillRect (sur, &r, 0);

		r.x = 160 + 120 * cos (get_time () * .5 * M_PI);
		r.y = 100;
		r.w = 20;
		r.h = 20;
		SDL_FillRect (sur, &r, 0xff0000);
	
		SDL_Flip (sur);

		usleep (33 * 1000);

	}

	return (0);
}
开发者ID:getir-hackathon-2016,项目名称:raceintospace-cvs,代码行数:78,代码来源:sdltest.c

示例9: I_InitTimer

void I_InitTimer(void)
{
    // initialize timer
    SDL_InitSubSystem(SDL_INIT_TIMER);
}
开发者ID:bnied,项目名称:doomretro,代码行数:5,代码来源:i_timer.c

示例10: SDL_Linked_Version

SDLVideo::SDLVideo(int parm)
{
	const SDL_version *SDLVersion = SDL_Linked_Version();

	if(SDLVersion->major != SDL_MAJOR_VERSION
		|| SDLVersion->minor != SDL_MINOR_VERSION)
	{
		I_FatalError("SDL version conflict (%d.%d.%d vs %d.%d.%d dll)\n",
			SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL,
			SDLVersion->major, SDLVersion->minor, SDLVersion->patch);
		return;
	}

	if (SDL_InitSubSystem (SDL_INIT_VIDEO) == -1)
	{
		I_FatalError("Could not initialize SDL video.\n");
		return;
	}

	if(SDLVersion->patch != SDL_PATCHLEVEL)
	{
		Printf_Bold("SDL version warning (%d.%d.%d vs %d.%d.%d dll)\n",
			SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL,
			SDLVersion->major, SDLVersion->minor, SDLVersion->patch);
	}

    // [Russell] - Just for windows, display the icon in the system menu and
    // alt-tab display
    #if WIN32 && !_XBOX
    HICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));

    if (hIcon)
    {
        HWND WindowHandle;

        SDL_SysWMinfo wminfo;
        SDL_VERSION(&wminfo.version)
        SDL_GetWMInfo(&wminfo);

        WindowHandle = wminfo.window;

        SendMessage(WindowHandle, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
        SendMessage(WindowHandle, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
    }
    #endif

    I_SetWindowCaption();

   sdlScreen = NULL;
   infullscreen = false;
   screenw = screenh = screenbits = 0;
   palettechanged = false;

   // Get Video modes
   SDL_PixelFormat fmt;
   fmt.palette = NULL;
   fmt.BitsPerPixel = 8;
   fmt.BytesPerPixel = 1;

   SDL_Rect **sdllist = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_SWSURFACE);

   vidModeIterator = 0;
   vidModeIteratorBits = 8;
   vidModeList.clear();

   if(!sdllist)
   {
	  // no fullscreen modes, but we could still try windowed
	  Printf(PRINT_HIGH, "SDL_ListModes returned NULL. No fullscreen video modes are available.\n");
	  return;
   }
   else if(sdllist == (SDL_Rect **)-1)
   {
      I_FatalError("SDL_ListModes returned -1. Internal error.\n");
      return;
   }
   else
   {
      vidMode_t CustomVidModes[] =
      {
         { 640, 480, 8 }
        ,{ 640, 400, 8 }
        ,{ 320, 240, 8 }
        ,{ 320, 200, 8 }
      };

      // Add in generic video modes reported by SDL
      for(int i = 0; sdllist[i]; ++i)
      {
        vidMode_t vm;

        vm.width = sdllist[i]->w;
        vm.height = sdllist[i]->h;
        vm.bits = 8;

        vidModeList.push_back(vm);
      }

      // Now custom video modes to be added
      for (size_t i = 0; i < STACKARRAY_LENGTH(CustomVidModes); ++i)
//.........这里部分代码省略.........
开发者ID:JohnnyonFlame,项目名称:odamex,代码行数:101,代码来源:i_sdlvideo.cpp

示例11: scrnmng_create

BOOL scrnmng_create(int width, int height) {

    char			s[256];
    const SDL_VideoInfo	*vinfo;
    SDL_Surface		*surface;
    SDL_PixelFormat	*fmt;
    BOOL			r;

    if (SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
        fprintf(stderr, "Error: SDL_Init: %s\n", SDL_GetError());
        return(FAILURE);
    }
    SDL_WM_SetCaption(app_name, app_name);
    vinfo = SDL_GetVideoInfo();
    if (vinfo == NULL) {
        fprintf(stderr, "Error: SDL_GetVideoInfo: %s\n", SDL_GetError());
        return(FAILURE);
    }
    SDL_VideoDriverName(s, sizeof(s));

    surface = SDL_SetVideoMode(width, height, vinfo->vfmt->BitsPerPixel,
                               SDL_HWSURFACE | SDL_ANYFORMAT | SDL_DOUBLEBUF | SDL_FULLSCREEN);
    if (surface == NULL) {
        fprintf(stderr, "Error: SDL_SetVideoMode: %s\n", SDL_GetError());
        return(FAILURE);
    }

    r = FALSE;
    fmt = surface->format;
#if defined(SUPPORT_8BPP)
    if (fmt->BitsPerPixel == 8) {
        r = TRUE;
    }
#endif
#if defined(SUPPORT_16BPP)
    if ((fmt->BitsPerPixel == 16) && (fmt->Rmask == 0xf800) &&
            (fmt->Gmask == 0x07e0) && (fmt->Bmask == 0x001f)) {
        r = TRUE;
    }
#endif
#if defined(SUPPORT_24BPP)
    if (fmt->BitsPerPixel == 24) {
        r = TRUE;
    }
#endif
#if defined(SUPPORT_32BPP)
    if (fmt->BitsPerPixel == 32) {
        r = TRUE;
    }
#endif
#if defined(SCREEN_BPP)
    if (fmt->BitsPerPixel != SCREEN_BPP) {
        r = FALSE;
    }
#endif
    if (r) {
        scrnmng.enable = TRUE;
        scrnmng.width = width;
        scrnmng.height = height;
        scrnmng.bpp = fmt->BitsPerPixel;
        return(SUCCESS);
    }
    else {
        fprintf(stderr, "Error: Bad screen mode");
        return(FAILURE);
    }
}
开发者ID:josejl1987,项目名称:neko-tracer,代码行数:67,代码来源:scrnmng.c

示例12: SNDDMA_Init

qboolean
SNDDMA_Init (void)
{
	SDL_AudioSpec desired, obtained;
	int desired_bits, freq;
	
	if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
		if (SDL_Init(SDL_INIT_AUDIO) < 0) {
			Com_Printf ("Couldn't init SDL audio: %s\n", SDL_GetError ());
			return 0;
		}
	} else if (SDL_WasInit(SDL_INIT_AUDIO) == 0) {
		if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
			Com_Printf ("Couldn't init SDL audio: %s\n", SDL_GetError ());
			return 0;
		}
	}
	
	snd_inited = 0;
	desired_bits = (Cvar_Get("sndbits", "16", CVAR_ARCHIVE))->value;

	/* Set up the desired format */
	freq = (Cvar_Get("s_khz", "0", CVAR_ARCHIVE))->value;
	if (freq == 44)
		desired.freq = 44100;
	else if (freq == 22)
		desired.freq = 22050;
	else
		desired.freq = 11025;
	
	switch (desired_bits) {
		case 8:
			desired.format = AUDIO_U8;
			break;
		case 16:
			if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
				desired.format = AUDIO_S16MSB;
			else
				desired.format = AUDIO_S16LSB;
			break;
		default:
			Com_Printf ("Unknown number of audio bits: %d\n", desired_bits);
			return 0;
	}
	desired.channels = (Cvar_Get("sndchannels", "2", CVAR_ARCHIVE))->value;
	
	if (desired.freq == 44100)
		desired.samples = 2048;
	else if (desired.freq == 22050)
		desired.samples = 1024;
	else
		desired.samples = 512;
	
	desired.callback = paint_audio;
	
	/* Open the audio device */
	if (SDL_OpenAudio (&desired, &obtained) < 0) {
		Com_Printf ("Couldn't open SDL audio: %s\n", SDL_GetError ());
		return 0;
	}

	/* Make sure we can support the audio format */
	switch (obtained.format) {
		case AUDIO_U8:
			/* Supported */
			break;
		case AUDIO_S16LSB:
		case AUDIO_S16MSB:
			if (((obtained.format == AUDIO_S16LSB) &&
				 (SDL_BYTEORDER == SDL_LIL_ENDIAN)) ||
				((obtained.format == AUDIO_S16MSB) &&
				 (SDL_BYTEORDER == SDL_BIG_ENDIAN))) {
				/* Supported */
				break;
			}
			/* Unsupported, fall through */ ;
		default:
			/* Not supported -- force SDL to do our bidding */
			SDL_CloseAudio ();
			if (SDL_OpenAudio (&desired, NULL) < 0) {
				Com_Printf ("Couldn't open SDL audio: %s\n", SDL_GetError ());
				return 0;
			}
			memcpy (&obtained, &desired, sizeof (desired));
			break;
	}
	SDL_PauseAudio (0);

	/* Fill the audio DMA information block */
	shm = &dma;
	shm->samplebits = (obtained.format & 0xFF);
	shm->speed = obtained.freq;
	shm->channels = obtained.channels;
	shm->samples = obtained.samples * shm->channels;
	shm->samplepos = 0;
	shm->submission_chunk = 1;
	shm->buffer = NULL;

	snd_inited = 1;
	return 1;
//.........这里部分代码省略.........
开发者ID:RichardBruce,项目名称:RAPTor,代码行数:101,代码来源:snd_sdl.c

示例13: EXPORT

EXPORT(bool) InitVideo(int w, int h, std::string sphere_dir)
{

    ScreenWidth  = w;
    ScreenHeight = h;

    static bool firstcall = true;

    // Center the window on the display
    putenv("SDL_VIDEO_CENTERED=1");

    if (firstcall)
    {
        LoadConfiguration(sphere_dir);

        if (!InitScreenBuffer())
            return false;

        // initialize SDL
        // Note: SDL_INIT_EVENTTHREAD is currently not supported on Mac OS X
        if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) == -1)
        {
            fprintf(stderr, "Could not initialize SDL:\n%s\n", SDL_GetError());
            return false;
        }

        SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

        firstcall  = false;

    }
    else
    {
        // reinitialize the screen buffer, because the new resolution can differ
        if (!InitScreenBuffer())
        {
            SDL_Quit();
            return false;
        }

        // reinitialize the SDL video subsystem
        SDL_QuitSubSystem(SDL_INIT_VIDEO);

        if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1)
        {
            fprintf(stderr, "Could not initialize video:\n%s\n", SDL_GetError());
            return false;
        }

        // keep the window title as what it was
        SetWindowTitle(WindowTitle.c_str());
    }

    int s_width  = ScreenBufferWidth  * (Config.scale ? 2 : 1);
    int s_height = ScreenBufferHeight * (Config.scale ? 2 : 1);

    dword flags = 0;
    if (Config.fullscreen)  flags |= SDL_FULLSCREEN;
    if (Config.vsync)       flags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
    else                    flags |= SDL_SWSURFACE;

    // set up the video surface
    SDLScreenBuffer = SDL_SetVideoMode(s_width, s_height, 32, flags);

    if (SDLScreenBuffer == NULL)
    {
        fprintf(stderr, "Could not set video mode:\n%s\n", SDL_GetError());
        return false;
    }

    SDL_ShowCursor(false);
    SetClippingRectangle(0, 0, SDLScreenBuffer->w, SDLScreenBuffer->h);

    return true;
}
开发者ID:FlyingJester,项目名称:sphere,代码行数:75,代码来源:sdl32.cpp

示例14: ECHO

SCA_Joystick *SCA_Joystick::GetInstance( short int joyindex )
{
#ifndef WITH_SDL
	return NULL;
#else  /* WITH_SDL */
	if (joyindex < 0 || joyindex >= JOYINDEX_MAX) {
		ECHO("Error-invalid joystick index: " << joyindex);
		return NULL;
	}

	if (m_refCount == 0) 
	{
		int i;
		/* The video subsystem is required for joystick input to work. However,
		 * when GHOST is running under SDL, video is initialized elsewhere.
		 * Do this once only. */
#  ifdef WITH_GHOST_SDL
		if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1 ) {
#  else
		if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO) == -1 ) {
#  endif
			ECHO("Error-Initializing-SDL: " << SDL_GetError());
			return NULL;
		}
		
		m_joynum = SDL_NumJoysticks();
		
		for (i=0; i<JOYINDEX_MAX; i++) {
			m_instance[i] = new SCA_Joystick(i);
			m_instance[i]->CreateJoystickDevice();
		}
		m_refCount = 1;
	}
	else
	{
		m_refCount++;
	}
	return m_instance[joyindex];
#endif /* WITH_SDL */
}

void SCA_Joystick::ReleaseInstance()
{
	if (--m_refCount == 0)
	{
#ifdef WITH_SDL
		int i;
		for (i=0; i<JOYINDEX_MAX; i++) {
			if (m_instance[i]) {
				m_instance[i]->DestroyJoystickDevice();
				delete m_instance[i];
			}
			m_instance[i] = NULL;
		}

		/* The video subsystem is required for joystick input to work. However,
		 * when GHOST is running under SDL, video is freed elsewhere.
		 * Do this once only. */
#  ifdef WITH_GHOST_SDL
		SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
#  else
		SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO);
#  endif
#endif /* WITH_SDL */
	}
}

void SCA_Joystick::cSetPrecision(int val)
{
	m_prec = val;
}


bool SCA_Joystick::aAxisPairIsPositive(int axis)
{
	return (pAxisTest(axis) > m_prec) ? true:false;
}

bool SCA_Joystick::aAxisPairDirectionIsPositive(int axis, int dir)
{

	int res;

	if (dir==JOYAXIS_UP || dir==JOYAXIS_DOWN)
		res = pGetAxis(axis, 1);
	else /* JOYAXIS_LEFT || JOYAXIS_RIGHT */
		res = pGetAxis(axis, 0);
	
	if (dir==JOYAXIS_DOWN || dir==JOYAXIS_RIGHT)
		return (res > m_prec) ? true : false;
	else /* JOYAXIS_UP || JOYAXIS_LEFT */
		return (res < -m_prec) ? true : false;
}
开发者ID:danielmarg,项目名称:blender-main,代码行数:93,代码来源:SCA_Joystick.cpp

示例15: SDL_GetPlatform

void Audio::start_audio()
{
    if (!sound_enabled)
    {
        // Since many GNU/Linux distros are infected with PulseAudio, SDL2 could chose PA as first
	// driver option before ALSA, and PA doesn't obbey our sample number requests, resulting
	// in audio gaps, if we're on a GNU/Linux we force ALSA.
	// Else we accept whatever SDL2 wants to give us or what the user specifies on SDL_AUDIODRIVER
	// enviroment variable.
	std::string platform = SDL_GetPlatform();
	if (platform=="Linux"){

	    if (SDL_InitSubSystem(SDL_INIT_AUDIO)!=0) {

		std::cout << "Error initalizing audio subsystem: " << SDL_GetError() << std::endl;
	    }

	    if (SDL_AudioInit("alsa")!=0) {
		std::cout << "Error initalizing audio using ALSA: " << SDL_GetError() << std::endl;
		return;
	    }

	}
	else {
	    if(SDL_Init(SDL_INIT_AUDIO) == -1) 
	    {
		std::cout << "Error initalizing audio: " << SDL_GetError() << std::endl;
		return;
	    }		
	}

        // SDL Audio Properties
        SDL_AudioSpec desired, obtained;

        desired.freq     = FREQ;
        desired.format   = AUDIO_S16SYS;
        desired.channels = CHANNELS;
        desired.samples  = SAMPLES;
        desired.callback = fill_audio;
        desired.userdata = NULL;
	
	// SDL2 block
	dev = SDL_OpenAudioDevice(NULL, 0, &desired, &obtained, /*SDL_AUDIO_ALLOW_FORMAT_CHANGE*/0);
	if (dev == 0)
	{
            std::cout << "Error opening audio device: " << SDL_GetError() << std::endl;
            return;
        }

        if (desired.samples != obtained.samples) {
            std::cout << "Error initalizing audio: number of samples not supported." << std::endl
                      << "Please compare desired vs obtained. Look at what audio driver SDL2 is using." << std::endl;
	    return;
	}

        bytes_per_sample = CHANNELS * (BITS / 8);

        // Start Audio
        sound_enabled = true;

        // how many fragments in the dsp buffer
        const int DSP_BUFFER_FRAGS = 5;
        int specified_delay_samps = (FREQ * SND_DELAY) / 1000;
        int dsp_buffer_samps = SAMPLES * DSP_BUFFER_FRAGS + specified_delay_samps;
        dsp_buffer_bytes = CHANNELS * dsp_buffer_samps * (BITS / 8);
        dsp_buffer = new uint8_t[dsp_buffer_bytes];

        // Create Buffer For Mixing
        uint16_t buffer_size = (FREQ / config.fps) * CHANNELS;
        mix_buffer = new uint16_t[buffer_size];

        clear_buffers();
        clear_wav();

        SDL_PauseAudioDevice(dev,0);
    }
}
开发者ID:djyt,项目名称:cannonball,代码行数:77,代码来源:audio.cpp


注:本文中的SDL_InitSubSystem函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。