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


C++ SDL_CreateTextureFromSurface函数代码示例

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


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

示例1: free

bool Texture::loadFromFile(std::string path, SDL_Renderer* mR) {
	//Get rid of preexisting texture
	free();

	//The final texture
	SDL_Texture* newTexture = 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 {
		//Color key image
		SDL_SetColorKey(loadedSurface, SDL_TRUE,
				SDL_MapRGB(loadedSurface->format, 0, 0xFF, 0xFF));

		//Create texture from surface pixels
		newTexture = SDL_CreateTextureFromSurface(mR, loadedSurface);
		if (newTexture == NULL) {
			printf("Unable to create texture from %s! SDL Error: %s\n",
					path.c_str(), SDL_GetError());
		} else {
			//Get image dimensions
			mWidth = loadedSurface->w;
			mHeight = loadedSurface->h;
		}

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

	//Return success
	mTexture = newTexture;
	return mTexture != NULL;
}
开发者ID:miroslavavramov,项目名称:Memory-Game,代码行数:36,代码来源:Texture.cpp

示例2: Unload

void Images::Load(int i_id, string i_path, int i_x, int i_y, int i_mtime, int i_a, int i_atime)
{
	//detect that if it exist an images,unload it
	for (auto it = m_imgs.begin(); it != m_imgs.end(); ++it)
	if (it->id == i_id)
		Unload(i_id);
	//create a new texture struct and add it to the vector
	Image newImg;
	if (m_files->ReadRW(i_path, &(newImg.rw), newImg.index)){
		if (!(newImg.sur = IMG_Load_RW(newImg.rw, AUTOFREE))){
			SekaiAlert("cannot analyse the picture file from " + i_path);
			return;
		}
		newImg.tex = SDL_CreateTextureFromSurface(m_ren, newImg.sur);
        SDL_FreeSurface(newImg.sur);
		newImg.id = i_id;
		SDL_QueryTexture(newImg.tex, NULL, NULL, &(newImg.rect.w), &newImg.rect.h);
		newImg.rect.x = i_x;
		newImg.rect.y = i_y;
		newImg.a = i_a;
		newImg.path = i_path;
		m_imgs.push_back(newImg);
	}
}
开发者ID:Amarillys,项目名称:MaikazeSekai,代码行数:24,代码来源:[Core]Image.cpp

示例3: loadSurface

bool RenderManagerSDL::setBackground(const std::string& filename)
{
    try
    {
        SDL_Surface *tempBackgroundSurface = loadSurface(filename);
        SDL_Texture *tempBackgroundTexture = SDL_CreateTextureFromSurface(mRenderer, tempBackgroundSurface);
        BufferedImage* oldBackground = mImageMap["background"];
        SDL_DestroyTexture(oldBackground->sdlImage);
        delete oldBackground;

        BufferedImage* newImage = new BufferedImage;
        newImage->w = tempBackgroundSurface->w;
        newImage->h = tempBackgroundSurface->h;
        newImage->sdlImage = tempBackgroundTexture;
        SDL_FreeSurface(tempBackgroundSurface);
        mBackground = newImage->sdlImage;
        mImageMap["background"] = newImage;
    }
    catch (FileLoadException)
    {
        return false;
    }
    return true;
}
开发者ID:EliasOenal,项目名称:blobby,代码行数:24,代码来源:RenderManagerSDL.cpp

示例4: SDL_LoadBMP

bool Player::LoadTexture(std::string textureFile) {
    m_surface = SDL_LoadBMP(textureFile.c_str());
    if (!m_surface)
    {
        return false;
    }

    m_texture = SDL_CreateTextureFromSurface(m_sdlRenderer, m_surface);

    // centre the player on screen
    SDL_Rect displayRect;

    SDL_GetDisplayBounds(0, &displayRect);

    m_xPos = displayRect.w / 2;
    m_yPos = displayRect.h / 2;

    UpdateTexturePos();

    m_textureRect.w = m_surface->w;
    m_textureRect.h = m_surface->h;

    return true;
}
开发者ID:Saurbaum,项目名称:ClionSDL2,代码行数:24,代码来源:Player.cpp

示例5: maj_panneau

void maj_panneau(SDL_Renderer* ren, int nb_fleche[]){

    SDL_Texture *texture_directions = NULL;
    SDL_Surface *Directions = IMG_Load("IMG/Directions.png");
    texture_directions = SDL_CreateTextureFromSurface(ren,Directions);
    SDL_FreeSurface(Directions);
    SDL_Rect dst_directions;
    dst_directions.x = 730;
    dst_directions.y = 80;
    SDL_QueryTexture(texture_directions, NULL, NULL, &dst_directions.w, &dst_directions.h);
    SDL_RenderCopy(ren, texture_directions, NULL, &dst_directions);
    SDL_DestroyTexture(texture_directions);

    affichage_nb(ren,768,210,nb_fleche[0]);//d1
    affichage_nb(ren,818,210,nb_fleche[1]);//d2
    affichage_nb(ren,868,210,nb_fleche[2]);//d3
    affichage_nb(ren,768,160,nb_fleche[3]);//d4
    affichage_nb(ren,868,160,nb_fleche[5]);//d6
    affichage_nb(ren,768,110,nb_fleche[6]);//d7
    affichage_nb(ren,818,110,nb_fleche[7]);//d8
    affichage_nb(ren,868,110,nb_fleche[8]);//d9
    
    SDL_RenderPresent(ren);
}
开发者ID:Rorchar,项目名称:projetC,代码行数:24,代码来源:lv01.c

示例6: rand

//Initialization
void Bola::Init(SDL_Renderer *renderer){
    rect.h = BOLA_SIZE;
    rect.w = BOLA_SIZE;
    rect.y = WIN_HEIGHT/2;
    rect.x = WIN_WIDTH/2;
	//Iniciar con un angulo random, pero que nunca sea completamente horizontal o vertical
	int type = rand() % 4;
	switch (type)
	{
	case 0:	//15-75
		angle = rand() % 60 + 15;
		break;
	case 1: //105-165
		angle = rand() % 60 + 105;
		break;
	case 2: //195-255
		angle = rand() % 60 + 195;
		break;
	case 3://285-345
		angle = rand() % 60 + 285;
		break;
	}
    SDL_Surface *surf = IMG_Load("assets/pelota.png");
    imagen = SDL_CreateTextureFromSurface(renderer, surf);

	dx = dy = 0.0f;
	speed = 0.4f;
	rebotandoY = rebotandoX =  false;

	speedX = (float)cos(angle*M_PI / 180.0f) * speed;
	speedY = (float)sin(angle*M_PI / 180.0f) * speed;

	MAX_speed = speed *2;

	InitMedia();
}
开发者ID:jandujar,项目名称:multipong,代码行数:37,代码来源:Bola.cpp

示例7: loadFont

/* this function loads our font into an SDL_Texture and returns the SDL_Texture  */
SDL_Texture*
loadFont(void)
{

    SDL_Surface *surface = SDL_LoadBMP("kromasky_16x16.bmp");

    if (!surface) {
        printf("Error loading bitmap: %s\n", SDL_GetError());
        return 0;
    } else {
        /* set the transparent color for the bitmap font (hot pink) */
        SDL_SetColorKey(surface, 1, SDL_MapRGB(surface->format, 238, 0, 252));
        /* now we convert the surface to our desired pixel format */
        int format = SDL_PIXELFORMAT_ABGR8888;  /* desired texture format */
        Uint32 Rmask, Gmask, Bmask, Amask;      /* masks for desired format */
        int bpp;                /* bits per pixel for desired format */
        SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask,
                                   &Amask);
        SDL_Surface *converted =
            SDL_CreateRGBSurface(0, surface->w, surface->h, bpp, Rmask, Gmask,
                                 Bmask, Amask);
        SDL_BlitSurface(surface, NULL, converted, NULL);
        /* create our texture */
        texture =
            SDL_CreateTextureFromSurface(renderer, converted);
        if (texture == 0) {
            printf("texture creation failed: %s\n", SDL_GetError());
        } else {
            /* set blend mode for our texture */
            SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
        }
        SDL_FreeSurface(surface);
        SDL_FreeSurface(converted);
        return texture;
    }
}
开发者ID:Akitory4,项目名称:gplayer,代码行数:37,代码来源:keyboard.c

示例8: SDL_CreateTextureFromSurface

void Image::reload(SDL_Surface *surface) {
	m_filename = "";

	if(m_texture) SDL_DestroyTexture(m_texture);

	m_width = surface->w;
	m_height = surface->h;

	m_texture = SDL_CreateTextureFromSurface(GameWindow::main->renderer(), surface);
	SDL_SetTextureBlendMode(m_texture, SDL_BLENDMODE_BLEND);
	SDL_FreeSurface(surface);

	m_clipRect.x = 0;
	m_clipRect.y = 0;
	m_clipRect.w = m_width;
	m_clipRect.h = m_height;

	m_posRect.x = 0;
	m_posRect.y = 0;
	m_posRect.w = m_width;
	m_posRect.h = m_height;

	m_hidden = false;
}
开发者ID:Quent42340,项目名称:Asylia,代码行数:24,代码来源:Image.cpp

示例9: DEBUG_LOG

bool ResourceFontTexture::LoadResource(const std::string& text, ResourceFont font, SDL_Renderer * renderer, Color color)
{
	if (initialized)
	{
		DEBUG_LOG("Trying to load resource in already initialized instantion.");
		return false;
	}
	SDL_Surface * surface = TTF_RenderText_Solid(font.getFont(), text.c_str(), {color.r,color.g,color.b,color.a});
	if (surface == nullptr)
	{
		DEBUG_LOG("Error loading surface from font.");
		return false;
	}

	texture.reset(SDL_CreateTextureFromSurface(renderer, surface), SDL_DestroyTexture);
	SDL_FreeSurface(surface);
	if (texture == nullptr)
	{
		DEBUG_LOG("Failed to create texture from surface");
		return false;
	}
	initialized = true;
	return true;
}
开发者ID:Eresor,项目名称:Cziczaka,代码行数:24,代码来源:ResourceFontTexture.cpp

示例10: Object

Planet::Planet(std::string name):
	Object(),
	Drawable(),
	Touchable(),
	weaponAim_(0, 0)
{

	type_ = Assets::instance().info("Planet", name);

	b2BodyDef temp;
	temp.position = b2Vec2(0.0, 0.0);
	temp.type = b2_staticBody;
	CreateBody(temp, type_.def);

	laser_ = new Laser(GetBody());

	SDL_Log("Planet m=%f", GetMass());

	SDL_Surface* surface = Screen::CreateSurface(1, 1, 32);
	Uint32 color = SDL_MapRGBA(surface->format, 255, 90, 255, 250);
	SDL_FillRect(surface, NULL, color);

	texture_ = SDL_CreateTextureFromSurface(Screen::instance().renderer(), surface);
}
开发者ID:Deraen,项目名称:ohj2710,代码行数:24,代码来源:Planet.cpp

示例11: SDL_RWFromFile

void Image::reload(const char *filename) {
	m_filename = filename;

	if(m_texture) SDL_DestroyTexture(m_texture);

	SDL_RWops *image = SDL_RWFromFile(filename, "rb");
	SDL_Surface *surface = IMG_Load_RW(image, 1);

	if(!surface) {
		error("Failed to load image \"%s\": %s\n", filename, IMG_GetError());
		exit(EXIT_FAILURE);
	}

	m_width = surface->w;
	m_height = surface->h;

	m_texture = SDL_CreateTextureFromSurface(GameWindow::main->renderer(), surface);
	if(!m_texture) {
		error("Failed to create texture from image: %s", SDL_GetError());
		exit(EXIT_FAILURE);
	}
	SDL_SetTextureBlendMode(m_texture, SDL_BLENDMODE_BLEND);
	SDL_FreeSurface(surface);

	m_clipRect.x = 0;
	m_clipRect.y = 0;
	m_clipRect.w = m_width;
	m_clipRect.h = m_height;

	m_posRect.x = 0;
	m_posRect.y = 0;
	m_posRect.w = m_width;
	m_posRect.h = m_height;

	m_hidden = false;
}
开发者ID:Quent42340,项目名称:Asylia,代码行数:36,代码来源:Image.cpp

示例12: draw_msg

int draw_msg(SDL_Surface *screen, int x, int y, const char *msg)
{
	//SDL_Color bg={0x19,0x19,0x19,0x40};
	SDL_Color bg={0,0,0,0};
	SDL_Color fg={238,238,230,0x40};

        //defaultTextColor.setAllColors(238, 238, 230, 0x40);
        //colorDefaultWidgetBackground.setAllColors(0x19, 0x19, 0x19, 0x40);
	//SDL_Color bg={0,0,0,0};
	//SDL_Color fg={255,255,255,255};

	SDL_Surface *surf= TTF_RenderText_Shaded(font,msg,fg, bg);

        SDL_TextureID text = SDL_CreateTextureFromSurface(0, surf);

        //Central alignment for subtitle
        //x=(int) ((320.0*fs_screen_width/640.0) -(surf->w/2.0));

        SDL_Rect rect = {x, y, surf->w, surf->h };
        SDL_RenderCopy(text, NULL, &rect);

        SDL_FreeSurface(surf);
        SDL_DestroyTexture(text);
}
开发者ID:Alocaly,项目名称:dolphin-player.nextgen,代码行数:24,代码来源:broov_font.c

示例13: TTF_OpenFont

/* Set the Text */
SDL_Texture* Font::RenderText(const std::string &message, SDL_Color color,
                              int fontSize, SDL_Renderer *renderer)
{
	font = TTF_OpenFont(this->fontPath.c_str(), fontSize);
	if (!font){
		logging(TTF_GetError());
		return NULL;
	}
	surf = TTF_RenderText_Blended(font, message.c_str(), color);
	if (!surf){
		logging(TTF_GetError());
		return NULL;
	}
	SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surf);
	if (!texture){
		logging(TTF_GetError());
		return NULL;
	}

	TTF_CloseFont(font);
	font = NULL;
	SDL_FreeSurface(surf);
	return texture;
}
开发者ID:gdraynz,项目名称:super-bernard-land,代码行数:25,代码来源:Font.cpp

示例14: printf

void cGame::mWorldMapLoad(string path){
	if (!mIsLoaded()){
		if (!loadMedia(path.c_str())){
			printf("Failed to load media!\n");
		}
		else{
			mSetLoaded(true);
			//Set up player quad
			player1.mPlayerQuad.x = player1.getPlayerX();
			player1.mPlayerQuad.y = player1.getPlayerY();
			player1.mPlayerQuad.w = player1.getPlayerWidth();
			player1.mPlayerQuad.h = player1.getPlayerHeight();

			player1.mPlayerSurface = IMG_Load("Images/Character/hero_jimmy.png");
			player1.mPlayerTexture = SDL_CreateTextureFromSurface(mRenderer, player1.mPlayerSurface);

			player1.mPlayerSteps = 0;
			mRandomEncounter = rand() % 500;
			if (mRandomEncounter < 30)
				mRandomEncounter = rand() % 500;
		}
			mWorldMapUpdate();
	}
}
开发者ID:Relic1503,项目名称:RPGtheGame,代码行数:24,代码来源:game_worldmap.cpp

示例15: Free

bool Texture::Load(const std::string &Path, SDL_Renderer *const Renderer)
{
	Free();

	SDL_Texture *New=NULL;
	SDL_Surface *Surface=NULL;
	// Load the surface
	Surface=IMG_Load(Path.c_str());
	if(Surface==NULL)
	{
		Print("Failed to load file \""+Path+"\".");
		return false;
	}

	// Create texture
	New=SDL_CreateTextureFromSurface(Renderer, Surface);
	if(New==NULL)
	{
		SDL_FreeSurface(Surface);
		Print("Failed to create texture from Surface from file \""+Path+"\".");
		return false;
	}

	// Store the texture dimensions
	Width=Surface->w;
	Height=Surface->h;

	// Free up the memory
	SDL_FreeSurface(Surface);

	// Store the fully loaded texture
	Image=New;

	Print("Loaded image from \""+Path+"\".");
	return true;
}
开发者ID:hnefatl,项目名称:Pong,代码行数:36,代码来源:Texture.cpp


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