Example #1
0
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;
}
Example #2
0
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;
}
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;
}
Example #4
0
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;
}
Example #5
0
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;
}
Example #6
0
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;
}
Example #7
0
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;
}
Example #8
0
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;
}
Example #9
0
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);
	}
}
Example #10
0
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;
}
Example #11
0
	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);
	}
Example #12
0
/**
 * \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;
}
Example #13
0
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;
}
Example #14
0
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);
}
Example #15
0
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);
	}
}
Example #16
0
bool GsBitmap::scaleTo(const GsRect<Uint16> &destRes)
{
    SDL_Rect newRect = destRes.SDLRect();

    // Need to do that, otherwise it won't work.
    optimizeSurface();

    if(newRect.w == mpBitmapSurface->w &&
       newRect.h == mpBitmapSurface->h)
        return true;


    std::shared_ptr<SDL_Surface> newSfc;

    auto bmpSfc = mpBitmapSurface.get();
    auto bmpFormat = bmpSfc->format;

    newSfc.reset( SDL_CreateRGBSurface(bmpSfc->flags,
                                       newRect.w, newRect.h,
                                       bmpFormat->BitsPerPixel,
                                       bmpFormat->Rmask,
                                       bmpFormat->Gmask,
                                       bmpFormat->Bmask,
                                       bmpFormat->Amask ),
                    &SDL_FreeSurface );

    if(!newSfc)
      return false;

#if SDL_VERSION_ATLEAST(2, 0, 0)

    SDL_BlendMode blendMode;

    SDL_GetSurfaceBlendMode(bmpSfc, &blendMode);
    SDL_SetSurfaceBlendMode(newSfc.get(), blendMode);

#endif

    CVidConfig &vidConf = gVideoDriver.getVidConfig();


    blitScaled(bmpSfc,
               bmpSfc->clip_rect,
               newSfc.get(),
               newRect,
               vidConf.m_ScaleXFilter);

    mpBitmapSurface = newSfc;

    return true;
}
Example #17
0
SDL_Surface *OpenGLImageHelper::convertSurface(SDL_Surface *tmpImage,
                                               int width, int height)
{
    if (!tmpImage)
        return nullptr;

#ifdef USE_SDL2
    SDL_SetSurfaceAlphaMod(tmpImage, SDL_ALPHA_OPAQUE);
#else  // USE_SDL2

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

    // 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  // SDL_BYTEORDER == SDL_BIG_ENDIAN

    rmask = 0x000000ff;
    gmask = 0x0000ff00;
    bmask = 0x00ff0000;
    amask = 0xff000000;
#endif  // SDL_BYTEORDER == SDL_BIG_ENDIAN

    if (tmpImage->format->BitsPerPixel != 32
        || 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  // USE_SDL2

        tmpImage = MSDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
            32, rmask, gmask, bmask, amask);

        if (!tmpImage)
        {
            reportAlways("Error, image convert failed: out of memory");
            return nullptr;
        }
        SDL_BlitSurface(oldImage, nullptr, tmpImage, nullptr);
    }
    return tmpImage;
}
Example #18
0
void CCursorHandler::initCursor()
{
	xpos = ypos = 0;
	type = ECursor::DEFAULT;
	dndObject = nullptr;
	currentCursor = nullptr;

	help = CSDL_Ext::newSurface(40,40);
	//No blending. Ensure, that we are copying pixels during "screen restore draw"
	SDL_SetSurfaceBlendMode(help,SDL_BLENDMODE_NONE);	
	SDL_ShowCursor(SDL_DISABLE);

	changeGraphic(ECursor::ADVENTURE, 0);
}
Example #19
0
int image_sdl_mask(SDL_Surface *overlay, int32_t overlay_x,
				   int32_t overlay_y, SDL_Surface *dst_image,
				   enum mask_style style)
{
	int ret;
	SDL_Rect overlay_rect;

	assert(overlay);
	assert(dst_image);

	overlay_rect.x = overlay_x;
	overlay_rect.y = overlay_y;
	/* overlay_rect.w = overlay->w + overlay_x; */
	/* overlay_rect.h = overlay->h + overlay_y; */
	if(style == MASKSTYLE_BLEND)
		SDL_SetSurfaceBlendMode(overlay, SDL_BLENDMODE_BLEND);
	else if(style == MASKSTYLE_REPLACE)
		SDL_SetSurfaceBlendMode(overlay, SDL_BLENDMODE_NONE);
	ret = SDL_BlitSurface(overlay, NULL, dst_image, &overlay_rect);
	if(ret != 0)
		sg_log_err("SDL_BlitSurface failure: %s.", SDL_GetError());

	return ret;
}
Example #20
0
bool GsSurface::scaleTo(const GsRect<Uint16> &scaledRect, const filterOptionType filter)
{
    SDL_Rect newRect = scaledRect.SDLRect();

    if(newRect.w == mpSurface->w && newRect.h == mpSurface->h)
        return true;


    // Need to do that, otherwise it won't work ???
    //optimizeSurface();

    auto sfcFormat = mpSurface->format;

    SDL_Surface *newSfc =
            SDL_CreateRGBSurface(mpSurface->flags,
                                 newRect.w, newRect.h,
                                 sfcFormat->BitsPerPixel,
                                 sfcFormat->Rmask,
                                 sfcFormat->Gmask,
                                 sfcFormat->Bmask,
                                 sfcFormat->Amask  );

    if(!newSfc)
      return false;

#if SDL_VERSION_ATLEAST(2, 0, 0)

    SDL_BlendMode blendMode;

    SDL_GetSurfaceBlendMode(mpSurface, &blendMode);
    SDL_SetSurfaceBlendMode(newSfc, blendMode);

#endif

    blitScaled(mpSurface,
               mpSurface->clip_rect,
               newSfc,
               newRect,
               filter);

    // Tear down old surface!
    SDL_FreeSurface(mpSurface);

    // And set the newly created and scaled one
    mpSurface = newSfc;

    return true;
}
Example #21
0
void Texture::loadFromSurface(SDL_Surface* surface)
{
    SDL_Surface* resizedSurface = NULL;
    SDL_Rect area;

    if (surface == NULL)
    {
        return;
    }

    int newWidth = NearestPowerOf2(_width);
    int newHeight = NearestPowerOf2(_height);

    int bpp;
    Uint32 Rmask, Gmask, Bmask, Amask;

    SDL_PixelFormatEnumToMasks(
        SDL_PIXELFORMAT_ABGR8888, &bpp,
        &Rmask, &Gmask, &Bmask, &Amask
    );

    resizedSurface = SDL_CreateRGBSurface(0, newWidth, newHeight, bpp,
        Rmask, Gmask, Bmask, Amask
    );

    area.x = 0;
    area.y = 0;
    area.w = surface->w;
    area.h = surface->h;

    SDL_SetSurfaceAlphaMod( surface, 0xFF );
    SDL_SetSurfaceBlendMode( surface, SDL_BLENDMODE_NONE );
    SDL_BlitSurface(surface, &area, resizedSurface, &area);

    glBindTexture(GL_TEXTURE_2D, _textureID);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, resizedSurface->w, resizedSurface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, resizedSurface->pixels);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    _textureWidth = resizedSurface->w;
    _textureHeight = resizedSurface->h;
    SDL_FreeSurface(resizedSurface);
}
Example #22
0
Bitmap::Bitmap(const char *filename)
{
	BitmapOpenHandler handler;
	shState->fileSystem().openRead(handler, filename);
	SDL_Surface *imgSurf = handler.surf;

	if (!imgSurf)
		throw Exception(Exception::SDLError, "Error loading image '%s': %s",
		                filename, SDL_GetError());

	p->ensureFormat(imgSurf, SDL_PIXELFORMAT_ABGR8888);

	if (imgSurf->w > glState.caps.maxTexSize || imgSurf->h > glState.caps.maxTexSize)
	{
		/* Mega surface */
		p = new BitmapPrivate(this);
		p->megaSurface = imgSurf;
		SDL_SetSurfaceBlendMode(p->megaSurface, SDL_BLENDMODE_NONE);
	}
	else
	{
		/* Regular surface */
		TEXFBO tex;

		try
		{
			tex = shState->texPool().request(imgSurf->w, imgSurf->h);
		}
		catch (const Exception &e)
		{
			SDL_FreeSurface(imgSurf);
			throw e;
		}

		p = new BitmapPrivate(this);
		p->gl = tex;

		TEX::bind(p->gl.tex);
		TEX::uploadImage(p->gl.width, p->gl.height, imgSurf->pixels, GL_RGBA);

		SDL_FreeSurface(imgSurf);
	}

	p->addTaintedArea(rect());
}
Example #23
0
static KW_Surface * KWSDL_createRGBA32Surface(KW_RenderDriver * driver, unsigned width, unsigned height) {
  unsigned rmask, gmask, bmask, amask;
  SDL_Surface * s;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
  rmask = 0xff000000;
  gmask = 0x00ff0000;
  bmask = 0x0000ff00;
  amask = 0x000000ff;
#else
  rmask = 0x000000ff;
  gmask = 0x0000ff00;
  bmask = 0x00ff0000;
  amask = 0xff000000;
#endif
  s = SDL_CreateRGBSurface(0, width, height, 32, rmask, gmask, bmask, amask);
  SDL_SetSurfaceBlendMode(s, SDL_BLENDMODE_NONE);
  return s;
}
Example #24
0
bool Surface::Load(const std::string & fn)
{
    FreeSurface(*this);

#ifdef WITH_IMAGE
    surface = IMG_Load(fn.c_str());
#if SDL_VERSION_ATLEAST(2, 0, 0)
    SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
#endif
#else
    surface = SDL_LoadBMP(fn.c_str());
#endif

    if(!surface)
	ERROR(SDL_GetError());

    return surface;
}
Example #25
0
SDL_Surface* load_image(char *filename) {
    SDL_Surface *optimized = NULL;
    SDL_Surface *raw = IMG_Load(filename);

    if (raw == NULL) {
        fprintf(stderr, "Unable to load image %s - %s\n", filename,
            SDL_GetError());
    }
    else {
        optimized = SDL_ConvertSurface(raw, g_screen->format, 0);
        if (optimized == NULL) {
            fprintf(stderr, "Unable to optimize image %s - %s", filename,
                SDL_GetError());
        }
        SDL_SetSurfaceBlendMode(optimized, SDL_BLENDMODE_BLEND);
    }
    return optimized;
}
Example #26
0
	void redraw()
	{
		fillSurface(winSurf, cBgNorm);

		for (size_t i = 0; i < widgets.size(); ++i)
			widgets[i]->draw(winSurf);

		if (state == AwaitingInput)
		{
			char buf[64];
			snprintf(buf, sizeof(buf), "Press key or joystick button for \"%s\"", captureName);

			drawOff = Vec2i();

			SDL_Surface *dark = createSurface(winSize.x, winSize.y);
			fillSurface(dark, 0);
			SDL_SetSurfaceAlphaMod(dark, 128);
			SDL_SetSurfaceBlendMode(dark, SDL_BLENDMODE_BLEND);
			SDL_Surface *txt = createTextSurface(buf, false);

			SDL_BlitSurface(dark, 0, winSurf, 0);

			SDL_Rect fill;
			fill.x = (winSize.x - txt->w - 20) / 2;
			fill.y = (winSize.y - txt->h - 20) / 2;
			fill.w = txt->w + 20;
			fill.h = txt->h + 20;

			fillRect(winSurf, cBgNorm, fill.x, fill.y, fill.w, fill.h);
			strokeRectInner(winSurf, cLine, fill.x, fill.y, fill.w, fill.h, 2);

			fill.x += 10;
			fill.y += 10;
			fill.w = txt->w;
			fill.h = txt->h;

			SDL_BlitSurface(txt, 0, winSurf, &fill);

			SDL_FreeSurface(txt);
			SDL_FreeSurface(dark);
		}

		SDL_UpdateWindowSurface(window);
	}
Example #27
0
void GameShell::gameWon()
{
    SDL_Rect fullscreen;
    SDL_Rect position;
    SDL_Rect goverpos;
    fullscreen.x = fullscreen.y = 0;
    fullscreen.h = SCREEN_HEIGHT;
    fullscreen.w = SCREEN_WIDTH;
    //Uint32 color = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
    //SDL_FillRect(screen, &fullscreen, color);
    Uint8 alpha = 1;
    SDL_SetSurfaceBlendMode(screen, SDL_BLENDMODE_BLEND);
    SDL_SetSurfaceAlphaMod(screen, alpha);
    position.x = 80;
    position.y = 212;
    goverpos.x = goverpos.y = 0;
    goverpos.h = 55;
    goverpos.w = 480;
    SDL_BlitSurface(gamewon, &goverpos, screen, &position);
}
Example #28
0
SDL_Surface *Surface::createSurfaceWithFormat(int width, int height,
        int depth, uint32_t format)
{
#if SDL_VERSION_ATLEAST(2, 0, 5)
    return SDL_CreateRGBSurfaceWithFormat(0, width, height, depth, format);
#else
    SDL_Surface *unoptSurface = SDL_CreateRGBSurface(0, width, height,
                                depth, 0, 0, 0, 0);
    SDL_Surface *optSurface = SDL_ConvertSurfaceFormat(unoptSurface, format, 0);
    SDL_FreeSurface(unoptSurface);

    // Surfaces with alpha are set up for blending by default.
    if (optSurface->format->Amask != 0)
    {
        SDL_SetSurfaceBlendMode(optSurface, SDL_BLENDMODE_BLEND);
    }

    return optSurface;
#endif
}
Example #29
0
static void init_vbutton_texture() {
    SDL_DisplayMode current;
    SDL_GetCurrentDisplayMode(0, &current);    
    
    SDL_Surface *overlay = SDL_CreateRGBSurface(0, current.w, current.h, 32,
                                        0x00FF0000,
                                        0x0000FF00,
                                        0x000000FF,
                                        0xFF000000);
   
    // Draw DPad
    SDL_Rect left = {DPAD_LEFT_X, DPAD_LEFT_Y(current.h), DPAD_LEFT_W, DPAD_LEFT_H};
    SDL_Rect right = {DPAD_RIGHT_X, DPAD_RIGHT_Y(current.h), DPAD_RIGHT_W, DPAD_RIGHT_H};
    SDL_Rect up = {DPAD_UP_X, DPAD_UP_Y(current.h), DPAD_UP_W, DPAD_UP_H};
    SDL_Rect down = {DPAD_DOWN_X, DPAD_DOWN_Y(current.h), DPAD_DOWN_W, DPAD_DOWN_H};

    // Draw Start/Select
    SDL_Rect start = {START_X, START_Y(current.h), START_W, START_H};
    SDL_Rect select = {SELECT_X, SELECT_Y(current.h), SELECT_W, SELECT_H};

    // Draw A/B
    SDL_Rect a = {A_X(current.w), A_Y(current.h), A_W, A_H};
    SDL_Rect b = {B_X(current.w), B_Y(current.h), B_W, B_H};
    
    Uint32 b_color = SDL_MapRGB(overlay->format, 0x95, 0x8E, 0x8E);
 
    SDL_FillRect(overlay, &left, b_color);
    SDL_FillRect(overlay, &right, b_color);
    SDL_FillRect(overlay, &down, b_color);
    SDL_FillRect(overlay, &up, b_color);
    SDL_FillRect(overlay, &start, b_color);
    SDL_FillRect(overlay, &select, b_color);
    SDL_FillRect(overlay, &a, b_color);
    SDL_FillRect(overlay, &b, b_color);

    SDL_SetSurfaceBlendMode(overlay, SDL_BLENDMODE_BLEND);

    // Make overlay partially transparent
    SDL_SetSurfaceAlphaMod(overlay, 0x7F);
    overlay_t = SDL_CreateTextureFromSurface(renderer, overlay);
}
Example #30
0
	void GLText::SetText(const std::string& str, const SDL_Color &color, TTF_Font *font) {
		glGenTextures(1, &textureid);
		glBindTexture(GL_TEXTURE_2D, textureid);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
		glBindTexture(GL_TEXTURE_2D, 0);

		SDL_Surface *surf = TTF_RenderUTF8_Blended(font, str.c_str(), color);
		//int p = int(pow(2, ceil(log(std::max(surf->w, surf->h)) / log(2))));
		SDL_Surface* ns = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
		SDL_BlitSurface(surf, nullptr, ns, nullptr);
		SDL_SetSurfaceBlendMode(surf, SDL_BLENDMODE_NONE);
		glBindTexture(GL_TEXTURE_2D, textureid);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ns->w, ns->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, ns->pixels);
		glBindTexture(GL_TEXTURE_2D, 0);
		//SDL_SaveBMP(surf, GetPathToAsset("blended.bmp").c_str());
		SDL_FreeSurface(surf);
	}