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


C++ SDL_SetRenderDrawColor函数代码示例

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


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

示例1: main

int main(int argc, char **argv)
{

    if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        fprintf(stderr, "Failed to initialize SDL: %s\n", SDL_GetError());
        return 1;
    }
    if (TTF_Init() != 0) {
        fprintf(stderr, "Failed to initialize TTF: %s\n", SDL_GetError());
        return 1;
    }
    if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096)) {
        fprintf(stderr, "Failed to load Mixer: %s", SDL_GetError());
    }
    int imgFlags = IMG_INIT_JPG|IMG_INIT_PNG;
    if(!(IMG_Init(imgFlags) & imgFlags)) {
        fprintf(stderr,"Failed to initialize Image: %s",SDL_GetError());
    }

    screen = SDL_CreateWindow(WINDOW_TITLE,
                              SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
                              WINDOW_WIDTH, WINDOW_HEIGHT,
                              SDL_WINDOW_BORDERLESS);
    if (screen == NULL) {
        fprintf(stderr, "Failed to create window: %s\n", SDL_GetError());
        return 1;
    }

    renderer = SDL_CreateRenderer(screen, -1, 0);
    if (renderer == NULL) {
        fprintf(stderr, "Failed to create renderer: %s\n", SDL_GetError());
        return 1;
    }

    char* path = buildPath(ASSETS,"fonts/FONT.TTF");
    font = TTF_OpenFont(path, 12);
    if (font == NULL) {
        fprintf(stderr, "Failed to load font: %s\n",TTF_GetError());
        return 1;
    }
    free(path);

    Mix_Music* music = loadMusic(buildPath(ASSETS,"music/song.mp3"));
    playMusic(music);

    // Black backround
    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);

    game_init();

    if (buffers_init(renderer) != 0) {
        fprintf(stderr, "Failed to craete buffers: %s", SDL_GetError());
        return 1;
    }

    curr_buffer = buffer;
    SDL_Event e;
    SDL_Rect render_rect;
    render_rect.x = 0;
    render_rect.y = 0;
    render_rect.w = WINDOW_WIDTH;
    render_rect.h = WINDOW_HEIGHT;
    bool quit = false;
    int deltaTime = 0;
    int currentFrame = SDL_GetTicks();
    int lastFrame;
    int fpsMs = 1000 / MAX_FPS;

    map_tex = renderMap(renderer, map);

    camera.x = 0;
    camera.y = 0;
    camera.w = WINDOW_WIDTH;
    camera.h = WINDOW_HEIGHT;

    while (!quit) {
        lastFrame = currentFrame;
        currentFrame = SDL_GetTicks();
        deltaTime = currentFrame - lastFrame;
        renderClear(renderer);

        update(deltaTime);
        draw(deltaTime);

        while (SDL_PollEvent(&e)) {
            if (e.type == SDL_QUIT)
                quit = true;
            else
                event(e, deltaTime);
        }

        // Reset the target
        SDL_SetRenderTarget(renderer, NULL);
        // Copy the buffer
        SDL_RenderCopy(renderer, curr_buffer, &camera, &render_rect);
        // Draw the buffer to window
        SDL_RenderPresent(renderer);

        // Delay if we are drawing more that 100 fps
        float delay = fpsMs - deltaTime / 1000;
//.........这里部分代码省略.........
开发者ID:chinaboyli123,项目名称:game,代码行数:101,代码来源:main.c

示例2: 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

示例3: 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

示例4: SDL_SetRenderDrawColor

bool Render::postUpdate()
{
	SDL_SetRenderDrawColor(renderer, background.r, background.g, background.g, background.a);
	SDL_RenderPresent(renderer);
	return true;
}
开发者ID:crandino,项目名称:Element_fury,代码行数:6,代码来源:Render.cpp

示例5: printf

bool World::InitScreen()
{
     bool run = true;
     if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
        {
            printf("Fail initialize : %s\n",SDL_GetError());
            run = false;
        }
        else
        {
            printf("Initialization Success!\n");

            if(!SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1"))
            {
                printf("Warning: VSync not enabled!\n");
                run = false;
            }

            m_window = SDL_CreateWindow(TITLE,SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,g_WINDOW_WIDTH,g_WINDOW_HEIGHT,SDL_WINDOW_SHOWN);

            if(m_window == NULL)
            {
                printf("ERROR creting Window : %s\n",SDL_GetError());
                run = false;
            }
            else
            {
                printf("Created Window .\n");

                m_render = SDL_CreateRenderer(m_window,-1,SDL_RENDERER_ACCELERATED);

                if(m_render == NULL)
                {
                    printf("Failed creating Render : %s\n",SDL_GetError());
                    run = false;
                }
                else
                {
                    printf("Creted Render.\n");
                    SDL_SetRenderDrawColor( m_render, 0xFF, 0xFF, 0xFF, 0xFF );

                    int picFlag = IMG_INIT_PNG;
                    if(!(IMG_Init(picFlag))& picFlag)
                    {
                        printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
                        run = false;
                    }
                    else
                    {
                        if(!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"))
                        {
                            printf("Warning: Scale Quality not enabled!\n");
                            run = false;
                        }
                        else
                        {
                            m_Stick1 = SDL_JoystickOpen(0);
                            if(m_Stick1 == NULL)
                            {
                                printf("Warning: 1st Joystick FAIL\n");
                            }
                            m_Stick2 = SDL_JoystickOpen(1);
                            if(m_Stick2 == NULL)
                            {
                                printf("Warning: 2nd Joystick FAIL\n");
                            }
                                if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 4, 4048 ) < 0 )
                            {
                                printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
                            }
                        }
                    }

                }
            }
        }
        m_main_music= new Sound();
        m_main_music->Init("data/music.txt");
        m_main_music->Play(true);
        SDL_JoystickEventState(SDL_ENABLE);
        return run;
}
开发者ID:nbu-gamedev,项目名称:spacewar-2014,代码行数:82,代码来源:World.cpp

示例6: clr

void clr(SDL_Renderer* destination, const SDL_Color& col) {
    SDL_SetRenderDrawColor(destination, col.r, col.g, col.b, col.a);
    SDL_RenderClear(destination);
}
开发者ID:cherosene,项目名称:learning_algorithms,代码行数:4,代码来源:sdlUtility.cpp

示例7: renderRect

void renderRect( SDL_Rect& rect, const SDL_Color& col, SDL_Renderer* destination, bool filled) {
    SDL_SetRenderDrawColor(destination, col.r, col.g, col.b, col.a);
    if(filled) {    SDL_RenderFillRect(destination, &rect); }
    else {          SDL_RenderDrawRect(destination, &rect); }
}
开发者ID:cherosene,项目名称:learning_algorithms,代码行数:5,代码来源:sdlUtility.cpp

示例8: SDL_GetRenderTarget

bool Button::draw(SDL_Renderer* renderer) {

    /*if(label->isDirty()) {
        label->draw();
    }*/
    SDL_Texture *oldTarget = SDL_GetRenderTarget(renderer);
    SDL_SetRenderTarget(renderer, _texture);
    SDL_SetRenderDrawColor(renderer, 0,0,0,0);
    SDL_RenderClear(renderer);
    SDL_SetRenderDrawColor(renderer, 0,0,0,255);
    SDL_Rect extents = {0, 0, frame.w, frame.h};
    _theme->draw(renderer, &extents);
    SDL_Rect contentRect;
    getContentRect(&contentRect);
    //printf("Content rect: %dx%d%+d%+d\n", contentRect.w, contentRect.h, contentRect.x, contentRect.y);
    //contentRect.x = padding.x;
    //contentRect.y = padding.y;
    //contentRect.w += padding.x + padding.w;
    //contentRect.h += padding.y + padding.h;
    //-- SDL_RenderCopy(renderer, label->getTexture(), NULL, &contentRect);
    /*printf("contentRect.w: %d\n", contentRect.w);
    int w;
    SDL_QueryTexture(label->getTexture(), NULL, NULL, &w, NULL);
    printf("label with: %d\n", w);*/
#if 0
    SDL_Point srcPoints[] = {
        {0, 0},
        {padding.x, padding.y},
        {w - padding.w, h - padding.h},
        {w, h}
    };
    SDL_Point dstPoints[] = {
        {frame->x, frame->y},
        {frame->x + padding.x, frame->y + padding.y},
        {frame->x + frame->w - padding.w, frame->y + frame->h - padding.h},
        {frame->x + frame->w, frame->y + frame->h}
    };
    for (int y = 0; y < 3; y++ ) {
        for (int x = 0; x < 3; x++) {
            SDL_Rect src = {
                srcPoints[x].x,
                srcPoints[y].y,
                srcPoints[x+1].x,
                srcPoints[y+1].y
            };
            src.w -= src.x;
            src.h -= src.y;

            SDL_Rect dst = {
                dstPoints[x].x,
                dstPoints[y].y,
                dstPoints[x+1].x,
                dstPoints[y+1].y
            };
            dst.w -= dst.x;
            dst.h -= dst.y;
            //printf("%d,%d\n", x, y);
            //printf("src: %dx%d%+d%+d\n", src.w, src.h, src.x, src.y);
            //printf("dst: %dx%d%+d%+d\n\n", dst.w, dst.h, dst.x, dst.y);
            /*printf("src: %d+%d+%dx%d dst: %d+%d+%dx%d\n",
                src.x, src.y, src.w, src.h,
                dst.x, dst.y, dst.w, dst.h);*/
            SDL_RenderCopy(texture, &src, &dst);
            //SDL_SetRenderDrawColor(renderer, 32+x*32, 32+y*32, 0, 127);
            //SDL_RenderFillRect(renderer, &dst);
        }
    }
#endif
    dirty = false;
    SDL_SetRenderTarget(renderer, oldTarget);
    return true;
}
开发者ID:jvaemape,项目名称:SDL2Gui,代码行数:72,代码来源:Button.cpp

示例9: SDL_SetRenderDrawColor

update_status ModuleRender::PostUpdate()
{
	SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
	SDL_RenderPresent(renderer);
	return update_status::UPDATE_CONTINUE;
}
开发者ID:Trodek,项目名称:Pokemon-Stay,代码行数:6,代码来源:ModuleRender.cpp

示例10: main

int main( int argc, char** argv )
{
  // Create the hidden program options (required args)
  boost::program_options::options_description hidden( "Hidden options" );
  hidden.add_options()
    ("image",
     boost::program_options::value<std::string>(),
     "the image (with path) that will be used\n");
    
  // Create the positional (required) args
  boost::program_options::positional_options_description pd;
  pd.add("image", 1 );
  
  // Create the optional arguments
  boost::program_options::options_description generic( "Allowed options" );
  generic.add_options()
    ("help,h", "produce help message")
    ("color_key_red,r",
     boost::program_options::value<unsigned>(),
     "the color key red value (0-255)\n")
    ("color_key_green,g",
     boost::program_options::value<unsigned>(),
     "the color key green value (0-255)\n")
    ("color_key_blue,b",
     boost::program_options::value<unsigned>(),
     "the color key blue value (0-255)\n");

  // Create the command-line argument parser
  boost::program_options::options_description
    cmdline_options( "Allowed options" );
  cmdline_options.add(generic).add(hidden);

  boost::program_options::variables_map vm;
  boost::program_options::store( boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(pd).run(), vm );
  boost::program_options::notify( vm );

  // Check if the help message was requested
  if( vm.count( "help" ) )
  {
    std::cerr << cmdline_options << std::endl;
    
    return 1;
  }

  // Store the image name
  std::string image_name;

  if( vm.count( "image" ) )
    image_name = vm["image"].as<std::string>();
  else
  {
    std::cerr << "The image (with path) must be specified."
	      << std::endl;

    return 1;
  }

  // Store the color key rgb values
  unsigned char color_key_r = 255, color_key_g = 255, color_key_b = 255;

  if( vm.count( "color_key_red" ) )
    color_key_r = vm["color_key_red"].as<unsigned>();

  if( vm.count( "color_key_green" ) )
    color_key_g = vm["color_key_green"].as<unsigned>();

  if( vm.count( "color_key_blue" ) )
    color_key_b = vm["color_key_blue"].as<unsigned>();
  
  // Initialize the window
  if( !initialize() )
    return 1;
  else
  {
    // Load the bitmap
    if( !loadMedia( image_name, color_key_r, color_key_g, color_key_b ) )
      return 1;
    else
    {
      bool quit = false;

      // The event
      SDL_Event event;

      // The current animation frame
      int frame = 0;
      
      // Main application loop
      while( !quit )
      {
	while( SDL_PollEvent( &event ) != 0 )
	{
	  if( event.type == SDL_QUIT )
	    quit = true;
	}

	// Clear the screen
	SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
	
	SDL_RenderClear( g_renderer );
//.........这里部分代码省略.........
开发者ID:aprobinson,项目名称:GDev,代码行数:101,代码来源:sdl_test_14_sean.cpp

示例11: main


//.........这里部分代码省略.........
   renderer = SDL_CreateRenderer(window, -1, config.renderflags);

   hsprite  = loadPic("img/predator.gif");
   psprite  = loadPic("img/prey.gif");
   black    = loadPic("img/black.gif");

   /*
    * Initialize maze, and send player name.
    */
   MAZE.X = (config.win_width - MAZE.w * 16) / 2;
   MAZE.Y = (config.win_height - MAZE.h * 16) / 2;

   SDLNet_TCP_Send(srv_sock, myname, PNAME_SIZE);


   /*
    * Initialize maze and get the LOCAL player, then the REMOTE players.
    */

   SDLNet_TCP_Recv(srv_sock, &myno, 1);
   player = calloc(1, sizeof(PLAYER));

   if (!((magic = getshort(srv_sock)) == ADD_PLAYER))
   {
      printf("server not sending players\n!");
      exit(EXIT_FAILURE);
   }

   unsigned char hunter = addp(player, srv_sock);

   choose_hunter(player, hunter);
   me = choose_player(player, myno);

   SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
   draw_maze(MAZE.X, MAZE.Y);

   PLAYER *temp;

   for (temp = player->next; temp != NULL; temp = temp->next)
   {
      printf("drew player %d\n", temp->playerno);
      drawPlayer(temp);
   }
   
   printf("starting game!!\n");
   /*
    * Game loop!
    */
   
   for (;;)
   {
      time = SDL_GetTicks();

      /*
       * Poll the  network in each frame. Because.
       */

      int result, numready = SDLNet_CheckSockets(srv_sset, 0);

      if (numready == -1)
      {
         printf("SDLNet_CheckSockets: %s\n", SDLNet_GetError());
         perror("SDLNet_CheckSockets");
      }
      else if (numready)
      {
开发者ID:pcoutin,项目名称:mazeoftorment,代码行数:67,代码来源:main.c

示例12: initialize

//! initialize sdl window
bool initialize()
{
  // Initialization flag
  bool success = true;

  // Initialize SDL
  if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
  {
    std::cerr << "SDL could not initialize. SDL_Error: "
	      << SDL_GetError()
	      << std::endl;
    success = false;
  }
  else
  {
    // Set texture filtering to linear
    if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
    {
      std::cerr << "Warning: Linear texture filtering not enabled!" 
		<< std::endl;
    }
    
    // Create window
    g_window = SDL_CreateWindow( "SDL Tutorial",
				 SDL_WINDOWPOS_UNDEFINED,
				 SDL_WINDOWPOS_UNDEFINED,
				 screen_width_height[0],
				 screen_width_height[1],
				 SDL_WINDOW_SHOWN );
    if( g_window == NULL )
    {
      std::cerr << "Window could not be created. SDL_Error: "
		<< SDL_GetError()
		<< std::endl;
      success = false;
    }
     else
    {
      // Create the renderer for the window
      g_renderer = SDL_CreateRenderer( 
			g_window, 
			-1, 
			SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
      
      if( g_renderer == NULL )
      {
	std::cerr << "Renderer could not be created! SDL_Error: "
		  << SDL_GetError()
		  << std::endl;
	success = false;
      }
      else
      {
	// Initialize renderer color
	SDL_SetRenderDrawColor( g_renderer, 0xFF, 0xFF, 0xFF, 0xFF );

	// Initialize PNG loading
	int img_flags = IMG_INIT_PNG;

	if( !( IMG_Init( img_flags ) & img_flags ) )
	{
	  std::cerr << "SDL_image extension could not initialize! "
		    << "SDL_image Error: " << IMG_GetError()
		    << std::endl;
	  success = false;
	}
      }
    }
  }
  
  return success;
}
开发者ID:aprobinson,项目名称:GDev,代码行数:73,代码来源:sdl_test_14_sean.cpp

示例13: stat

// load the surface from a .pbm or bitmap file
bool NXSurface::LoadImage(const char *pbm_name, bool use_colorkey, int use_display_format)
{
	stat("NXSurface::LoadImage name = %s, this = %p", pbm_name, this);
	SDL_Surface *image;

	Free();
	
	// if (use_display_format == -1)
	// {	// use value specified in settings
	// 	use_display_format = settings->displayformat;
	// }
	
	image = SDL_LoadBMP_RW(SDL_RWFromFP(fileopenRO(pbm_name), SDL_TRUE), 1);
	if (!image)
	{
		staterr("NXSurface::LoadImage: load failed of '%s'!", pbm_name);
		return 1;
	}
	
	if (use_colorkey)
	{
		SDL_SetColorKey(image, SDL_TRUE, SDL_MapRGB(image->format, 0, 0, 0));
	}

	SDL_Texture * tmptex = SDL_CreateTextureFromSurface(renderer, image);
	if (!tmptex)
	{
		staterr("NXSurface::LoadImage: SDL_CreateTextureFromSurface failed: %s", SDL_GetError());
		SDL_FreeSurface(image);
		return 1;
	}

	SDL_FreeSurface(image);

	{
		int wd, ht, access;
		Uint32 format;
		NXFormat nxformat;
		if (SDL_QueryTexture(tmptex, &format, &access, &wd, &ht)) goto error;
		nxformat.format = format;
		if (AllocNew(wd, ht, &nxformat)) goto error;
		if (SDL_SetTextureBlendMode(tmptex, SDL_BLENDMODE_MOD))	goto error;
		if (SDL_SetRenderTarget(renderer, fTexture)) goto error;
		if (SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255)) goto error;
		if (SDL_RenderClear(renderer)) goto error;
		if (SDL_RenderCopy(renderer, tmptex, NULL, NULL)) goto error;
		if (SDL_SetRenderTarget(renderer, NULL)) goto error;
		if (SDL_SetTextureBlendMode(fTexture, SDL_BLENDMODE_BLEND)) goto error;

		SDL_DestroyTexture(tmptex);

		goto done;
error:
		{
			staterr("NXSurface::LoadImage failed: %s", SDL_GetError());
			if (tmptex)  { SDL_DestroyTexture(tmptex); tmptex = NULL; }
			if (fTexture){ SDL_DestroyTexture(fTexture); fTexture = NULL; }
			SDL_SetRenderTarget(renderer, NULL);
		}
done:
		;
	}

	stat("NXSurface::LoadImage name = %s, this = %p done", pbm_name, this);

	return (fTexture == NULL);
}
开发者ID:octopuserectus,项目名称:NXEngine-iOS,代码行数:68,代码来源:nxsurface.cpp

示例14: draw_HUD

void draw_HUD(SDL_Renderer* ren)
{
    //Draw the top bar
    SDL_SetRenderDrawColor(ren, 255, 255, 255, 0);
    top_bar.w = window_size_x;
    SDL_RenderFillRect(ren, &top_bar);

    draw_int(ren, font, top_bar_text_color, 20, 0, reqired_power,  "Required: ", " MW");
    draw_int(ren, font, top_bar_text_color, 20, 20, power_avalible, "Avalible: ", " MW");
    draw_int(ren, font, top_bar_text_color, 200, 00, getBalance(), "£", "000");
    draw_int(ren, font, top_bar_text_color, 200, 20, lastBalanceChange, "£", "000");

    draw_int(ren, font, top_bar_text_color, 400, 0, getPopulation(), "Pop: ", "");

    fill_scale_values();
    public_happiness_scale.x = window_size_x-100-80;
    draw_scale(ren, &public_happiness_scale, scale_values.average);

    //Draw the side bar
    if(show_sidebar) {
        SDL_SetRenderDrawColor(ren, 255, 255, 255, 0);
        side_bar.x = window_size_x - side_bar.w;
        SDL_RenderFillRect(ren, &side_bar);
        SDL_Rect scaleBox = {window_size_x-100-5,0,100,fontSizeLarge+2};
        int item_y = side_bar.y+5;

        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_POLICE_start);
        scaleBox.y = item_y;
        draw_scale(ren, &scaleBox, scale_values.police);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_HEALTH_start);
        setColorGoodBad(ren, scale_values.health);
        scaleBox.y = item_y;
        SDL_RenderFillRect(ren, &scaleBox);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_EDUCATION_start);
        setColorGoodBad(ren, populationPerSchool() < target_population_per_school);
        scaleBox.y = item_y;
        draw_scale(ren, &scaleBox, scale_values.education);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_SHOPPING_start);
        setColorGoodBad(ren, scale_values.shopping);
        scaleBox.y = item_y;
        SDL_RenderFillRect(ren, &scaleBox);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_POWER_start);
        scaleBox.y = item_y;
        draw_scale(ren, &scaleBox, scale_values.power);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_WASTE_start);
        scaleBox.y = item_y;
        draw_scale(ren, &scaleBox, scale_values.waste);

        item_y += fontSizeLarge+2;
        draw_string(ren, fontLarge, top_bar_text_color, side_bar.x+5, item_y, &_binary_VALUE_TEXT_POLUTION_start);
        scaleBox.y = item_y;
        draw_scale(ren, &scaleBox, scale_values.polution);
    }

    SDL_SetRenderDrawColor(ren, 0, 0, 0, 0);

    SDL_Rect open_menu_button = {window_size_x-30,0,30,30};
    SDL_RenderFillRect(ren, &open_menu_button);

    char* modeText = NULL;
    switch(getMode()) {
        case MODE_BUILD_RESIDENTIAL_1:
            modeText = &_binary_MODE_TEXT_RESIDENTIAL_1_start;
            break;
        case MODE_BUILD_RESIDENTIAL_2:
            modeText = &_binary_MODE_TEXT_RESIDENTIAL_2_start;
            break;
        case MODE_BUILD_ROAD:
            modeText = &_binary_MODE_TEXT_BUILD_ROAD_start;
            break;
        case MODE_BUILD_POWER_GAS:
            modeText = &_binary_MODE_TEXT_BUILD_POWER_GAS_start;
            break;
        case MODE_BUILD_DESTROY:
            modeText = &_binary_MODE_TEXT_DESTROY_start;
            break;
        case MODE_BUILD_RETAIL:
            modeText = &_binary_MODE_TEXT_BUILD_RETAIL_start;
            break;
        case MODE_BUILD_HOSPITAL:
            modeText = &_binary_MODE_TEXT_BUILD_HOSPITAL_start;
            break;
        case MODE_BUILD_POWER_SOLAR:
            modeText = &_binary_MODE_TEXT_BUILD_POWER_SOLAR_start;
            break;
        default:
            break;
    }
    if(modeText != NULL) {
        draw_string(ren, font, top_bar_text_color, 5, window_size_y-15, modeText);
//.........这里部分代码省略.........
开发者ID:jake314159,项目名称:city-master,代码行数:101,代码来源:drawing_functions.c

示例15: WatchGameController

SDL_bool
WatchGameController(SDL_GameController * gamecontroller)
{
    const char *name = SDL_GameControllerName(gamecontroller);
    const char *basetitle = "Game Controller Test: ";
    const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1;
    char *title = (char *)SDL_malloc(titlelen);
    SDL_Window *window = NULL;

    retval = SDL_FALSE;
    done = SDL_FALSE;

    if (title) {
        SDL_snprintf(title, titlelen, "%s%s", basetitle, name);
    }

    /* Create a window to display controller state */
    window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED,
                              SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
                              SCREEN_HEIGHT, 0);
    SDL_free(title);
    title = NULL;
    if (window == NULL) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
        return SDL_FALSE;
    }

    screen = SDL_CreateRenderer(window, -1, 0);
    if (screen == NULL) {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
        SDL_DestroyWindow(window);
        return SDL_FALSE;
    }

    SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
    SDL_RenderClear(screen);
    SDL_RenderPresent(screen);
    SDL_RaiseWindow(window);

    /* scale for platforms that don't give you the window size you asked for. */
    SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);

    background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
    button = LoadTexture(screen, "button.bmp", SDL_TRUE);
    axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);

    if (!background || !button || !axis) {
        SDL_DestroyRenderer(screen);
        SDL_DestroyWindow(window);
        return SDL_FALSE;
    }
    SDL_SetTextureColorMod(button, 10, 255, 21);
    SDL_SetTextureColorMod(axis, 10, 255, 21);

    /* !!! FIXME: */
    /*SDL_RenderSetLogicalSize(screen, background->w, background->h);*/

    /* Print info about the controller we are watching */
    SDL_Log("Watching controller %s\n",  name ? name : "Unknown Controller");

    /* Loop, getting controller events! */
#ifdef __EMSCRIPTEN__
    emscripten_set_main_loop_arg(loop, gamecontroller, 0, 1);
#else
    while (!done) {
        loop(gamecontroller);
    }
#endif

    SDL_DestroyRenderer(screen);
    screen = NULL;
    background = NULL;
    button = NULL;
    axis = NULL;
    SDL_DestroyWindow(window);
    return retval;
}
开发者ID:Cyberunner23,项目名称:SDL-mirror,代码行数:77,代码来源:testgamecontroller.c


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