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


C++ SDL_SetSurfaceBlendMode函数代码示例

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


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

示例1: assert

SDL_Surface *image_sdl_set_alpha(SDL_Surface *src, uint8_t alpha)
{
	int ret;
	SDL_Surface *surf;
	Uint8 swap;

	assert(src);

	surf = image_sdl_create((uint32_t)src->w, (uint32_t)src->h, color_transparent);
	if(surf == NULL) {
		sg_log_err("image_create returns null.");
		return NULL;
	}

	SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_NONE);

	ret = SDL_GetSurfaceAlphaMod(src, &swap);
	if(ret != 0) {
		sg_log_err("SDL_GetSurfaceAlphaMod failure.");
		return NULL;
	}
	SDL_SetSurfaceAlphaMod(src, alpha); /* Set new alpha degree. */
	SDL_BlitSurface(src, NULL, surf, NULL);
	SDL_SetSurfaceAlphaMod(src, swap); /* Reset to original alpha degree. */

	return surf;
}
开发者ID:IvwsIgeMq,项目名称:libsg,代码行数:27,代码来源:image_sdl.c

示例2: SW_CreateTexture

static int
SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
    int bpp;
    Uint32 Rmask, Gmask, Bmask, Amask;

    if (!SDL_PixelFormatEnumToMasks
        (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
        return SDL_SetError("Unknown texture format");
    }

    texture->driverdata =
        SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask,
                             Bmask, Amask);
    SDL_SetSurfaceColorMod(texture->driverdata, texture->r, texture->g,
                           texture->b);
    SDL_SetSurfaceAlphaMod(texture->driverdata, texture->a);
    SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode);

    /* Only RLE encode textures without an alpha channel since the RLE coder
     * discards the color values of pixels with an alpha value of zero.
     */
    if (texture->access == SDL_TEXTUREACCESS_STATIC && !Amask) {
        SDL_SetSurfaceRLE(texture->driverdata, 1);
    }

    if (!texture->driverdata) {
        return -1;
    }
    return 0;
}
开发者ID:ibachar,项目名称:firecube,代码行数:31,代码来源:SDL_render_sw.c

示例3: SW_CreateTexture

static int
SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
    int bpp;
    Uint32 Rmask, Gmask, Bmask, Amask;

    if (!SDL_PixelFormatEnumToMasks
        (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
        return SDL_SetError("Unknown texture format");
    }

    texture->driverdata =
        SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask,
                             Bmask, Amask);
    SDL_SetSurfaceColorMod(texture->driverdata, texture->r, texture->g,
                           texture->b);
    SDL_SetSurfaceAlphaMod(texture->driverdata, texture->a);
    SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode);

    if (texture->access == SDL_TEXTUREACCESS_STATIC) {
        SDL_SetSurfaceRLE(texture->driverdata, 1);
    }

    if (!texture->driverdata) {
        return -1;
    }
    return 0;
}
开发者ID:MichalWolodkiewicz,项目名称:wizznic-android,代码行数:28,代码来源:SDL_render_sw.c

示例4: SDL_SetAlpha

int SDL_SetAlpha(SDL_Surface *surface, Uint32 flag, Uint8 alpha) {
	if (SDL_SetSurfaceAlphaMod(surface, alpha)) {
		return -1;
	}

	if (alpha == 255 || !flag) {
		if (SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE)) {
			return -1;
		}
	} else {
		if (SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND)) {
			return -1;
		}
	}

	return 0;
}
开发者ID:CrazyMax,项目名称:scummvm,代码行数:17,代码来源:sdl.cpp

示例5: powerOfTwo

SDL_Surface *OpenGLImageHelper::convertSurface(SDL_Surface *tmpImage,
                                               int width, int height)
{
    if (!tmpImage)
        return nullptr;

    int realWidth = powerOfTwo(width);
    int realHeight = powerOfTwo(height);

    if (realWidth < width || realHeight < height)
    {
        logger->log("Warning: image too large, cropping to %dx%d texture!",
                    tmpImage->w, tmpImage->h);
    }

#ifdef USE_SDL2
    SDL_SetSurfaceAlphaMod(tmpImage, SDL_ALPHA_OPAQUE);
#else
    // Make sure the alpha channel is not used, but copied to destination
    SDL_SetAlpha(tmpImage, 0, SDL_ALPHA_OPAQUE);
#endif

    // Determine 32-bit masks based on byte order
    uint32_t rmask, gmask, bmask, amask;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    rmask = 0xff000000;
    gmask = 0x00ff0000;
    bmask = 0x0000ff00;
    amask = 0x000000ff;
#else
    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
    amask = 0xff000000;
#endif

    if (tmpImage->format->BitsPerPixel != 32
        || realWidth != width || realHeight != height
        || rmask != tmpImage->format->Rmask
        || gmask != tmpImage->format->Gmask
        || amask != tmpImage->format->Amask)
    {
        SDL_Surface *oldImage = tmpImage;
#ifdef USE_SDL2
        SDL_SetSurfaceBlendMode(oldImage, SDL_BLENDMODE_NONE);
#endif
        tmpImage = MSDL_CreateRGBSurface(SDL_SWSURFACE, realWidth, realHeight,
            32, rmask, gmask, bmask, amask);

        if (!tmpImage)
        {
            logger->log("Error, image convert failed: out of memory");
            return nullptr;
        }
        SDL_BlitSurface(oldImage, nullptr, tmpImage, nullptr);
    }
    return tmpImage;
}
开发者ID:nashley,项目名称:ManaPlus,代码行数:58,代码来源:openglimagehelper.cpp

示例6: SDL_SetAlpha

int
SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value)
{
    if (flag & SDL_SRCALPHA) {
        /* According to the docs, value is ignored for alpha surfaces */
        if (surface->format->Amask) {
            value = 0xFF;
        }
        SDL_SetSurfaceAlphaMod(surface, value);
        SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
    } else {
        SDL_SetSurfaceAlphaMod(surface, 0xFF);
        SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
    }
    SDL_SetSurfaceRLE(surface, (flag & SDL_RLEACCEL));

    return 0;
}
开发者ID:Blitzoreo,项目名称:pcsx2-online,代码行数:18,代码来源:SDL_compat.c

示例7: KWSDL_loadSurface

static KW_Surface * KWSDL_loadSurface(KW_RenderDriver * driver, const char * texturefile) {
  SDL_Surface * s = IMG_Load(texturefile);
  if (s == NULL) {
    fprintf(stderr, "KW_RenderDriver_SDL: Could not load texture %s: %s\n", texturefile, IMG_GetError());
    return NULL;
  }
  SDL_SetSurfaceBlendMode(s, SDL_BLENDMODE_NONE);
  return s;
}
开发者ID:ckeen,项目名称:KiWi,代码行数:9,代码来源:KW_renderdriver_sdl2.c

示例8: set_blend_mode

bool Image::set_blend_mode ( const SDL_BlendMode blend )
{
  if ( SDL_SetSurfaceBlendMode ( this->image(), blend ) != 0 )
  {
NOM_LOG_ERR ( NOM, SDL_GetError() );
    return false;
  }

  return true;
}
开发者ID:i8degrees,项目名称:nomlib,代码行数:10,代码来源:Image.cpp

示例9: update_sky

void update_sky()
{
	if (target_transp != curr_transp)
	{
		curr_transp += ((target_transp - curr_transp) > 0) ? 5 : -5;
		SDL_BlitSurface(s_b_sky_day, NULL, s_b_sky, NULL);
		SDL_SetSurfaceAlphaMod(s_b_sky_night, curr_transp);
		SDL_SetSurfaceBlendMode(s_b_sky_night, SDL_BLENDMODE_BLEND);
		SDL_BlitSurface(s_b_sky_night, NULL, s_b_sky, NULL);
	}
}
开发者ID:omegacoleman,项目名称:toksin,代码行数:11,代码来源:user_interface.cpp

示例10: mrb_sdl2_video_surface_set_blend_mode

static mrb_value
mrb_sdl2_video_surface_set_blend_mode(mrb_state *mrb, mrb_value self)
{
    mrb_int mode;
    mrb_get_args(mrb, "i", &mode);
    SDL_Surface *s = mrb_sdl2_video_surface_get_ptr(mrb, self);
    if (0 != SDL_SetSurfaceBlendMode(s, (SDL_BlendMode)mode)) {
        mruby_sdl2_raise_error(mrb);
    }
    return self;
}
开发者ID:asfluido,项目名称:mruby-sdl2,代码行数:11,代码来源:sdl2_surface.c

示例11: switch

	void SurfaceSDL::setBlendMode(Surface::BlendMode bm) 
	{
		SDL_BlendMode sdl_bm;
		switch(bm) {
			case BLEND_MODE_NONE:	sdl_bm = SDL_BLENDMODE_NONE; break;
			case BLEND_MODE_BLEND:	sdl_bm = SDL_BLENDMODE_BLEND; break;
			case BLEND_MODE_ADD:	sdl_bm = SDL_BLENDMODE_ADD; break;
			case BLEND_MODE_MODULATE:	sdl_bm = SDL_BLENDMODE_MOD; break;
		}
		SDL_SetSurfaceBlendMode(surface_, sdl_bm);
	}
开发者ID:cbeck88,项目名称:render_engine,代码行数:11,代码来源:SurfaceSDL.cpp

示例12: if

/**
 * \brief Returns the SDL_Surface corresponding to the requested file.
 *
 * The returned SDL_Surface has to be manually deleted.
 *
 * \param file_name Name of the image file to load, relative to the base directory specified.
 * \param base_directory The base directory to use.
 * \return The SDL_Surface.
 */
SDL_Surface* Surface::get_surface_from_file(
    const std::string& file_name,
    ImageDirectory base_directory) {

  std::string prefix;
  bool language_specific = false;

  if (base_directory == DIR_SPRITES) {
    prefix = "sprites/";
  }
  else if (base_directory == DIR_LANGUAGE) {
    language_specific = true;
    prefix = "images/";
  }
  std::string prefixed_file_name = prefix + file_name;

  if (!QuestFiles::data_file_exists(prefixed_file_name, language_specific)) {
    // File not found.
    return nullptr;
  }

  const std::string& buffer = QuestFiles::data_file_read(prefixed_file_name, language_specific);
  SDL_RWops* rw = SDL_RWFromMem(const_cast<char*>(buffer.data()), (int) buffer.size());

  SDL_Surface* software_surface = IMG_Load_RW(rw, 0);

  SDL_RWclose(rw);

  Debug::check_assertion(software_surface != nullptr,
      std::string("Cannot load image '") + prefixed_file_name + "'");

  SDL_PixelFormat* pixel_format = Video::get_pixel_format();
  if (software_surface->format->format == pixel_format->format) {
    return software_surface;
  }

  // Convert to the preferred pixel format.
  uint8_t opacity;
  SDL_GetSurfaceAlphaMod(software_surface, &opacity);
  SDL_Surface* converted_surface = SDL_ConvertSurface(
        software_surface,
        pixel_format,
        0
        );
  Debug::check_assertion(converted_surface != nullptr,
                         "Failed to convert software surface");
  SDL_FreeSurface(software_surface);

  SDL_SetSurfaceAlphaMod(converted_surface, opacity);  // Re-apply the alpha.
  SDL_SetSurfaceBlendMode(converted_surface, SDL_BLENDMODE_BLEND);

  return converted_surface;
}
开发者ID:Maxs1789,项目名称:solarus,代码行数:62,代码来源:Surface.cpp

示例13: caml_SDL_SetSurfaceBlendMode

CAMLprim value
caml_SDL_SetSurfaceBlendMode(
        value surface,
        value blendMode)
{
    int r =
        SDL_SetSurfaceBlendMode(
            SDL_Surface_val(surface),
            SDL_BlendMode_val(blendMode));
    if (r) caml_failwith("Sdlsurface.set_blend_mode");
    return Val_unit;
}
开发者ID:fccm,项目名称:OCamlSDL2,代码行数:12,代码来源:sdlsurface_stub.c

示例14: SW_SetTextureBlendMode

static int
SW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
{
    SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
    /* If add or mod blending are ever enabled, permanently disable RLE (which doesn't support
     * them) to avoid potentially frequent RLE encoding/decoding.
     */
    if ((texture->blendMode == SDL_BLENDMODE_ADD || texture->blendMode == SDL_BLENDMODE_MOD)) {
        SDL_SetSurfaceRLE(surface, 0);
    }
    return SDL_SetSurfaceBlendMode(surface, texture->blendMode);
}
开发者ID:0-wiz-0,项目名称:mame,代码行数:12,代码来源:SDL_render_sw.c

示例15: SDL_SetAlpha

int SDL_SetAlpha(SDL_Surface* surface, Uint32 flag, Uint8 alpha)
{
	if(flag & SDL_SRCALPHA) {
		// Need to specify the alpha blend mode if not setting alpha as opaque
		int blendModeResult = SDL_SetSurfaceBlendMode (surface, SDL_BLENDMODE_BLEND);
		if (blendModeResult != 0)
			return blendModeResult;

		return SDL_SetSurfaceAlphaMod(surface, alpha);
	} else {
		return SDL_SetSurfaceAlphaMod(surface, SDL_ALPHA_OPAQUE);
	}
}
开发者ID:Heark,项目名称:wesnoth,代码行数:13,代码来源:alpha.cpp


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