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


C++ SDL_RenderClear函数代码示例

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


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

示例1: main

int main( int argc, char* args[] )
{
	//Start up SDL and create window
	if( !init() )
	{
		printf( "Failed to initialize!\n" );
	}
	else
	{
		//Load media
		if( !loadMedia() )
		{
			printf( "Failed to load media!\n" );
		}
		else
		{
			//Main loop flag
			bool quit = false;

			//Event handler
			SDL_Event e;

			//Modulation component
			Uint8 a = 255;

			//While application is running
			while( !quit )
			{
				//Handle events on queue
				while( SDL_PollEvent( &e ) != 0 )
				{
					//User requests quit
					if( e.type == SDL_QUIT )
					{
						quit = true;
					}
					//Handle key presses
					else if( e.type == SDL_KEYDOWN )
					{
						//Increase alpha on w
						if( e.key.keysym.sym == SDLK_w )
						{
							//Cap if over 255
							if( a + 32 > 255 )
							{
								a = 255;
							}
							//Increment otherwise
							else
							{
								a += 32;
							}
						}
						//Decrease alpha on s
						else if( e.key.keysym.sym == SDLK_s )
						{
							//Cap if below 0
							if( a - 32 < 0 )
							{
								a = 0;
							}
							//Decrement otherwise
							else
							{
								a -= 32;
							}
						}
					}
				}

				//Clear screen
				SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
				SDL_RenderClear( gRenderer );

				//Render background
				gBackgroundTexture.render( 0, 0 );

				//Render front blended
				gModulatedTexture.setAlpha( a );
				gModulatedTexture.render( 0, 0 );

				//Update screen
				SDL_RenderPresent( gRenderer );
			}
		}
	}

	//Free resources and close SDL
	close();

	return 0;
}
开发者ID:stillcollating,项目名称:projects,代码行数:92,代码来源:13_alpha_blending.cpp

示例2: main

int main(int argc, char* argv[]) {
    //initialize and loading variables
    char *bgmm[11] = { "l1.mp3", "l2.mp3", "l3.mp3", "l4.mp3", "l5.mp3", "l6.mp3", "l7.mp3", "l8.mp3", "l9.mp3", "l10.mp3", "l11.mp3" };
    char *bv[11] = { "can we live together.wav",
        "can't you just relax do you even remember.wav",
        "chage is good for you.wav",
        "grace and integrity are what define us.wav",
        "how do thrive and grow under pressure.wav",
        "i don't want you to keep going.wav",
        "i know sometimes it feels like you have no controle",
        "i want to help you but you need to let me.wav",
        "is there another way.wav",
        "once an action is done it cannot be undone.wav",
        "push any further and yu will  break.wav" };
    SDL_Color color;
    const point center = { 220.0, 350.0 };
    int currenttick, score=0;
    short circleradius = 44,musicselect=0;
    boolean mainmenu = yes;
    double theta = 0.0,speed=0.09;
    //Uint8 alpha;
    SDL_Renderer *rendertarget = NULL;
    
    SDL_Rect rectangle1 = { 320, 0, 100, 20 }, rectangle2 = { 230, rectangle1.y-80, 100, 20 };
    SDL_Rect littlerectangle1 = { 310, rectangle1.y - 165, 50, 20 };
    SDL_Rect cube1 = { 300, rectangle1.y - 270, 40, 40 }, cube2 = { 310, cube1.y - 90, 40, 40 }, cube3 = { 305, cube2.y - 90, 40, 40 };
    
    SDL_Rect redballposition = { center.x + circleradius*sin(theta), center.y + circleradius*cos(theta), 25, 25 };
    SDL_Rect blueballposition = { center.x - circleradius*sin(theta), center.y - circleradius*cos(theta), 25, 25 };
    
    const Uint8 *keystate;
    SDL_Window *window = NULL;
    SDL_Texture *redball = NULL, *blueball = NULL, *box = NULL; //gametexture
    
    // Initialize SDL2
    SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
    Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 2560);
    Mix_Music *bgm = Mix_LoadMUS("l1.mp3");
    
    Mix_Chunk *voice = Mix_LoadWAV("trust your instincts.wav"), *hitsound = Mix_LoadWAV("Samples/3816133910831170.wav");
    Mix_PlayChannel(2,voice,0);
    Mix_PlayMusic(bgm, -1);
    
    
    
    // Create an application window with the following settings:
    window = SDL_CreateWindow("An SDL2 window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 440, 480, SDL_WINDOW_SHOWN  );
    
    rendertarget = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
    box = loadTexture("box.png", rendertarget);
    
    redball = loadTexture("redball.png", rendertarget);
    blueball = loadTexture("bleuball.png", rendertarget);
    
    
    //SDL_SetRenderDrawColor(rendertarget, 0x23, 0x23, 0x23, 0x23);
    SDL_SetRenderDrawColor(rendertarget, 0x99, 0x99, 0xF8, 0x23);
    color.r = 0x99;
    color.g = 0x99;
    color.b = 0xF8;
    color.a = 0x23;
    option select = exitgame;
    //gameloop
    
    boolean gamerunning = yes, programruns = yes;
    SDL_Event e;
    
    while (programruns == yes){
        while (gamerunning == yes && select == startgame){
            
            
            while (SDL_PollEvent(&e)) {
                if (e.type == SDL_QUIT)
                    gamerunning = no;
            };
            srand(time(0));
            
            currenttick = SDL_GetTicks();
            if (e.key.keysym.scancode == SDL_SCANCODE_ESCAPE){
                SDL_RenderClear(rendertarget);
                SDL_RenderPresent(rendertarget);
                //SDL_RenderCopy(rendertarget, gameTitle, NULL, &Gametitleposition);
                //update(gameTitle, Gametitleposition);
                
                SDL_RenderPresent(rendertarget);
                mainmenu = yes;
                break;
                //code to stop game and get back to menu
            }
            keystate = SDL_GetKeyboardState(NULL);
            
            if (keystate[SDL_SCANCODE_LEFT]) {
                theta += speed;
                redballposition.x = center.x + circleradius*sin(theta);
                redballposition.y = center.y + circleradius*cos(theta);
                blueballposition.x = center.x - circleradius*sin(theta);
                blueballposition.y = center.y - circleradius*cos(theta);
            }
            else if (keystate[SDL_SCANCODE_RIGHT]){
                
//.........这里部分代码省略.........
开发者ID:afritfr,项目名称:Duet-Game,代码行数:101,代码来源:main.c

示例3: SDL_RenderClear

void Graphics::clear() {
	SDL_RenderClear(this->_renderer);
}
开发者ID:tkinneen,项目名称:Cavestory_Remake,代码行数:3,代码来源:graphics.cpp

示例4: av_register_all


//.........这里部分代码省略.........
	//Output Info-----------------------------
	printf("---------------- File Information ---------------\n");
	av_dump_format(pFormatCtx, 0, filepath, 0);
	printf("-------------------------------------------------\n");

	img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt,
		pCodecCtx->width, pCodecCtx->height, PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);


	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {
		printf("Could not initialize SDL - %s\n", SDL_GetError());
		return ;
	}
	//SDL 2.0 Support for multiple windows
	screen_w = pCodecCtx->width;
	screen_h = pCodecCtx->height;
	screen = SDL_CreateWindow("Simplest ffmpeg player's Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
		screen_w, screen_h, SDL_WINDOW_OPENGL);

	if (!screen) {
		printf("SDL: could not create window - exiting:%s\n", SDL_GetError());
		return ;
	}
	sdlRenderer = SDL_CreateRenderer(screen, -1, 0);
	//IYUV: Y + U + V  (3 planes)
	//YV12: Y + V + U  (3 planes)
	sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, pCodecCtx->width, pCodecCtx->height);

	sdlRect.x = 0;
	sdlRect.y = 0;
	sdlRect.w = screen_w;
	sdlRect.h = screen_h;

	packet = (AVPacket *)av_malloc(sizeof(AVPacket));

	video_tid = SDL_CreateThread(sfp_refresh_thread, NULL, NULL);
	//------------SDL End------------
	//Event Loop

	for (;;) {
		//Wait
		SDL_WaitEvent(&event);
		if (event.type == SFM_REFRESH_EVENT){
			while (1){
				if (av_read_frame(pFormatCtx, packet)<0)
					thread_exit = 1;

				if (packet->stream_index == videoindex)
					break;


			}
			ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, packet);
			if (ret < 0){
				printf("Decode Error.\n");
				return ;
			}
			if (got_picture){
				sws_scale(img_convert_ctx, (const uint8_t* const*)pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameYUV->data, pFrameYUV->linesize);

#if OUTPUT_YUV420P
				y_size = pCodecCtx->width*pCodecCtx->height;
				fwrite(pFrameYUV->data[0], 1, y_size, pFile);    //Y 
				fwrite(pFrameYUV->data[1], 1, y_size / 4, pFile);  //U
				fwrite(pFrameYUV->data[2], 1, y_size / 4, pFile);  //V

#endif
				//SDL---------------------------
				SDL_UpdateTexture(sdlTexture, NULL, pFrameYUV->data[0], pFrameYUV->linesize[0]);
				SDL_RenderClear(sdlRenderer);
				//SDL_RenderCopy( sdlRenderer, sdlTexture, &sdlRect, &sdlRect );  
				SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
				SDL_RenderPresent(sdlRenderer);
				//SDL End-----------------------
			}
			av_free_packet(packet);
		}
		else if (event.type == SDL_KEYDOWN){
			//Pause
			if (event.key.keysym.sym == SDLK_SPACE)
				thread_pause = !thread_pause;
		}
		else if (event.type == SDL_QUIT){
			thread_exit = 1;
		}
		else if (event.type == SFM_BREAK_EVENT){
			break;
		}

	}

	sws_freeContext(img_convert_ctx);

	SDL_Quit();
	//--------------
	av_frame_free(&pFrameYUV);
	av_frame_free(&pFrame);
	avcodec_close(pCodecCtx);
	avformat_close_input(&pFormatCtx);
}
开发者ID:xichyw1314807xn,项目名称:FfmpegOk,代码行数:101,代码来源:VideoDecodcEncodc.cpp

示例5: SDL_PollEvent

void CSDL_Setup::Begin()
{	
	SDL_PollEvent(mainEvent);
	SDL_RenderClear(renderer);
}
开发者ID:CodeThat,项目名称:TankGame,代码行数:5,代码来源:SDL_Setup.cpp

示例6: main

int main(int argc, char **argv)
{
    int done = 0;
    SDL_Window *window;
    SDL_Renderer *renderer;

    /* !!! FIXME: check for errors. */
    SDL_Init(SDL_INIT_VIDEO);
    window = SDL_CreateWindow("Drag the red boxes", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE);
    renderer = SDL_CreateRenderer(window, -1, 0);

    if (SDL_SetWindowHitTest(window, hitTest, NULL) == -1) {
        SDL_Log("Enabling hit-testing failed!\n");
        SDL_Quit();
        return 1;
    }

    while (!done)
    {
        SDL_Event e;
        int nothing_to_do = 1;

        SDL_SetRenderDrawColor(renderer, 0, 0, 127, 255);
        SDL_RenderClear(renderer);
        SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
        SDL_RenderFillRects(renderer, areas, SDL_arraysize(drag_areas));
        SDL_RenderPresent(renderer);

        while (SDL_PollEvent(&e)) {
            nothing_to_do = 0;

            switch (e.type)
            {
                case SDL_MOUSEBUTTONDOWN:
                    SDL_Log("button down!\n");
                    break;

                case SDL_MOUSEBUTTONUP:
                    SDL_Log("button up!\n");
                    break;

                case SDL_WINDOWEVENT:
                    if (e.window.event == SDL_WINDOWEVENT_MOVED) {
                        SDL_Log("Window event moved to (%d, %d)!\n", (int) e.window.data1, (int) e.window.data2);
                    }
                    break;

                case SDL_KEYDOWN:
                    if (e.key.keysym.sym == SDLK_ESCAPE) {
                        done = 1;
                    } else if (e.key.keysym.sym == SDLK_x) {
                        if (!areas) {
                            areas = drag_areas;
                            numareas = SDL_arraysize(drag_areas);
                        } else {
                            areas = NULL;
                            numareas = 0;
                        }
                    }
                    break;

                case SDL_QUIT:
                    done = 1;
                    break;
            }
        }

        if (nothing_to_do) {
            SDL_Delay(50);
        }
    }

    SDL_Quit();
    return 0;
}
开发者ID:Evengard,项目名称:UniMod,代码行数:75,代码来源:testhittesting.c

示例7: state_in_game

game_status state_in_game(SDL_Renderer *renderer, game* p_game)
{
  bool done=false;

  game_status ret_code = QUIT;
  map *p_map = p_game->p_map;
  
  while (!done){
    //update display
    //clear
    SDL_SetRenderDrawColor(renderer, 0x0, 0x0, 0x0, 0xFF);
    SDL_RenderClear(renderer);

    //draw the map
    map_draw(p_map, renderer);

    //draw the chipset
    image_draw(p_map->p_chipset, renderer, 0, 0);
    
    //input
    SDL_Event event;
    while (SDL_PollEvent(&event)){

      if(event.type ==  SDL_QUIT){
	done=true;
	break;
      }

      const int cam_speed = 8;
    
    switch ( event.type )
      {
      case SDL_KEYDOWN:
	switch (event.key.keysym.sym)
	  {
	  case SDLK_q:
	    done=true;
	    break;
	  case SDLK_s:
	    map_save(p_map, p_game->map_save_path);
	    break;
	  case SDLK_LEFT:
	    p_map->o_camera.x -= cam_speed;
	    break;
	  case SDLK_RIGHT:
	    p_map->o_camera.x += cam_speed;
	    break;
	  case SDLK_UP:
	    p_map->o_camera.y -= cam_speed;
	    break;
	  case SDLK_DOWN:
	    p_map->o_camera.y += cam_speed;
	    break;
	  default:
	    break;
	  }
	break;
      case SDL_MOUSEBUTTONDOWN:
	map_tile_click(p_map,
		       event.button.x,
		       event.button.y,
		       event.button.button);	  
	break;
      case SDL_MOUSEMOTION:
	map_mouse_move(p_map,
		       renderer,
		       event.button.x,
		       event.button.y);
	break;	  
      case SDL_MOUSEWHEEL:
	if(event.button.x < 0)
	  p_map->o_camera.y--;
	else if(event.button.x > 0)
	  p_map->o_camera.y++;
	break;
      default:
	break;
      }
    }

    //render
    SDL_RenderPresent(renderer);
  }
    
  return ret_code;
}
开发者ID:odrevet,项目名称:GE2,代码行数:86,代码来源:main.c

示例8: SDL_Texture

std::shared_ptr<Texture> Generic::Load(std::vector<std::vector<int>> map, std::shared_ptr<Entity> ent, std::string path, unsigned width, unsigned height, float starting_point_x, float starting_point_y, int frame_width, int frame_height)
{
	if (!path.size())
	{
		Output_Handler::Error << "ERR Generic::Load : No path supplied\n";
		return nullptr;
	}
	if (!map.size() || !map[0].size())
	{
		Output_Handler::Error << "ERR Generic::Change : Given map has width/height equal to 0\n";
		return nullptr;
	}

	SDL_Texture* gt = nullptr;
	for (auto& ttr : Texture::__Textures) if (path == ttr->__Path && dynamic_cast<Generic*>(ttr.get()))
	{
		gt = dynamic_cast<Generic*>(ttr.get())->__Generic_Texture;
		break;
	}
	if (!gt) gt = IMG_LoadTexture(Screen::Renderer, path.c_str());
	if (!gt)
	{
		Output_Handler::Error << "ERR Texture::Load : No valid texture file supplied\n";
		return nullptr;
	}

	auto texture = SDL_CreateTexture
		(
		Screen::Renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET,
		frame_width * map[0].size(),
		frame_height * map.size()
		);
	if (!texture)
	{
		Output_Handler::Error << "ERR Texture::Load : Couldn't create SDL_Texture (probably size is too big)\n";
		SDL_DestroyTexture(gt);
		return nullptr;
	}

	Texture::__Textures.emplace_back(std::make_shared<Generic>());
	Texture::__Load(ent, Texture::__Textures.back(), frame_width * map[0].size(), frame_height * map.size(), starting_point_x, starting_point_y);
	std::shared_ptr<Generic> ts = std::static_pointer_cast<Generic>(Texture::__Textures.back());



	ts->__Generic_Texture = gt;
	ts->__Generic_Width = width;
	ts->__Generic_Height = height;
	ts->__Width = frame_width * map[0].size();
	ts->__Height = frame_height * map.size();
	ts->__SDL_Texture = texture;
	ts->__Tilemap = map;
	ts->__Path = path;

	if (frame_width == 0) ts->Frame_Width = width;
	else if (frame_width < 0) ts->Frame_Width = width / -frame_width;
	else ts->Frame_Width = frame_width;

	if (frame_height == 0) ts->Frame_Height = height;
	else if (frame_height < 0) ts->Frame_Height = height / -frame_height;
	else ts->Frame_Height = frame_height;

	if (ent) ent->texture = Texture::__Textures.back();


	SDL_SetTextureBlendMode(ts->__SDL_Texture, SDL_BLENDMODE_BLEND);
	SDL_SetRenderTarget(Screen::Renderer, ts->__SDL_Texture);


	SDL_Rect src = { 0,0, (int)frame_width, (int)frame_height };
	SDL_Rect dst = { 0,0, (int)frame_width, (int)frame_height };

	auto get_frame_pos = [&ts](int frame)->std::pair<int, int>
	{
		if (frame < 0) return std::pair<int, int>( frame, frame );
		std::pair<int, int> p;
		p.second = 0;
		p.first = frame * (int)ts->Frame_Width;
		while (p.first >= (int)ts->__Generic_Width)
		{
			p.first -= ts->__Generic_Width;
			p.second += ts->Frame_Height;
		}
		return p;
	};

	SDL_RenderClear(Screen::Renderer);
	for (unsigned i = 0; i < map.size(); i++)
	{
		for (unsigned j = 0; j < map[i].size(); j++)
		{
			if (map[i][j] < (int)ts->Tiles_Count())
			{
				auto frame_pos = get_frame_pos(map[i][j]);
				src.x = frame_pos.first;
				src.y = frame_pos.second;
			}
			else
			{
				Output_Handler::Output << "MSG Generic::Change : Tile " << map[i][j] << " doesn't exist (max " << ts->Tiles_Count() - 1 << "); no tile is drawn\n";
//.........这里部分代码省略.........
开发者ID:Xemar5,项目名称:Hardy-Part,代码行数:101,代码来源:Generic.cpp

示例9: debugInfo

void StateHandler::Game()
{
    bool quit = false;
    bool quitToOs = false;

    double deltaTime = 0.0;

    GameTimer gameTimer;

    DebugInfo debugInfo(myRenderer);

    Enemy a(myRenderer, eEnemyType::Mollusk);
    Entity b(myRenderer);

    a.SetPosition(450, 450);
    b.SetPosition(500, 500);

    SDL_Event eventQueue;

    while (quit == false)
    {
        gameTimer.Update();
        deltaTime = gameTimer.GetDeltaTime();
        debugInfo.Update(gameTimer);

        while(SDL_PollEvent(&eventQueue) != 0)
        {
            if(eventQueue.type == SDL_QUIT)
            {
                quitToOs = true;
                quit = true;
            }
            else if (eventQueue.type == SDL_KEYDOWN)
            {
                switch(eventQueue.key.keysym.sym)
                {
                    case SDLK_ESCAPE:
                        quitToOs = true;
                        quit = true;
                        break;

                    case SDLK_F10:
                        debugInfo.ToggleShow();
                        break;
                }
            }
        }

        SDL_SetRenderDrawColor(myRenderer, 0x00, 0x00, 0x00, 0xFF);
        SDL_RenderClear(myRenderer);

        a.Update(deltaTime);
        //b.Update(deltaTime);

        b.Render();
        a.Render();

        debugInfo.Render();

        SDL_RenderPresent(myRenderer);
    }

    if(quitToOs == true)
    {
        SetState(eGameStates::Quit);
    }
    else
    {
        SetState(eGameStates::MainMenu);
    }
}
开发者ID:droolgamestudio,项目名称:metvan,代码行数:71,代码来源:StateHandlerClass.cpp

示例10: cairo_surface_flush


//.........这里部分代码省略.........
							_Render_for_scaling_uniform_or_letterbox(osd);
						} break;
						
						case std::experimental::io2d::scaling::fill_uniform:
						{
							// Maintain aspect ratio and center, but overflow if needed rather than letterboxing.
							if (backBufferWidth == displayWidth && backBufferHeight == displayHeight) {
								cairo_set_source_surface(displayContext, backBufferSfc, 0.0, 0.0);
								cairo_paint(displayContext);
							}
							else {
								auto widthRatio = displayWidth / backBufferWidth;
								auto heightRatio = displayHeight / backBufferHeight;
								if (widthRatio < heightRatio) {
									cairo_set_source_rgb(displayContext, 0.0, 0.0, 0.0);
									cairo_paint(displayContext);
									cairo_matrix_t ctm;
									cairo_matrix_init_scale(&ctm, 1.0 / heightRatio, 1.0 / heightRatio);
									cairo_matrix_translate(&ctm, trunc(abs((displayWidth - (backBufferWidth * heightRatio)) / 2.0)), 0.0);
									unique_ptr<cairo_pattern_t, decltype(&cairo_pattern_destroy)> pat(cairo_pattern_create_for_surface(backBufferSfc), &cairo_pattern_destroy);
									auto patPtr = pat.get();
									cairo_pattern_set_matrix(patPtr, &ctm);
									cairo_pattern_set_extend(patPtr, CAIRO_EXTEND_NONE);
									cairo_pattern_set_filter(patPtr, cairoFilter);
									cairo_set_source(displayContext, patPtr);
									cairo_paint(displayContext);
								}
								else {
									cairo_set_source_rgb(displayContext, 0.0, 0.0, 0.0);
									cairo_paint(displayContext);
									cairo_matrix_t ctm;
									cairo_matrix_init_scale(&ctm, 1.0 / widthRatio, 1.0 / widthRatio);
									cairo_matrix_translate(&ctm, 0.0, trunc(abs((displayHeight - (backBufferHeight * widthRatio)) / 2.0)));
									unique_ptr<cairo_pattern_t, decltype(&cairo_pattern_destroy)> pat(cairo_pattern_create_for_surface(backBufferSfc), &cairo_pattern_destroy);
									auto patPtr = pat.get();
									cairo_pattern_set_matrix(patPtr, &ctm);
									cairo_pattern_set_extend(patPtr, CAIRO_EXTEND_NONE);
									cairo_pattern_set_filter(patPtr, cairoFilter);
									cairo_set_source(displayContext, patPtr);
									cairo_paint(displayContext);
								}
							}
						} break;
						case std::experimental::io2d::scaling::fill_exact:
						{
							// Maintain aspect ratio and center, but overflow if needed rather than letterboxing.
							if (backBufferWidth == displayWidth && backBufferHeight == displayHeight) {
								cairo_set_source_surface(displayContext, backBufferSfc, 0.0, 0.0);
								cairo_paint(displayContext);
							}
							else {
								auto widthRatio = displayWidth / backBufferWidth;
								auto heightRatio = displayHeight / backBufferHeight;
								cairo_matrix_t ctm;
								cairo_matrix_init_scale(&ctm, 1.0 / widthRatio, 1.0 / heightRatio);
								unique_ptr<cairo_pattern_t, decltype(&cairo_pattern_destroy)> pat(cairo_pattern_create_for_surface(backBufferSfc), &cairo_pattern_destroy);
								auto patPtr = pat.get();
								cairo_pattern_set_matrix(patPtr, &ctm);
								cairo_pattern_set_extend(patPtr, CAIRO_EXTEND_NONE);
								cairo_pattern_set_filter(patPtr, cairoFilter);
								cairo_set_source(displayContext, patPtr);
								cairo_paint(displayContext);
							}
						} break;
						case std::experimental::io2d::scaling::none:
						{
							cairo_set_source_surface(displayContext, backBufferSfc, 0.0, 0.0);
							cairo_paint(displayContext);
						} break;
						default:
						{
							assert("Unexpected _Scaling value." && false);
						} break;
					}
				}
				
				//     cairo_restore(_Native_context.get());
				// This call to cairo_surface_flush is needed for Win32 surfaces to update.
				cairo_surface_flush(displaySfc);
				cairo_set_source_rgb(displayContext, 0.0, 0.0, 0.0);

				SDL_SetRenderDrawColor(data.renderer, 0, 0, 0, 255);
				if (SDL_RenderClear(data.renderer) != 0) {
					throw ::std::system_error(::std::make_error_code(::std::errc::io_error), SDL_GetError());
				}

				// Copy Cairo canvas to SDL2 texture
				unsigned char * src = cairo_image_surface_get_data(displaySfc);
				// TODO([email protected]): compute the pitch, given  
				const int pitch = (int)backBufferWidth * 4;    // '4' == 4 bytes per pixel
				if (SDL_UpdateTexture(data.texture, nullptr, src, pitch) != 0) {
					throw ::std::system_error(::std::make_error_code(::std::errc::io_error), SDL_GetError());
				}
				if (SDL_RenderCopy(data.renderer, data.texture, nullptr, nullptr) != 0) {
					throw ::std::system_error(::std::make_error_code(::std::errc::io_error), SDL_GetError());
				}

				// Present latest image
				SDL_RenderPresent(data.renderer);
			}
开发者ID:mikebmcl,项目名称:N3888_RefImpl,代码行数:101,代码来源:cairo_renderer_sdl2.cpp

示例11: _tmain


//.........这里部分代码省略.........
	if(avcodec_open2(pCodecCtx, pCodec,NULL)<0)
	{
		printf("Could not open codec.(无法打开解码器)\n");
		return -1;
	}
	AVFrame	*pFrame,*pFrameYUV;
	pFrame=avcodec_alloc_frame();
	pFrameYUV=avcodec_alloc_frame();
	uint8_t *out_buffer=(uint8_t *)av_malloc(avpicture_get_size(PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height));
	avpicture_fill((AVPicture *)pFrameYUV, out_buffer, PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);
//------------SDL----------------
	if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {  
		printf( "Could not initialize SDL - %s\n", SDL_GetError()); 
		return -1;
	} 

	int screen_w=0,screen_h=0;
	SDL_Window *screen; 
	//SDL 2.0 Support for multiple windows
	screen_w = pCodecCtx->width;
	screen_h = pCodecCtx->height;
	screen = SDL_CreateWindow("Simplest ffmpeg player's Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
		screen_w, screen_h,
		SDL_WINDOW_OPENGL);

	if(!screen) {  
		printf("SDL: could not create window - exiting:%s\n",SDL_GetError());  
		return -1;
	}


	SDL_Renderer* sdlRenderer = SDL_CreateRenderer(screen, -1, 0);  
	//IYUV: Y + U + V  (3 planes)
	//YV12: Y + V + U  (3 planes)
	SDL_Texture* sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING,pCodecCtx->width,pCodecCtx->height);  

	SDL_Rect sdlRect;  
	sdlRect.x = 0;  
	sdlRect.y = 0;  
	sdlRect.w = screen_w;  
	sdlRect.h = screen_h;  

	int ret, got_picture;

	AVPacket *packet=(AVPacket *)av_malloc(sizeof(AVPacket));
	//Output Info-----------------------------
	printf("File Information(文件信息)---------------------\n");
	av_dump_format(pFormatCtx,0,filepath,0);
	printf("-------------------------------------------------\n");
	
	struct SwsContext *img_convert_ctx;
	img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL); 
	//--------------
	SDL_Thread *video_tid = SDL_CreateThread(sfp_refresh_thread,NULL,NULL);
	//
	//Event Loop
	SDL_Event event;
	for (;;) {
		//Wait
		SDL_WaitEvent(&event);
		if(event.type==SFM_REFRESH_EVENT){
			//------------------------------
			if(av_read_frame(pFormatCtx, packet)>=0){
				if(packet->stream_index==videoindex){
					ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, packet);
					if(ret < 0){
						printf("Decode Error.(解码错误)\n");
						return -1;
					}
					if(got_picture){
						sws_scale(img_convert_ctx, (const uint8_t* const*)pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameYUV->data, pFrameYUV->linesize);
						//SDL---------------------------
						SDL_UpdateTexture( sdlTexture, &sdlRect, pFrameYUV->data[0], pFrameYUV->linesize[0] );  
						SDL_RenderClear( sdlRenderer );  
						SDL_RenderCopy( sdlRenderer, sdlTexture, &sdlRect, &sdlRect );  
						SDL_RenderPresent( sdlRenderer );  
						//SDL End-----------------------
					}
				}
				av_free_packet(packet);
			}else{
				//Exit Thread
				thread_exit=1;
				break;
			}
		}

	}

	sws_freeContext(img_convert_ctx);

	SDL_Quit();
	//--------------
	av_free(out_buffer);
	av_free(pFrameYUV);
	avcodec_close(pCodecCtx);
	avformat_close_input(&pFormatCtx);

	return 0;
}
开发者ID:82488059,项目名称:GitProject,代码行数:101,代码来源:simplest_ffmpeg_player_su.cpp

示例12: main

int main( int argc, char* args[] )
{
	//Start up SDL and create window
	if( !init() )
	{
		printf( "Failed to initialize!\n" );
	}
	else
	{
		//The level tiles
		Tile* tileSet[ TOTAL_TILES ];

		//Load media
		if( !loadMedia( tileSet ) )
		{
			printf( "Failed to load media!\n" );
		}
		else
		{	
			//Main loop flag
			bool quit = false;

			//Event handler
			SDL_Event e;

			//The dot that will be moving around on the screen
			Dot dot;

			//Level camera
			SDL_Rect camera = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT };

			//While application is running
			while( !quit )
			{
				//Handle events on queue
				while( SDL_PollEvent( &e ) != 0 )
				{
					//User requests quit
					if( e.type == SDL_QUIT )
					{
						quit = true;
					}

					//Handle input for the dot
					dot.handleEvent( e );
				}

				//Move the dot
				dot.move( tileSet );
				dot.setCamera( camera );

				//Clear screen
				SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
				SDL_RenderClear( gRenderer );

				//Render level
				for( int i = 0; i < TOTAL_TILES; ++i )
				{
					tileSet[ i ]->render( camera );
				}

				//Render dot
				dot.render( camera );

				//Update screen
				SDL_RenderPresent( gRenderer );
			}
		}
		
		//Free resources and close SDL
		close( tileSet );
	}

	return 0;
}
开发者ID:Stephen-Lamb,项目名称:Work,代码行数:75,代码来源:39_tiling.cpp

示例13: main

int main(int, char**){
	//Start up SDL and make sure it went ok
	if (SDL_Init(SDL_INIT_VIDEO) != 0){
		logSDLError(std::cout, "SDL_Init");
		return 1;
	}

	//Setup our window and renderer
	SDL_Window *window = SDL_CreateWindow("Lesson 5", SDL_WINDOWPOS_CENTERED,
			SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
	if (window == nullptr){
		logSDLError(std::cout, "CreateWindow");
		SDL_Quit();
		return 1;
	}
	SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
	if (renderer == nullptr){
		logSDLError(std::cout, "CreateRenderer");
		cleanup(window);
		SDL_Quit();
		return 1;
	}
	const std::string resPath = getResourcePath("Lesson5");
	SDL_Texture *image = loadTexture(resPath + "image.png", renderer);
	if (image == nullptr){
		cleanup(image, renderer, window);
		IMG_Quit();
		SDL_Quit();
		return 1;
	}

	//iW and iH are the clip width and height
	//We'll be drawing only clips so get a center position for the w/h of a clip
	int iW = 100, iH = 100;
	int x = SCREEN_WIDTH / 2 - iW / 2;
	int y = SCREEN_HEIGHT / 2 - iH / 2;

	//Setup the clips for our image
	SDL_Rect clips[4];
	//Since our clips our uniform in size we can generate a list of their
	//positions using some math (the specifics of this are covered in the lesson)
	for (int i = 0; i < 4; ++i){
		clips[i].x = i / 2 * iW;
		clips[i].y = i % 2 * iH;
		clips[i].w = iW;
		clips[i].h = iH;
	}
	//Specify a default clip to start with
	int useClip = 0;

	SDL_Event e;
	bool quit = false;
	while (!quit){
		//Event Polling
		while (SDL_PollEvent(&e)){
			if (e.type == SDL_QUIT){
				quit = true;
			}
			//Use number input to select which clip should be drawn
			if (e.type == SDL_KEYDOWN){
				switch (e.key.keysym.sym){
					case SDLK_1:
						useClip = 0;
						break;
					case SDLK_2:
						useClip = 1;
						break;
					case SDLK_3:
						useClip = 2;
						break;
					case SDLK_4:
						useClip = 3;
						break;
					case SDLK_ESCAPE:
						quit = true;
						break;
					default:
						break;
				}
			}
		}
		//Rendering
		SDL_RenderClear(renderer);
		//Draw the image
		renderTexture(image, renderer, x, y, &clips[useClip]);
		//Update the screen
		SDL_RenderPresent(renderer);
	}
	//Clean up
	cleanup(image, renderer, window);
	IMG_Quit();
	SDL_Quit();

	return 0;
}
开发者ID:alexhod,项目名称:TwinklebearDev-Lessons,代码行数:95,代码来源:main.cpp

示例14: SDL_SetRenderDrawColor

/******************************************************************************
 * Display BackBuffer Flipping
******************************************************************************/
void display::flip() {
    SDL_SetRenderDrawColor(pRenderer, 0, 0, 0, 255);
    SDL_RenderPresent(pRenderer);
    SDL_RenderClear(pRenderer);
}
开发者ID:Night-Owl-Studios,项目名称:Giant-Slayers,代码行数:8,代码来源:display.cpp

示例15: SDL_RenderClear

void Game::Draw() {
	SDL_RenderClear(m_pRenderer);

	switch (StateManager::stateMachine->getCurrentGameStates()) {
	case MENU:


		m_StartGameMenu.backGroundMenu.Draw(m_pRenderer);
		//		buttonsMenu.Draw(m_pRenderer);
		for (int iter = 0; iter < 5; iter++)
			m_StartGameMenu.m_buttonSet[iter].Draw(m_pRenderer);
//		txt.Draw(m_pRenderer);
//		level.Draw(m_pRenderer);
		break;

	case STARTGAME:

		texture.Draw(m_pRenderer);
//			for (int iter = 0; iter < 14; iter++)
//					m_cardSet[iter].Draw(m_pRenderer);
		m_cardLogic.Draw(m_pRenderer);
		m_Play.Draw(m_pRenderer);
		m_Bet.Draw(m_pRenderer);
		m_WIN.Draw(m_pRenderer);
		m_Credits.Draw(m_pRenderer);
		m_Menu.Draw(m_pRenderer);  //BUTTON MENU
		txt.Draw(m_pRenderer);
		break;

	case RULES_OF_GAMES:
		m_StartGameMenu.backGroundForTeam.DrawRules(m_pRenderer);
		break;

	case TEAM_PROJECT:
		m_StartGameMenu.backGroundForTeam.DrawTeam(m_pRenderer);
		break;

	case GAMEOVER:

		texture.Draw(m_pRenderer);
		m_Play.Draw(m_pRenderer);
		m_Bet.Draw(m_pRenderer);
		m_WIN.Draw(m_pRenderer);
		m_Credits.Draw(m_pRenderer);
		m_Menu.Draw(m_pRenderer);  //BUTTON MENU
		break;

	case VIEW_CARDS:
		if (m_Play.isIsClicked()) {
			m_cardLogic.GetCardFromDeck();
			m_cardLogic.m_TwoCard.clear();
			m_Play.setIsClicked(false);
		}

		texture.Draw(m_pRenderer);
		m_Play.Draw(m_pRenderer);
		m_Bet.Draw(m_pRenderer);
		m_WIN.Draw(m_pRenderer);
		m_Credits.Draw(m_pRenderer);
		m_Menu.Draw(m_pRenderer);  //BUTTON MENU
		m_cardLogic.Draw(m_pRenderer);
		txt.Draw(m_pRenderer);

		break;

	}

	SDL_RenderPresent(m_pRenderer);
}/*end of Draw*/
开发者ID:jordanmitarov,项目名称:Memory-Game,代码行数:69,代码来源:Game.cpp


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