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


C++ SDL_ConvertSurface函数代码示例

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


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

示例1: SDL_VERSION_ATLEAST

std::shared_ptr<SDL_Surface> CSprite::createCopySDLSurface(
        const std::shared_ptr<SDL_Surface>& original)
{
    std::shared_ptr<SDL_Surface> surface;

    if(original->format->BitsPerPixel < 16)
    {
        surface.reset(SDL_CreateRGBSurface( 0, m_xsize, m_ysize, 8, 0, 0, 0, 0), &SDL_FreeSurface);
#if SDL_VERSION_ATLEAST(2, 0, 0)
        SDL_SetPaletteColors(surface->format->palette, original->format->palette->colors, 0, 255);
        SDL_SetColorKey(surface.get(), SDL_TRUE, COLORKEY);
#else
        SDL_SetColors( surface.get(), original->format->palette->colors, 0, 255);
        SDL_SetColorKey( surface.get(), SDL_SRCCOLORKEY, COLORKEY ); // One black is the color key. There is another black, as normal color
#endif

        auto *origSfcPtr = original.get();

        SDL_FillRect( surface.get(), NULL, COLORKEY );
        SDL_BlitSurface( origSfcPtr, NULL, surface.get(), NULL);
    }
    else
    {
        surface.reset(SDL_ConvertSurface(original.get(),original->format,0));
    }

    return surface;
}
开发者ID:winktzhong,项目名称:Commander-Genius,代码行数:28,代码来源:CSprite.cpp

示例2: reference_count_

ttexture::ttexture(SDL_Renderer& renderer,
				   const int access,
				   const surface& surface)
	: reference_count_(new unsigned(1))
	, texture_(NULL)
	, rotation_(0)
	, hscale_(1)
	, vscale_(1)
	, smooth_scaling_(false)
	, flip_(SDL_FLIP_NONE)
	, clip_()
	, mod_r_(255)
	, mod_g_(255)
	, mod_b_(255)
	, alpha_(255)
	, source_surface_(
			SDL_ConvertSurface(surface, surface->format, surface->flags))
{
	if(source_surface_ == NULL) {
		throw texception("Invalid source_surface__ argument passed, failed to "
						 "create SDL_Texture object.",
						 false);
	}

	initialise_from_surface(renderer, access);
}
开发者ID:m06x,项目名称:wesnoth,代码行数:26,代码来源:texture.cpp

示例3: loadSurface

SDL_Surface* loadSurface( std::string path )
{
	//The final optimized image
	SDL_Surface* optimizedSurface = NULL;

	//Load image at specified path
	SDL_Surface* loadedSurface = IMG_Load( path.c_str() );
	if( loadedSurface == NULL )
	{
		printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() );
	}
	else
	{
		//Convert surface to screen format
		optimizedSurface = SDL_ConvertSurface( loadedSurface, gScreenSurface->format, NULL );
		if( optimizedSurface == NULL )
		{
			printf( "Unable to optimize image %s! SDL Error: %s\n", path.c_str(), SDL_GetError() );
		}

		//Get rid of old loaded surface
		SDL_FreeSurface( loadedSurface );
	}

	return optimizedSurface;
}
开发者ID:Fonzki,项目名称:SDLBoys,代码行数:26,代码来源:06.cpp

示例4: glGenTextures

Texture::Texture(unsigned dsize, const char* data, const char *extension, const char *mimeType)
{
  SDL_PixelFormat RGB_PixelFormat = {
    NULL,
    18,3,
    0,0,0,8,
    0,8,10,0,
    //! \todo bug with big endian?!
    0xff,0xff00,0xff0000,0x0,
    0,
    0xff
  };
    
  SDL_PixelFormat RGBA_PixelFormat = {
    NULL,
    32,4,
    0,0,0,0,
    0,8,16,24,
    //! \todo bug with big endian?!
    0xff,0xff00,0xff0000,0xff000000,
    0,
    0xff
  };

  SDL_Surface* image=loadImage(dsize, data, extension, mimeType);
  GLint internalformat;
  GLint format;
  GLenum type=GL_UNSIGNED_BYTE;
  SDL_PixelFormat* pixelformat;
  if (image->format->Amask) {
    // We have got a alpha channel !
    internalformat=GL_RGBA8;
    format=GL_RGBA;
    haveAlphaChannel=true;
    pixelformat=&RGBA_PixelFormat;
  }else{
    // as fallback convert to rgb
    internalformat=GL_RGB8;
    format=GL_RGB;
    haveAlphaChannel=false;
    pixelformat=&RGB_PixelFormat;
  }
  SDL_Surface* tmp=SDL_ConvertSurface(image,pixelformat,SDL_SWSURFACE);
  SDL_FreeSurface(image);
  image=tmp;
  tmp=NULL;
  width=image->w;
  height=image->h;
  
  glGenTextures(1,&textureID);
  glBindTexture(GL_TEXTURE_2D,textureID);
  int q=(2>1) ? GL_LINEAR : GL_NEAREST;
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,q); 
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,q);
  // 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image,
  // border 0 (normal), rgb color data, unsigned byte data, and finally the data itself.
  glTexImage2D(GL_TEXTURE_2D, 0, internalformat, width, height, 0, format , type, image->pixels);
  SDL_FreeSurface(image);
}
开发者ID:BackupTheBerlios,项目名称:jgachine,代码行数:59,代码来源:texture.cpp

示例5: strcpy

    //------------------------------------------------------------------------
    bool platform_support::load_img(unsigned idx, const char* file)
    {
        if(idx < max_images)
        {
            if(m_specific->m_surf_img[idx]) SDL_FreeSurface(m_specific->m_surf_img[idx]);

            char fn[1024];
            strcpy(fn, file);
            int len = strlen(fn);
            if(len < 4 || strcmp(fn + len - 4, ".bmp") != 0)
            {
                strcat(fn, ".bmp");
            }

            SDL_Surface* tmp_surf = SDL_LoadBMP(fn);
            if (tmp_surf == 0) 
            {
                fprintf(stderr, "Couldn't load %s: %s\n", fn, SDL_GetError());
                return false;
            }

            SDL_PixelFormat format;
            format.palette = 0;
            format.BitsPerPixel = m_bpp;
            format.BytesPerPixel = m_bpp >> 8;
            format.Rmask = m_specific->m_rmask;
            format.Gmask = m_specific->m_gmask;
            format.Bmask = m_specific->m_bmask;
            format.Amask = m_specific->m_amask;
            format.Rshift = 0;
            format.Gshift = 0;
            format.Bshift = 0;
            format.Ashift = 0;
            format.Rloss = 0;
            format.Gloss = 0;
            format.Bloss = 0;
            format.Aloss = 0;
            format.colorkey = 0;
            format.alpha = 0;

            m_specific->m_surf_img[idx] = 
                SDL_ConvertSurface(tmp_surf, 
                                   &format, 
                                   SDL_SWSURFACE);

            SDL_FreeSurface(tmp_surf);
            
            if(m_specific->m_surf_img[idx] == 0) return false;

            m_rbuf_img[idx].attach((unsigned char*)m_specific->m_surf_img[idx]->pixels, 
                                   m_specific->m_surf_img[idx]->w, 
                                   m_specific->m_surf_img[idx]->h, 
                                   m_flip_y ? -m_specific->m_surf_img[idx]->pitch : 
                                               m_specific->m_surf_img[idx]->pitch);
            return true;

        }
        return false;
    }
开发者ID:Chrysolophus,项目名称:aggdraw,代码行数:60,代码来源:agg_platform_support.cpp

示例6: SDL_ConvertSurface

Image *SDL2SoftwareImageHelper::_SDLload(SDL_Surface *tmpImage)
{
    if (!tmpImage)
        return nullptr;

    SDL_Surface *image = SDL_ConvertSurface(tmpImage, mFormat, 0);
    return new Image(image, false, nullptr);
}
开发者ID:KaneHart,项目名称:Elmlor-Client,代码行数:8,代码来源:sdl2softwareimagehelper.cpp

示例7: assert

SDL_Surface *image_sdl_clone(const SDL_Surface *src)
{
	assert(src);
	assert(src->w > 0);
	assert(src->h > 0);

	return SDL_ConvertSurface((SDL_Surface *)src, src->format, SDL_SWSURFACE);
}
开发者ID:IvwsIgeMq,项目名称:libsg,代码行数:8,代码来源:image_sdl.c

示例8: loginWindowUpdate

void loginWindowUpdate(const string &username, int pwdLen){
	if(loginSelectTexture[0] == 0) loginSelectTexture[0] = loadImg("res/loginsel0.png");
	if(loginSelectTexture[1] == 0) loginSelectTexture[1] = loadImg("res/loginsel1.png");
	if(loginSelectTexture[2] == 0) loginSelectTexture[2] = loadImg("res/loginsel2.png");
		
	if(loginSurface == NULL){
		loginSurface = IMG_Load("res/login.png");
	
		SDL_Color white, black;
		white.r = white.g = white.b = 0xFF;
		black.r = black.g = black.b = 0x00;
		
		SDL_Surface *titleText = TTF_RenderUTF8_Blended(font, "Login", white);
		SDL_Rect rTitle = {6,5,0,0};	
		SDL_BlitSurface(titleText, NULL, loginSurface, &rTitle);
		SDL_FreeSurface(titleText);	

		SDL_Surface *userLblText = TTF_RenderUTF8_Blended(font, "Usuario:", black);
		SDL_Rect rUserLbl = {8,35,0,0};
		SDL_BlitSurface(userLblText, NULL, loginSurface, &rUserLbl);
		SDL_FreeSurface(userLblText);		
		
		SDL_Surface *passLblText = TTF_RenderUTF8_Blended(font, "Password:", black);
		SDL_Rect rPassLbl = {8,67,0,0};
		SDL_BlitSurface(passLblText, NULL, loginSurface, &rPassLbl);
		SDL_FreeSurface(passLblText);		
		
		SDL_Surface *buttonText = TTF_RenderUTF8_Blended(font, "Aceptar", black);
		SDL_Rect rButton = {128,107,0,0};
		rButton.x -= buttonText->w/2;
		rButton.y -= buttonText->h/2;
		SDL_BlitSurface(buttonText, NULL, loginSurface, &rButton);
		SDL_FreeSurface(buttonText);			
		
		loginTexture = genTexture(loginSurface, loginTexture);	
	}
	
	SDL_Color black;
	black.r = black.g = black.b = 0x00;
	
	SDL_Surface *tempSurface = SDL_ConvertSurface(loginSurface, loginSurface->format, loginSurface->flags);
	
	SDL_Surface *userNameText = TTF_RenderUTF8_Blended(font, username.c_str(), black);
	SDL_Rect rUserName = {91,35,0,0};
	SDL_BlitSurface(userNameText, NULL, tempSurface, &rUserName);
	SDL_FreeSurface(userNameText);
	
	string tempPass;
	for(int i=0;i<pwdLen;i++) tempPass += '*';
	
	SDL_Surface *passWordText = TTF_RenderUTF8_Blended(font, tempPass.c_str(), black);
	SDL_Rect rPassWord = {91,67,0,0};
	SDL_BlitSurface(passWordText, NULL, tempSurface, &rPassWord);
	SDL_FreeSurface(passWordText);	
	
	loginTexture = genTexture(tempSurface, loginTexture);	
	SDL_FreeSurface(tempSurface);
}
开发者ID:scetticus,项目名称:electronica-tgc,代码行数:58,代码来源:login.cpp

示例9: SDL_ConvertSurface

bool Texture::CreateFromSurface(SDL_Surface *s, bool forceRGBA)
{
	bool freeSurface = false;

	SDL_PixelFormat *pixfmt = s->format;

	GLenum targetGLformat;
	SDL_PixelFormat *targetPixfmt;
	bool needConvert = !GetTargetFormat(pixfmt, &targetGLformat, &targetPixfmt, forceRGBA);

	if (needConvert) {
		s = SDL_ConvertSurface(s, targetPixfmt, SDL_SWSURFACE);
		freeSurface = true;
	}

	// store incoming 24-bit as GL_RGB to save on texture memory
	if (targetGLformat == GL_RGB && m_format.internalFormat == GL_RGBA) {
		m_format.internalFormat = GL_RGB;
		m_format.dataFormat = GL_RGB;
	}

	unsigned int width = s->w;
	unsigned int height = s->h;

	// extend to power-of-two if necessary
	int width2 = ceil_pow2(s->w);
	int height2 = ceil_pow2(s->h);
	if (s->w != width2 || s->h != height2) {
		SDL_Surface *s2 = SDL_CreateRGBSurface(SDL_SWSURFACE, width2, height2, targetPixfmt->BitsPerPixel, targetPixfmt->Rmask, targetPixfmt->Gmask, targetPixfmt->Bmask, targetPixfmt->Amask);

		SDL_SetAlpha(s, 0, 0);
		SDL_SetAlpha(s2, 0, 0);
		SDL_BlitSurface(s, 0, s2, 0);

		if (freeSurface)
			SDL_FreeSurface(s);

		s = s2;
		freeSurface = true;

		m_texWidth = float(width) / float(width2);
		m_texHeight = float(height) / float(height2);
	}
	else
		m_texWidth = m_texHeight = 1.0f;

	SDL_LockSurface(s);
	CreateFromArray(s->pixels, s->w, s->h);
	SDL_UnlockSurface(s);

	m_width = width;
	m_height = height;

	if (freeSurface)
		SDL_FreeSurface(s);

	return true;
}
开发者ID:ChromeSkull,项目名称:pioneer,代码行数:58,代码来源:Texture.cpp

示例10: data

	void ImageLoader::load(IResource* res) {
		VFS* vfs = VFS::instance();

		Image* img = dynamic_cast<Image*>(res);

		//Have to save the images x and y shift or it gets lost when it's
		//loaded again.
		int32_t xShiftSave = img->getXShift();
		int32_t yShiftSave = img->getYShift();

		if(!img->isSharedImage()) {
			const std::string& filename = img->getName();
			boost::scoped_ptr<RawData> data (vfs->open(filename));
			size_t datalen = data->getDataLength();
			boost::scoped_array<uint8_t> darray(new uint8_t[datalen]);
			data->readInto(darray.get(), datalen);
			SDL_RWops* rwops = SDL_RWFromConstMem(darray.get(), static_cast<int>(datalen));

			SDL_Surface* surface = IMG_Load_RW(rwops, false);

			if (!surface) {
				throw SDLException(std::string("Fatal Error when loading image into a SDL_Surface: ") + SDL_GetError());
			}

			RenderBackend* rb = RenderBackend::instance();
			// in case of SDL we don't need to convert the surface
			if (rb->getName() == "SDL") {
				img->setSurface(surface);
			// in case of OpenGL we need a 32bit surface
			} else {
				SDL_PixelFormat dst_format = rb->getPixelFormat();
				SDL_PixelFormat src_format = *surface->format;
				uint8_t dstbits = dst_format.BitsPerPixel;
				uint8_t srcbits = src_format.BitsPerPixel;

				if (srcbits != 32 || dst_format.Rmask != src_format.Rmask || dst_format.Gmask != src_format.Gmask ||
					dst_format.Bmask != src_format.Bmask || dst_format.Amask != src_format.Amask) {
					dst_format.BitsPerPixel = 32;
					SDL_Surface* conv = SDL_ConvertSurface(surface, &dst_format, 0);
					dst_format.BitsPerPixel = dstbits;

					if (!conv) {
						throw SDLException(std::string("Fatal Error when converting surface to the screen format: ") + SDL_GetError());
					}

					img->setSurface(conv);
					SDL_FreeSurface(surface);
				} else {
					img->setSurface(surface);
				}
			}

			SDL_FreeRW(rwops);
		}
		//restore saved x and y shifts
		img->setXShift(xShiftSave);
		img->setYShift(yShiftSave);
	}
开发者ID:Beliaar,项目名称:fifengine,代码行数:58,代码来源:imageloader.cpp

示例11: SDL_ConvertSurface

int Game::run()
{
	int retVal = 0;

	if (msurf_Screen)
	{
		if (!msurf_MapSurface)
		{
			msurf_MapSurface = SDL_ConvertSurface(msurf_Screen, msurf_Screen->format, msurf_Screen->flags);
		}

		if (msurf_MapSurface->w != Graphics::getScreenWidth() || msurf_MapSurface->h != Graphics::getScreenHeight())
		{
			if (msurf_MapSurface)
			{
				Graphics::free(msurf_MapSurface);
			}

			msurf_MapSurface = Graphics::zoom(msurf_Screen, Graphics::getScreenWidth(), Graphics::getScreenHeight(), true);
		}
	}

	SDL_Surface * screen = SDL_ConvertSurface(msurf_MapSurface, msurf_MapSurface->format, msurf_MapSurface->flags);

	Sound::resumeMusic();

	if (!Sound::musicPlaying())
	{
		//Sound::playMusic("GreenPillarAmbience.wav");
	}

	player->move(1, map->width(), map->height(), keyboard);
	
	player->draw(screen);
	Graphics::blit(screen);
	Graphics::free(screen);

	if (Input::keyHeld(SDLK_ESCAPE))
	{
		Sound::pauseMusic();
		retVal = MENU;
	}

	return retVal;
}
开发者ID:Qata,项目名称:TopDoom,代码行数:45,代码来源:Game.cpp

示例12: SetTransparency

/* use default 8x8 font */
GUI_Font::GUI_Font()
{
  SDL_Surface *temp=GUI_DefaultFont();
  fontStore=SDL_ConvertSurface(temp,temp->format,SDL_SWSURFACE);
  charh = fontStore->h/16;
  charw = fontStore->w/16;
  freefont=1;
  SetTransparency(1);
}
开发者ID:KIAaze,项目名称:iteam_hacking,代码行数:10,代码来源:GUI_font.cpp

示例13: throw

Texture::Texture (const Texture & rhs) throw (std::runtime_error) {
	Name = rhs.Name;
	if (rhs.Loaded) {
		Image = SDL_ConvertSurface(rhs.Image, rhs.Image->format, rhs.Image->flags);
	} else {
		Image = NULL;
	}
	Loaded = rhs.Loaded;
}
开发者ID:achernakov,项目名称:mine-bombers,代码行数:9,代码来源:texture.cpp

示例14: SDL_ConvertSurface

SDL_Surface *slideshow::convert_to_true_color(SDL_Surface *in)
{
	static const Uint32 surface_convert_mask 
		= SDL_SWSURFACE | SDL_HWSURFACE | SDL_SRCCOLORKEY | SDL_SRCALPHA;

	Uint32 flags = in->flags & surface_convert_mask;

	return SDL_ConvertSurface(in, &m_true_color_format, surface_convert_mask);
}
开发者ID:crutchwalkfactory,项目名称:motocakerteam,代码行数:9,代码来源:slideshow.cpp

示例15: SDL_ConvertSurface

Surface::Surface(SDL_Surface *s, SDL_PixelFormat *fmt, Uint32 flags) {
	dblbuffer = NULL;
	this->operator =(s);
	if (fmt!=NULL || flags!=0) {
		if (fmt==NULL) fmt = s->format;
		if (flags==0) flags = s->flags;
		raw = SDL_ConvertSurface( s, fmt, flags );
	}
}
开发者ID:NeoTheFox,项目名称:gmenu2x,代码行数:9,代码来源:surface.cpp


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