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


C++ SDL_SetVideoMode函数代码示例

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


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

示例1: main

int main(int argc,char** argv)
{
	SDL_Init(SDL_INIT_EVERYTHING);	//init the SDL
	SDL_Surface* screen=SDL_SetVideoMode(BLOCK_SIZE*WIDTH+BLOCK_SIZE*10,BLOCK_SIZE*HEIGHT,32,SDL_SWSURFACE);	//and our screen
	TTF_Init();	//the TTF as well, cus we want to write out stuff
	TTF_Font* font=TTF_OpenFont("air.ttf",12);
	Uint32 start;	//the start time, to limit FPS
	bool running=true;	//is the program still running?
	SDL_Event event;	//What event has happened?
	srand(time(0));	//seed the random number generator
	int db=0;	//how many blocks do we have (init 0)?
	int elements[8][4][4];	//we store all of the blocks in this 3D array
	int table[HEIGHT][WIDTH];	//This is our whole game-table, all of the blocks, which already put down is stored here
	int currentblock[4][4];	//our current falling block
	fillelement(elements,db);	//load the blocks
	SDL_Surface* blocks=SDL_LoadBMP("blocks.bmp");	//load the image, which stores, the part of the images
	SDL_SetColorKey(blocks,SDL_SRCCOLORKEY,SDL_MapRGB(screen->format,255,0,255));	//The purple color should be invisible
	int blockx;	//the init position of the falling block
	int blocky;
	bool h;	//if it's the 1. or 2. block, we need 4x4, else 3x3
	Uint32 lastmove=SDL_GetTicks();	//how often should the block come down one
	Uint32 lastkey=SDL_GetTicks();	//how often should react the block, when the key is pressed (without release)
	bool keys[2]={0,0};	//if left arrow pressed, than keys[0]=1 if right arrow is pressed keys[1]=1
	int points;
	int normalspeed;	//how quick the tetris blocks fall (in this case once every 0.5 seconds)
	int speed=500;	//the speed, the game currently running (the speed increase, when you press the down arrow)
	const int FPS=30;	//how many FPS the game will run (this effect minimally, how quick the blocks fall)
	int nextblock;	//what is the next block?
	int deletedlines;	//how much lines we already deleted
	int movingspeed=400;	//if we hold down the left/right arrow, how often (150ms) we want to move the block
	int quickmovingspeed=30;
	bool mousepointing=false;	//do we pointing to the toplist text?
	int tmpx,tmpy;	//the location of the mouse cursor
	//we initialize the game (set every parameter to default)
	initGame(&blockx,&blocky,&h,elements,table,currentblock,&normalspeed,&points,&deletedlines,&nextblock,&speed,db);
	int moved=0;
	while(running)	//while the game running
	{
		start=SDL_GetTicks();	//get the current time (for FPS limitation)
		while(SDL_PollEvent(&event))
		{
			switch(event.type)
			{
				case SDL_KEYDOWN:
					switch(event.key.keysym.sym)
					{
						case SDLK_ESCAPE:	//if escape is pressed, escape
							running=false;
							break;
						case SDLK_UP:	//if up arrow is pressed
							rotateleft(currentblock,h);	//rotate the block
							if(checkCollision(currentblock,blockx,blocky,table))	//and check if there is a collision
								for(int i=0;i<3;i++)
									rotateleft(currentblock,h);	//if there was a collision, rotate back (rotate 4 times, is like if you haven't done anything)
									
							break;
						case SDLK_LEFT:
							keys[0]=1;
							break;
						case SDLK_RIGHT:
							keys[1]=1;
							break;
						case SDLK_DOWN:
							speed=10;	//if down key is pressed, speed up a little bit
							break;
					}
					break;
				case SDL_KEYUP:
					switch(event.key.keysym.sym)
					{
						case SDLK_DOWN:
							speed=normalspeed;	//if you released the down arrow, set back the speed
							break;
						case SDLK_LEFT:
							keys[0]=0;
							moved=0;
							break;
						case SDLK_RIGHT:
							keys[1]=0;
							moved=0;
							break;
					}
					break;
				case SDL_QUIT:
					running=false;
					break;
				case SDL_MOUSEMOTION:
					//if we moved the mouse
					tmpx=event.motion.x;	//get the coordinates
					tmpy=event.motion.y;
					//if we are pointing to the square, which contain the toplist text
					if(tmpx>BLOCK_SIZE*WIDTH+2 && tmpx<BLOCK_SIZE*WIDTH+80 && tmpy>80+BLOCK_SIZE*5 && tmpy<80+BLOCK_SIZE*5+20)
						mousepointing=true;	//make this boolean true
					else
						mousepointing=false;	//else false
					break;
				case SDL_MOUSEBUTTONDOWN:
				//if we hit the mousebutton
					tmpx=event.button.x;
					tmpy=event.button.y;
//.........这里部分代码省略.........
开发者ID:helospark,项目名称:tetris,代码行数:101,代码来源:tetris.cpp

示例2: main

int main(int argc, char *argv[])
{
    SDL_Surface *screen;

    // Slightly different SDL initialization
    if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) {
        printf("Unable to initialize SDL: %s\n", SDL_GetError());
        return 1;
    }

    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new*

    screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL ); // *changed*
    if ( !screen ) {
        printf("Unable to set video mode: %s\n", SDL_GetError());
        return 1;
    }

    // Set the OpenGL state after creating the context with SDL_SetVideoMode

    glClearColor( 0, 0, 0, 0 );

#ifndef __EMSCRIPTEN__
    glEnable( GL_TEXTURE_2D ); // Need this to display a texture XXX unnecessary in OpenGL ES 2.0/WebGL
#endif

    glViewport( 0, 0, 640, 480 );

    glMatrixMode( GL_PROJECTION );
    GLfloat matrixData[] = { 2.0/640,        0,  0,  0,
                                   0, -2.0/480,  0,  0,
                                   0,        0, -1,  0,
                                  -1,        1,  0,  1 };
    glLoadMatrixf(matrixData); // test loadmatrix

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    // Load the OpenGL texture

    GLuint texture; // Texture object handle
    SDL_Surface *surface; // Gives us the information to make the texture

    if ( (surface = IMG_Load("screenshot.png")) ) {

        // Check that the image's width is a power of 2
        if ( (surface->w & (surface->w - 1)) != 0 ) {
            printf("warning: image.bmp's width is not a power of 2\n");
        }

        // Also check if the height is a power of 2
        if ( (surface->h & (surface->h - 1)) != 0 ) {
            printf("warning: image.bmp's height is not a power of 2\n");
        }

        // Have OpenGL generate a texture object handle for us
        glGenTextures( 1, &texture );

        // Bind the texture object
        glBindTexture( GL_TEXTURE_2D, texture );

        // Set the texture's stretching properties
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

        //SDL_LockSurface(surface);

        // Add some greyness
        memset(surface->pixels, 0x66, surface->w*surface->h);

        // Edit the texture object's image data using the information SDL_Surface gives us
        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0,
                      GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels );

        //SDL_UnlockSurface(surface);
    }
    else {
        printf("SDL could not load image.bmp: %s\n", SDL_GetError());
        SDL_Quit();
        return 1;
    }

    // Free the SDL_Surface only if it was successfully created
    if ( surface ) {
        SDL_FreeSurface( surface );
    }

    // Clear the screen before drawing
    glClear( GL_COLOR_BUFFER_BIT );

    shaders();

    // Bind the texture to which subsequent calls refer to
    glBindTexture( GL_TEXTURE_2D, texture );

    // Use clientside vertex pointers to render two items
    GLfloat vertexData[] = { 0, 0, 10, 10, // texture2, position2
                             1, 0, 300, 10,
                             1, 1, 300, 128,
                             0, 1, 10, 128,
//.........这里部分代码省略.........
开发者ID:4ian,项目名称:emscripten,代码行数:101,代码来源:gl_ps.c

示例3: printf

bool Game::OnInit()
{
	if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
	{
		printf("SDL_Init > SDL_INIT_EVERYTHING failed.\n");
		return false;
	}

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	if ((gameScreen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 32, SDL_OPENGL)) == NULL)
	{
		printf("Setting gameScreen failed.\n");
		return false;
	}

	// enable texture 2d
	glEnable(GL_TEXTURE_2D);

	// set clear color to black
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	// set our viewport
	glViewport(0, 0, SCREEN_W, SCREEN_H);

	// enable alpha
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	// clear screen
	glClear(GL_COLOR_BUFFER_BIT);

	// set the matrix for projection
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	// set the ortho to the screen
	glOrtho(0.0f, SCREEN_W, SCREEN_H, 0.0f, -1.0f, 1.0f);

	// switch to model view
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	// load lua
	if ((LuaController::Controller.OnInit()) == false)
	{
		printf("Lua initialization failed.\n");
		return false;
	}

	// load player
	if (player.OnLoad("../resources/sprites/player.png", 3, true) == false)
	{
		printf("Loading player failed.\n");
		return false;
	}
	Entity::EntityStack.push_back(&player);

	// Load map
	/*
	if (map.OnLoad("../resources/maps/autotest.map") == false)
	{
		printf("Loading map failed.\n");
		return false;
	}
	*/
	map.OnCreate(30, 25);
	Map::MapStack.push_back(&map);

	player.setPosition(map.getStartX(), map.getStartY());

	if (debugWindow.OnLoad("../resources/sprites/window.png") == false)
	{
		printf("Loading window failed.\n");
		return false;
	}

	debugWindow.setSize(160, 32);
	debugWindow.setPosition(8, 8);
	Window::WindowStack.push_back(&debugWindow);

	Camera::CameraControl.targetMode = TARGET_MODE_CENTER;
	Camera::CameraControl.SetBounds((SDL_Rect){0, 0, map.getTilesX() * TILE_SIZE, map.getTilesY() * TILE_SIZE});

	SDL_WM_SetCaption("Blade Brothers Engine", "../resources/icons/icon.png");

	return true;
}
开发者ID:LeonBlade,项目名称:Blade-Brothers-Engine-Old,代码行数:88,代码来源:Game.cpp

示例4: main

int main(int argc, char *argv[]) {
  SDL_Event       event;
  VideoState      *is;
  is = av_mallocz(sizeof(VideoState));
  if(argc < 2) {
    fprintf(stderr, "Usage: test <file>\n");
    exit(1);
  }
  // Register all formats and codecs
  av_register_all();

  if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
    fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
    exit(1);
  }

  // Make a screen to put our video
#ifndef __DARWIN__
  screen = SDL_SetVideoMode(640, 480, 0, 0);
#else
  screen = SDL_SetVideoMode(640, 480, 24, 0);
#endif
  if(!screen) {
    fprintf(stderr, "SDL: could not set video mode - exiting\n");
    exit(1);
  }

  av_strlcpy(is->filename, argv[1], 1024);


  // 初始化为视频缓冲准备的锁(pictq)
  // 因为一旦事件驱动调用视频函数, 视频函数会从 pictq 抽出预解码帧。
  // 同时, 视频解码器会把信息放进去, 我们不知道那个动作会先发生。
  is->pictq_mutex = SDL_CreateMutex();
  is->pictq_cond = SDL_CreateCond();

  // schedule_refresh 是一个将要定义的函数。它的动作是告诉系统在某个特定的毫秒数后弹出 FF_REFRESH_EVENT 事件。
  schedule_refresh(is, 40);

  is->av_sync_type = DEFAULT_AV_SYNC_TYPE;
  // 生成一个新线程能完全访问原始进程中的内存,启动我们给的线程,在这种情况下, 调用 decode_thread()并与 VideoState 结构体连接。
  is->parse_tid = SDL_CreateThread(decode_thread, is);
  if(!is->parse_tid) {
    av_free(is);
    return -1;
  }

//  事件循环
  for(;;) {

    SDL_WaitEvent(&event);
    switch(event.type) {
    case FF_QUIT_EVENT:
    case SDL_QUIT:
      is->quit = 1;
      /*
       * If the video has finished playing, then both the picture and
       * audio queues are waiting for more data.  Make them stop
       * waiting and terminate normally.
       */
      SDL_CondSignal(is->audioq.cond);
      SDL_CondSignal(is->videoq.cond);
      SDL_Quit();
      exit(0);
      break;
    case FF_ALLOC_EVENT:
      alloc_picture(event.user.data1);
      break;
    case FF_REFRESH_EVENT:
      video_refresh_timer(event.user.data1);
      break;
    default:
      break;
    }
  }
  return 0;
}
开发者ID:feixiao,项目名称:ffmpeg-tutorial,代码行数:77,代码来源:tutorial06.c

示例5: plat_sdl_change_video_mode

/* w, h is layer resolution */
int plat_sdl_change_video_mode(int w, int h, int force)
{
  static int prev_w, prev_h;

  if (w == 0)
    w = prev_w;
  else
    prev_w = w;
  if (h == 0)
    h = prev_h;
  else
    prev_h = h;

  // skip GL recreation if window doesn't change - avoids flicker
  if (plat_target.vout_method == vout_mode_gl && plat_sdl_gl_active
      && plat_target.vout_fullscreen == old_fullscreen && !force)
  {
    return 0;
  }

  if (plat_sdl_overlay != NULL) {
    SDL_FreeYUVOverlay(plat_sdl_overlay);
    plat_sdl_overlay = NULL;
  }
  if (plat_sdl_gl_active) {
    gl_finish();
    plat_sdl_gl_active = 0;
  }

  if (plat_target.vout_method != 0) {
    Uint32 flags = SDL_RESIZABLE | SDL_SWSURFACE;
    int win_w = window_w;
    int win_h = window_h;

    if (plat_target.vout_fullscreen) {
      flags |= SDL_FULLSCREEN;
      win_w = fs_w;
      win_h = fs_h;
    }

    // XXX: workaround some occasional mysterious deadlock in SDL_SetVideoMode
    SDL_PumpEvents();

    plat_sdl_screen = SDL_SetVideoMode(win_w, win_h, 0, flags);
    if (plat_sdl_screen == NULL) {
      fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError());
      plat_target.vout_method = 0;
    }
  }

  if (plat_target.vout_method == vout_mode_overlay) {
    plat_sdl_overlay = SDL_CreateYUVOverlay(w, h, SDL_UYVY_OVERLAY, plat_sdl_screen);
    if (plat_sdl_overlay != NULL) {
      if ((long)plat_sdl_overlay->pixels[0] & 3)
        fprintf(stderr, "warning: overlay pointer is unaligned\n");

      plat_sdl_overlay_clear();
    }
    else {
      fprintf(stderr, "warning: could not create overlay.\n");
      plat_target.vout_method = 0;
    }
  }
  else if (plat_target.vout_method == vout_mode_gl) {
    plat_sdl_gl_active = (gl_init(display, window, &gl_quirks) == 0);
    if (!plat_sdl_gl_active) {
      fprintf(stderr, "warning: could not init GL.\n");
      plat_target.vout_method = 0;
    }
  }

  if (plat_target.vout_method == 0) {
    SDL_PumpEvents();

    plat_sdl_screen = SDL_SetVideoMode(w, h, 16, SDL_SWSURFACE);
    if (plat_sdl_screen == NULL) {
      fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError());
      return -1;
    }
  }

  old_fullscreen = plat_target.vout_fullscreen;
  if (plat_sdl_resize_cb != NULL)
    plat_sdl_resize_cb(plat_sdl_screen->w, plat_sdl_screen->h);

  return 0;
}
开发者ID:CatalystG,项目名称:libpicofe,代码行数:88,代码来源:plat_sdl.c

示例6: g_Open


//.........这里部分代码省略.........
		
		player->x=2.5;
		player->y=2.5;
		player->z=0;
		player->ang=0;
	}
	vang=0;
	bob1 = 0; bob2 = 0; bob3 = 1;
	weap_mag[2]=2;
	
	// set camera
	camx=8;
	camy=2.5;
	camz=0;
	camang=0;

	// initiate SDL
	if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER ) == -1 ) {
		printf("ERROR: Could not initialize SDL. Aborting...\n\n");
		g_Close();
		exit(4);
	}
	//SDL_WM_GrabInput(SDL_GRAB_ON);
	
	// open audio
	if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
		printf("Unable to open audio!\n");
		exit(1);
	}

	// create a screen surface
	screen = SDL_CreateRGBSurface(SDL_HWSURFACE,xres,yres,32,0,0,0,0);
	if( !windowed )
		screen2 = SDL_SetVideoMode( xres, yres, 32, SDL_HWSURFACE | SDL_FULLSCREEN );
	else
		screen2 = SDL_SetVideoMode( xres, yres, 32, SDL_HWSURFACE );
	if( screen == NULL || screen2 == NULL ) {
		printf("ERROR: Could not create video surface. Aborting...\n\n");
		g_Close();
		exit(5);
	}
	SDL_WM_SetCaption( "Bubbenstein/SDL\n\n", 0 );
	SDL_ShowCursor(SDL_DISABLE);
	
	// reset the clock
	ot=SDL_GetTicks();
	i_GetFrameRate();
	
	// load sound effects
	fp = fopen("sound/sounds.txt","r");
	for( sound_num=0; !feof(fp); sound_num++ ) {
		while( fgetc(fp) != '\n' ) if( feof(fp) ) break;
	}
	fclose(fp);
	sounds = (Mix_Chunk **) malloc(sizeof(psize)*sound_num);
	fp = fopen("sound/sounds.txt","r");
	for( x=0; !feof(fp); x++ ) {
		fscanf(fp,"%s",name); while( fgetc(fp) != '\n' ) if( feof(fp) ) break;
		sounds[x] = Mix_LoadWAV(name);
	}
	fclose(fp);
	
	// load music
	music = Mix_LoadMUS("music/dead.ogg");
	Mix_VolumeMusic(64);
	//Mix_PlayMusic(music, -1);
开发者ID:SheridanR,项目名称:BSDL,代码行数:67,代码来源:g_data.c

示例7: SDL_GL_SetAttribute

	void SDLWindow::create(const String& name, unsigned int width, unsigned int height,
	            bool fullScreen, const NameValuePairList *miscParams)
    {
		int colourDepth = 32;
		String title = name;
		if(miscParams)
		{
			// Parse miscellenous parameters
			NameValuePairList::const_iterator opt;
			// Bit depth
			opt = miscParams->find("colourDepth");
			if(opt != miscParams->end()) //check for FSAA parameter, if not ignore it...
				colourDepth = StringConverter::parseUnsignedInt(opt->second);
			// Full screen antialiasing
			opt = miscParams->find("FSAA");
			if(opt != miscParams->end()) //check for FSAA parameter, if not ignore it...
			{
				size_t fsaa_x_samples = StringConverter::parseUnsignedInt(opt->second);
				if(fsaa_x_samples>1) {
					// If FSAA is enabled in the parameters, enable the MULTISAMPLEBUFFERS
					// and set the number of samples before the render window is created.
					SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1);
					SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,fsaa_x_samples);
				}
			}
			// Window title
			opt = miscParams->find("title");
			if(opt != miscParams->end()) //check for FSAA parameter, if not ignore it...
				title = opt->second;
		}   
	
        LogManager::getSingleton().logMessage("SDLWindow::create", LML_TRIVIAL);
        SDL_Surface* screen;
        int flags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE;
		
        SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
        // request good stencil size if 32-bit colour
        if (colourDepth == 32)
        {
            SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 8);
        }
		
        if (fullScreen)
            flags |= SDL_FULLSCREEN;

        LogManager::getSingleton().logMessage("Create window", LML_TRIVIAL);
        screen = SDL_SetVideoMode(width, height, colourDepth, flags);
        if (!screen)
        {
            LogManager::getSingleton().logMessage(LML_CRITICAL, 
                String("Could not make screen: ") + SDL_GetError());
            exit(1);
        }
        LogManager::getSingleton().logMessage("screen is valid", LML_TRIVIAL);
        mScreen = screen;

        mName = name;

        mWidth = width;
        mHeight = height;

        mActive = true;

        if (!fullScreen)
            SDL_WM_SetCaption(title.c_str(), 0);

        glXGetVideoSyncSGI = (int (*)(unsigned int *))SDL_GL_GetProcAddress("glXGetVideoSyncSGI");
        glXWaitVideoSyncSGI = (int (*)(int, int, unsigned int *))SDL_GL_GetProcAddress("glXWaitVideoSyncSGI");
    }
开发者ID:MrLobo,项目名称:El-Rayo-de-Zeus,代码行数:69,代码来源:OgreSDLWindow.cpp

示例8: display

/**
 * Display a video frame
 *
 * @param st    Video display state
 * @param title Window title
 * @param frame Video frame
 *
 * @return 0 if success, otherwise errorcode
 *
 * @note: On Darwin, this must be called from the main thread
 */
static int display(struct vidisp_st *st, const char *title,
		   const struct vidframe *frame)
{
	SDL_Rect rect;

	if (!st || !sdl.open)
		return EINVAL;

	if (!vidsz_cmp(&sdl.size, &frame->size)) {
		if (sdl.size.w && sdl.size.h) {
			info("sdl: reset size %u x %u  --->  %u x %u\n",
			     sdl.size.w, sdl.size.h,
			     frame->size.w, frame->size.h);
		}
		sdl_reset();
	}

	if (!sdl.screen) {
		int flags = SDL_HWSURFACE | SDL_ASYNCBLIT | SDL_HWACCEL;
		char capt[256];

		if (sdl.fullscreen)
			flags |= SDL_FULLSCREEN;
		else if (sdl.resizeh)
			flags |= SDL_RESIZABLE;

		if (title) {
			re_snprintf(capt, sizeof(capt), "%s - %u x %u",
				    title, frame->size.w, frame->size.h);
		}
		else {
			re_snprintf(capt, sizeof(capt), "%u x %u",
				    frame->size.w, frame->size.h);
		}

		SDL_WM_SetCaption(capt, capt);

		sdl.screen = SDL_SetVideoMode(frame->size.w, frame->size.h,
					      0, flags);
		if (!sdl.screen) {
			warning("sdl: unable to get video screen: %s\n",
				SDL_GetError());
			return ENODEV;
		}

		sdl.size = frame->size;
	}

	if (!sdl.bmp) {
		sdl.bmp = SDL_CreateYUVOverlay(frame->size.w, frame->size.h,
					       SDL_YV12_OVERLAY, sdl.screen);
		if (!sdl.bmp) {
			warning("sdl: unable to create overlay: %s\n",
				SDL_GetError());
			return ENODEV;
		}
	}

	SDL_LockYUVOverlay(sdl.bmp);
	picture_copy(sdl.bmp->pixels, sdl.bmp->pitches, frame);
	SDL_UnlockYUVOverlay(sdl.bmp);

	rect.x = 0;
	rect.y = 0;
	rect.w = sdl.size.w;
	rect.h = sdl.size.h;

	SDL_DisplayYUVOverlay(sdl.bmp, &rect);

	return 0;
}
开发者ID:AmesianX,项目名称:baresip,代码行数:82,代码来源:sdl.c

示例9: main

int main()
{
#ifdef __MIPSEL__
    create_app_dir(BASE_PATH);
#endif

    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        log(FATAL, "Cannot init SDL.");
    }

    if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_HWSURFACE | SDL_DOUBLEBUF)))
    {
        SDL_Quit();
        log(FATAL, "Cannot SetVideoMode.");
    }

    SDL_ShowCursor(SDL_DISABLE);

    if (TTF_Init() < 0)
    {
        SDL_Quit();
        log(FATAL, "Unable to start the TTF.");
    }

    int img_flags = IMG_INIT_PNG;

    if(!(IMG_Init(img_flags) & img_flags))
    {
        TTF_Quit();
        SDL_Quit();
        log(FATAL, "SDL_image could not initialize. %s.", IMG_GetError());
    }

    pconfig = new Config();
    pconfig->load();

    pmixer = new Mixer();
    current_volume = pmixer->get_speaker_volume();
    pmixer->set_speaker_volume(current_volume);

    load_resources();
    draw_buttons();
    draw_timer(0, 0, 0);
    draw_volume();
    draw_vu(1, -1);
    draw_vu(1, 1);

    pmic = new Mic();
    pmic->set_on_terminate_event(on_terminate_exec);
    pmic->set_on_vu_change_event(on_vu_changed);

    main_loop();

    delete pmic;
    delete pmixer;
    delete pconfig;

    TTF_CloseFont(font_10);
    TTF_CloseFont(font_28);

    IMG_Quit();
    TTF_Quit();
    SDL_Quit();

    return 0;
}
开发者ID:alexandrevicenzi,项目名称:gcw_mic,代码行数:67,代码来源:screen.cpp

示例10: SetVideoMode

static void SetVideoMode(screen_mode_t *mode, int w, int h)
{
    byte *doompal;
    int flags = 0;

    doompal = W_CacheLumpName(DEH_String("PLAYPAL"), PU_CACHE);

    // If we are already running and in a true color mode, we need
    // to free the screenbuffer surface before setting the new mode.

    if (screenbuffer != NULL && screen != screenbuffer)
    {
        SDL_FreeSurface(screenbuffer);
    }

    // Generate lookup tables before setting the video mode.

    if (mode != NULL && mode->InitMode != NULL)
    {
        mode->InitMode(doompal);
    }

    // Set the video mode.

    flags |= SDL_SWSURFACE | SDL_DOUBLEBUF;

    if (screen_bpp == 8)
    {
        flags |= SDL_HWPALETTE;
    }

    if (fullscreen)
    {
        flags |= SDL_FULLSCREEN;
    }
    else
    {
        // In windowed mode, the window can be resized while the game is
        // running.  This feature is disabled on OS X, as it adds an ugly
        // scroll handle to the corner of the screen.

#ifndef __MACOSX__
        flags |= SDL_RESIZABLE;
#endif
    }

    screen = SDL_SetVideoMode(w, h, screen_bpp, flags);

    if (screen == NULL)
    {
        I_Error("Error setting video mode %ix%ix%ibpp: %s\n",
                w, h, screen_bpp, SDL_GetError());
    }

    // Blank out the full screen area in case there is any junk in
    // the borders that won't otherwise be overwritten.

    SDL_FillRect(screen, NULL, 0);

    // If mode was not set, it must be set now that we know the
    // screen size.

    if (mode == NULL)
    {
        mode = I_FindScreenMode(screen->w, screen->h);

        if (mode == NULL)
        {
            I_Error("I_InitGraphics: Unable to find a screen mode small "
                    "enough for %ix%i", screen->w, screen->h);
        }

        // Generate lookup tables before setting the video mode.

        if (mode->InitMode != NULL)
        {
            mode->InitMode(doompal);
        }
    }

    // Create the screenbuffer surface; if we have a real 8-bit palettized
    // screen, then we can use the screen as the screenbuffer.

    if (screen->format->BitsPerPixel == 8)
    {
        screenbuffer = screen;
    }
    else
    {
        screenbuffer = SDL_CreateRGBSurface(SDL_SWSURFACE,
                                            mode->width, mode->height, 8,
                                            0, 0, 0, 0);

        SDL_FillRect(screenbuffer, NULL, 0);
    }

    // Save screen mode.

    screen_mode = mode;
}
开发者ID:twipley,项目名称:chocolate-doom,代码行数:100,代码来源:i_video.c

示例11: GLimp_InitGraphics

/*
** GLimp_InitGraphics
**
** This initializes the software refresh's implementation specific
** graphics subsystem.  In the case of Windows it creates DIB or
** DDRAW surfaces.
**
** The necessary width and height parameters are grabbed from
** vid.width and vid.height.
*/
static qboolean GLimp_InitGraphics( qboolean fullscreen )
{
	int flags;
	
	/* Just toggle fullscreen if that's all that has been changed */
	if (surface && (surface->w == vid.width) && (surface->h == vid.height)) {
		int isfullscreen = (surface->flags & SDL_FULLSCREEN) ? 1 : 0;
		if (fullscreen != isfullscreen)
			SDL_WM_ToggleFullScreen(surface);

		isfullscreen = (surface->flags & SDL_FULLSCREEN) ? 1 : 0;
		if (fullscreen == isfullscreen)
			return true;
	}
	
	srandom(getpid());

	// free resources in use
	if (surface)
		SDL_FreeSurface(surface);

	// let the sound and input subsystems know about the new window
	ri.Vid_NewWindow (vid.width, vid.height);

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	if (1) {
		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, 24);
		SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
        }
        else {
		SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
		SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
		SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
		SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
        }
	
	flags = SDL_OPENGL;
	if (fullscreen)
		flags |= SDL_FULLSCREEN;
	
	SetSDLIcon(); /* currently uses q2icon.xbm data */
	
	if ((surface = SDL_SetVideoMode(vid.width, vid.height, 0, flags)) == NULL) {
		Sys_Error("(SDLGL) SDL SetVideoMode failed: %s\n", SDL_GetError());
		return false;
	}

	// stencilbuffer shadows
 	{
		int stencil_bits;
	  
		have_stencil = false;
	  
		if (!SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil_bits)) {
			ri.Con_Printf(PRINT_ALL, "I got %d bits of stencil\n", 
			              stencil_bits);
		
			if (stencil_bits >= 1) {
				have_stencil = true;
	    		}
	  	}
	}

	SDL_WM_SetCaption(WINDOW_CLASS_NAME, WINDOW_CLASS_NAME);

	SDL_ShowCursor(0);

	X11_active = true;
		
	SetSDLGamma();
	
	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

	return true;
}
开发者ID:jitspoe,项目名称:starviewer,代码行数:90,代码来源:gl_sdl.c

示例12: sdlfb_control

static rt_err_t  sdlfb_control(rt_device_t dev, rt_uint8_t cmd, void *args)
{
	struct sdlfb_device *device;

	device = (struct sdlfb_device*)dev;
	RT_ASSERT(device != RT_NULL);
	RT_ASSERT(device->screen != RT_NULL);

	switch (cmd)
	{
	case RTGRAPHIC_CTRL_GET_INFO:
		{
		struct rt_device_graphic_info *info;

		info = (struct rt_device_graphic_info*) args;
		info->bits_per_pixel = 16;
		info->pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
		info->framebuffer = device->screen->pixels;
		info->width = device->screen->w;
		info->height = device->screen->h;
		}
		break;
	case RTGRAPHIC_CTRL_RECT_UPDATE:
		{
		struct rt_device_rect_info *rect;
		rect = (struct rt_device_rect_info*)args;

		/* SDL_UpdateRect(_device.screen, rect->x, rect->y, rect->x + rect->w, rect->y + rect->h); */
		SDL_UpdateRect(_device.screen, 0, 0, device->width, device->height);
		}
		break;
	case RTGRAPHIC_CTRL_SET_MODE:
		{		
		struct rt_device_rect_info* rect;

		rect = (struct rt_device_rect_info*)args;
		if ((_device.width == rect->width) && (_device.height == rect->height)) return -RT_ERROR;
		
		_device.width = rect->width;
		_device.height = rect->height;
		
		if (_device.screen != RT_NULL)
		{
			SDL_FreeSurface(_device.screen);
		
			/* re-create screen surface */
			_device.screen = SDL_SetVideoMode(_device.width, _device.height, 16, SDL_SWSURFACE | SDL_DOUBLEBUF);
			if ( _device.screen == NULL )
			{
				fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
				exit(1);
			}

			SDL_WM_SetCaption ("RT-Thread/GUI Simulator", NULL);
		}
		}
		break;
	}

	return RT_EOK;
}
开发者ID:aozima,项目名称:RTGUI,代码行数:61,代码来源:sdl_fb.c

示例13: sdl_free

void sdl_free( void ) {
	if( config_get()->iface.full_screen )
		SDL_SetVideoMode( saved_video.current_w, saved_video.current_h, saved_video.vfmt->BitsPerPixel, SDL_FULLSCREEN );
	SDL_Quit();
}
开发者ID:anvil0fcrom,项目名称:cabrio,代码行数:5,代码来源:sdl_wrapper.c

示例14: main

int main(int argc, char *argv[])
{	//inicializando SDL
        if(SDL_Init(SDL_INIT_VIDEO)<0)
        {       printf("Error al establecer modo video\n");exit(1);}
        SDL_WM_SetCaption("Prueba_botones",NULL);
        screen=SDL_SetVideoMode(ancho,alto,24,SDL_SWSURFACE);
        if(screen==NULL)
        {       printf("No se establecio el modo de video\n");
                exit(1);
        }
	//font
	TTF_Init();
	font_num=TTF_OpenFont("fonts/quid.ttf",60);
	if(font_num==NULL)
		printf("Error al cargar font\n");
	font_menu=TTF_OpenFont("fonts/font_menu.ttf",80);
	if(font_menu==NULL)
		printf("Error al cargar font_menu\n");
	font=TTF_OpenFont("fonts/FUAA.ttf",34);
	if(font==NULL)
		printf("Error en font\n");
	font_op=TTF_OpenFont("fonts/FUAA.ttf",20);
	arbol_ttf=TTF_OpenFont("fonts/arbol.ttf",25);
	if(arbol_ttf==NULL)
		printf("Error al cargar arbol\n");
	recorrido_ttf=TTF_OpenFont("fonts/arbol.ttf",17);
	fcolor.r=0; fcolor.g=0; fcolor.b=0;
	
	//principal
	A=NULL;
	int opcion=-1,n,dato;
	SDL_Rect pos;
	cargando_interface();
	menu_principal();
	draw_interface_principal();
	SDL_Event evento;
	while(opcion!=0)
	{	SDL_WaitEvent(&evento);
		if(evento.type==SDL_MOUSEMOTION)
		{	if(posicion_cursor(20,85,12,35,evento.motion.x,evento.motion.y))
			{	pos.x=20; pos.y=12;
				SDL_BlitSurface(boton_insertar[1],NULL,screen,&pos);
			}
			else if(posicion_cursor(145,210,12,35,evento.motion.x,evento.motion.y))
                        {       pos.x=145; pos.y=12;
                                SDL_BlitSurface(boton_eliminar[1],NULL,screen,&pos);
                        }
			else if(posicion_cursor(270,335,12,35,evento.motion.x,evento.motion.y))
                        {       pos.x=270; pos.y=12;
                                SDL_BlitSurface(boton_recorridos[1],NULL,screen,&pos);
                        }
			else if(posicion_cursor(820,885,12,35,evento.motion.x,evento.motion.y))
                        {       pos.x=820; pos.y=12;
                                SDL_BlitSurface(boton_salir[1],NULL,screen,&pos);
                        }
			else
				draw_menu_botones();
			SDL_Flip(screen);		
		}
		else if(evento.type==SDL_MOUSEBUTTONDOWN)
		{	if(posicion_cursor(820,885,12,35,evento.button.x,evento.button.y))
                        {
				menu_principal();
			}
			else if(posicion_cursor(20,85,12,35,evento.button.x,evento.button.y))
			{	dato=mini_ventana("Insertar dato: ",1);
				if(bandera!=0 && nivel_superado(A,0,dato))
					ventana_alerta("La rama supero el maximo");
				else
				{	if(bandera!=0)
						insertar_arbol(&A,dato);
					calcular_posiciones(A,70,450,450,0);
				}
				print_arbol(A,0);
				SDL_Flip(screen);
			}
			else if(posicion_cursor(145,210,12,35,evento.button.x,evento.button.y))
			{	dato=mini_ventana("Eliminar dato: ",2);
				eliminar(&A,dato);
				draw_interface_principal();
				calcular_posiciones(A,70,450,450,0);
				print_arbol(A,0);
				SDL_Flip(screen);
				
			}
			else if(posicion_cursor(270,335,12,35,evento.button.x,evento.button.y))
			{	ventana_recorridos();
			}
	
		}
		else if(evento.type==SDL_KEYDOWN)
                {       switch(evento.key.keysym.sym)
                        {       case SDLK_1:
				{ 	dato=mini_ventana("Insertar dato: ",1);
                               		if(bandera!=0 && nivel_superado(A,0,dato))
                                		ventana_alerta("La rama supero el maximo");	
					else
	                                {       if(bandera!=0)
        	                                        insertar_arbol(&A,dato);
                	                        calcular_posiciones(A,70,450,450,0);
//.........这里部分代码省略.........
开发者ID:positr0nix,项目名称:UTM,代码行数:101,代码来源:arboles_main.c

示例15: SDL_SetVideoMode

//-----------------------------------------------------------------------------
// Initialize
//-----------------------------------------------------------------------------
bool GraphicsPlugin::initialize(GFX_INFO* graphicsInfo)
{
    //Initialize video output
    if (CoreVideo_Init() != M64ERR_SUCCESS)
    {
        Logger::getSingleton().printMsg("Could not initialize video.", M64MSG_ERROR);
        return false;
    }

    //Save pointer to graphics info
    m_graphicsInfo = graphicsInfo;

    m_numDListProcessed = 0;

    //Detect what rom it is
    m_romDetector = &ROMDetector::getSingleton();        
    m_romDetector->initialize( m_graphicsInfo->HEADER );
#ifdef HAVE_GLES
	SDL_SetVideoMode(m_config->fullscreenWidth, m_config->fullscreenHeight, m_config->fullscreenBitDepth, SDL_FULLSCREEN);
    SDL_ShowCursor(SDL_DISABLE);
	EGL_Open(m_config->fullscreenWidth, m_config->fullscreenHeight);
#else
    if (m_config->multiSampling > 0)
    {
        CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLEBUFFERS, 1);
        if (m_config->multiSampling <= 2)
            CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 2);
        else if (m_config->multiSampling <= 4)
            CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 4);
        else if (m_config->multiSampling <= 8)
            CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 8);
        else
            CoreVideo_GL_SetAttribute(M64P_GL_MULTISAMPLESAMPLES, 16);
    }

    if (CoreVideo_GL_SetAttribute(M64P_GL_DOUBLEBUFFER, 1) != M64ERR_SUCCESS ||
        CoreVideo_GL_SetAttribute(M64P_GL_BUFFER_SIZE, 32) != M64ERR_SUCCESS ||
        CoreVideo_GL_SetAttribute(M64P_GL_DEPTH_SIZE, 24)  != M64ERR_SUCCESS)
    {
        Logger::getSingleton().printMsg("Could not set video attributes.", M64MSG_ERROR);
        return false;
    }

    if (CoreVideo_SetVideoMode(m_config->fullscreenWidth, m_config->fullscreenHeight, m_config->fullscreenBitDepth, 
        m_config->startFullscreen ? M64VIDEO_FULLSCREEN : M64VIDEO_WINDOWED, (m64p_video_flags) 0) != M64ERR_SUCCESS)
    {
        Logger::getSingleton().printMsg("Could not set video mode.", M64MSG_ERROR);
        return false;
    }

    CoreVideo_SetCaption("Arachnoid");
#endif
    //Initialize Video Interface
    m_vi = new VI();
    m_vi->calcSize(m_graphicsInfo);

    //Initialize Memory
    m_memory = new Memory();
    if ( !m_memory->initialize(m_graphicsInfo->RDRAM, m_graphicsInfo->DMEM) ) 
    {
        return false;
    }
    
    m_displayListParser = new DisplayListParser();
    m_displayListParser->initialize(&m_rsp, &m_rdp, &m_gbi, m_memory);

    //Init OpenGL
    if ( !m_openGLMgr.initialize(m_config->startFullscreen, m_config->fullscreenWidth, m_config->fullscreenHeight, m_config->fullscreenBitDepth, m_config->fullscreenRefreshRate, true, false) ) 
    {
        Logger::getSingleton().printMsg("Unable to initialize OpenGL", M64MSG_ERROR);
        return false;
    }

    
    m_openGLMgr.calcViewScale(m_vi->getWidth(), m_vi->getHeight());

    //Initialize Fog Manager
    m_fogManager = new FogManager();
    m_fogManager->initialize();



    //Initialize Texture Cache
    //! @todo Not "hardcode" TextureBitDepth.
    m_textureCache.initialize(&m_rsp, &m_rdp, m_memory, 16);
    m_textureCache.setMipmap( m_config->mipmapping );

    //Initialize OpenGL Renderer
    if ( !OpenGLRenderer::getSingleton().initialize(&m_rsp, &m_rdp, &m_textureCache, m_vi, m_fogManager) ) 
    {
        Logger::getSingleton().printMsg("Unable to initialize OpenGL Renderer", M64MSG_ERROR);
        return false;
    }

    //Initialize Processors
    m_rdp.initialize(m_graphicsInfo, &m_rsp, m_memory, &m_gbi, &m_textureCache, m_vi, m_displayListParser, m_fogManager);
    m_rsp.initialize(m_graphicsInfo, &m_rdp, m_memory, m_vi, m_displayListParser, m_fogManager);
//.........这里部分代码省略.........
开发者ID:ptitSeb,项目名称:mupen64plus-pandora,代码行数:101,代码来源:GraphicsPlugin.cpp


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