void Render_SW_SDL::renderTextureCur(float x, float y, float w, float h, float ani_top, float ani_bottom, float ani_left, float ani_right)
{
    if(!m_currentTexture)
    {
        renderRect(x, y, w, h,
                   (unsigned char)(255.f*color_binded_texture[0]),
                   (unsigned char)(255.f*color_binded_texture[1]),
                   (unsigned char)(255.f*color_binded_texture[2]),
                   (unsigned char)(255.f*color_binded_texture[3]) );
        return;
    }
    SDL_Rect sourceRect = {
        (int)roundf((float)m_currentTextureRect.width()*ani_left),
        (int)roundf((float)m_currentTextureRect.height()*ani_top),
        abs((int)roundf((float)m_currentTextureRect.width()*ani_right)-(int)roundf((float)m_currentTextureRect.width()*ani_left)),
        abs((int)roundf((float)m_currentTextureRect.height()*ani_bottom)-(int)roundf((float)m_currentTextureRect.height()*ani_top))
    };
    SDL_Rect destRect = scaledRect(x, y, w, h);
    SDL_SetTextureColorMod( m_currentTexture,
                            (unsigned char)(255.f*color_binded_texture[0]),
                            (unsigned char)(255.f*color_binded_texture[1]),
                            (unsigned char)(255.f*color_binded_texture[2]));
    SDL_SetTextureAlphaMod( m_currentTexture, (unsigned char)(255.f*color_binded_texture[3]));

    SDL_RenderCopy( m_gRenderer, m_currentTexture, &sourceRect, &destRect );
}
/**
 * @brief Test to see if can set texture color mode. Helper function.
 *
 * \sa
 * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureColorMod
 * http://wiki.libsdl.org/moin.cgi/SDL_GetTextureColorMod
 * http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
 */
static int
_hasTexColor (void)
{
   int fail;
   int ret;
   SDL_Texture *tface;
   Uint8 r, g, b;

   /* Get test face. */
   tface = _loadTestFace();
   if (tface == NULL)
      return 0;

   /* See if supported. */
   fail = 0;
   ret = SDL_SetTextureColorMod( tface, 100, 100, 100 );
   if (!_isSupported(ret))
      fail = 1;
   ret = SDL_GetTextureColorMod( tface, &r, &g, &b );
   if (!_isSupported(ret))
      fail = 1;

   /* Clean up. */
   SDL_DestroyTexture( tface );

   if (fail)
      return 0;
   else if ((r != 100) || (g != 100) || (b != 100))
      return 0;
   return 1;
}
Exemple #3
0
void GfxImage::VSetColor(byte r, byte g, byte b)
{
	m_color.r = r;
	m_color.g = g;
	m_color.b = b;
	SDL_SetTextureColorMod(m_pTexture, r, g, b);
}
void Sprite::draw()
{
	//scale stuff
    this-> s_width  = this -> width  * this -> scale;
    this-> s_height = this -> height * this -> scale;

	//Set rendering space and render to screen
	this -> rect =
	{ this -> pos . x - ( this -> s_width  / 2 ),
	  this -> pos . y - ( this -> s_height / 2 ),
	  this -> s_width, this -> s_height };

    const SDL_Rect * srcrect2 = & srcrect;
	const SDL_Rect * rect2 = & rect;

	//rotation center stuff
	center = { this -> s_width  / 2,
               this -> s_height / 2};
	SDL_Point * center2 = & center;

	//texture stuff
	SDL_SetTextureColorMod( texture, this -> red, this -> green, this -> blue );
    SDL_SetTextureAlphaMod( this -> texture, this -> alpha );
	//draw
	SDL_RenderCopyEx( renderer, texture, srcrect2, rect2, angle, center2, flip );
}
void Render_SW_SDL::renderTexture(PGE_Texture *texture, float x, float y, float w, float h, float ani_top, float ani_bottom, float ani_left, float ani_right)
{
    if(!texture) return;

    setRenderTexture( texture->texture );
    m_currentTextureRect.setRect( 0, 0, texture->w, texture->h );

    if(!m_currentTexture)
    {
        renderRect(x, y, w, h,
                   (unsigned char)(255.f*color_binded_texture[0]),
                   (unsigned char)(255.f*color_binded_texture[1]),
                   (unsigned char)(255.f*color_binded_texture[2]),
                   (unsigned char)(255.f*color_binded_texture[3]) );
        return;
    }

    SDL_Rect sourceRect = { (int)roundf((float)texture->w*ani_left), (int)roundf((float)texture->h*ani_top),
                            (int)roundf((float)texture->w*ani_right)-(int)roundf((float)texture->w*ani_left),
                            (int)roundf((float)texture->h*ani_bottom)-(int)roundf((float)texture->h*ani_top)
    };
    SDL_Rect destRect = scaledRect(x, y, w, h);
    SDL_SetTextureColorMod( m_currentTexture,
                            (unsigned char)(255.f*color_binded_texture[0]),
                            (unsigned char)(255.f*color_binded_texture[1]),
                            (unsigned char)(255.f*color_binded_texture[2]));
    SDL_SetTextureAlphaMod( m_currentTexture, (unsigned char)(255.f*color_binded_texture[3]));

    SDL_RenderCopy( m_gRenderer, m_currentTexture, &sourceRect, &destRect );
    setUnbindTexture();
}
//-------------------------------------------------------------------------------------------------
void Visuals::DrawSpriteOntoScreenBuffer(Uint16 index)
{
SDL_Rect destinationRect;
int windowWidth;
int windowHeight;
Uint32 textureFormat;
int textureAccess;
int textureWidth;
int textureHeight;

    SDL_GetWindowSize(Window, &windowWidth, &windowHeight);

    SDL_QueryTexture(Sprites[index].Texture, &textureFormat, &textureAccess, &textureWidth, &textureHeight);

    float winWidthFixed;
    float winHeightFixed;
    if (ForceAspectRatio == false)
    {
        winWidthFixed = (float)windowWidth / 640;
        winHeightFixed = (float)windowHeight / 480;
    }
    else
    {
        winWidthFixed = 1;
        winHeightFixed = 1;
    }

    destinationRect.x = ( Sprites[index].ScreenX * (winWidthFixed) )
                        - (  ( (textureWidth * Sprites[index].ScaleX) * (winWidthFixed) ) / 2  );
    destinationRect.y = ( Sprites[index].ScreenY * (winHeightFixed) )
                        - (  ( (textureHeight * Sprites[index].ScaleY) * (winHeightFixed) ) / 2  );
    destinationRect.w = textureWidth * Sprites[index].ScaleX * (winWidthFixed);
    destinationRect.h = textureHeight * Sprites[index].ScaleY * (winHeightFixed);

    SDL_SetTextureColorMod(Sprites[index].Texture, Sprites[index].RedHue, Sprites[index].GreenHue, Sprites[index].BlueHue);
    SDL_SetTextureAlphaMod(Sprites[index].Texture, Sprites[index].Transparency);

    if (Sprites[index].FlipX == false && Sprites[index].FlipY == false)
    {
        SDL_RenderCopyEx(Renderer, Sprites[index].Texture, NULL, &destinationRect, Sprites[index].RotationDegree
                         , NULL, SDL_FLIP_NONE);
    }
    else if (Sprites[index].FlipX == true && Sprites[index].FlipY == false)
    {
        SDL_RenderCopyEx(Renderer, Sprites[index].Texture, NULL, &destinationRect, Sprites[index].RotationDegree
                         , NULL, SDL_FLIP_HORIZONTAL);
    }
    else if (Sprites[index].FlipX == false && Sprites[index].FlipY == true)
    {
        SDL_RenderCopyEx(Renderer, Sprites[index].Texture, NULL, &destinationRect, Sprites[index].RotationDegree
                         , NULL, SDL_FLIP_VERTICAL);
    }
    else if (Sprites[index].FlipX == true && Sprites[index].FlipY == true)
    {
        double flipHorizontallyAndVerticallyDegreeFix = Sprites[index].RotationDegree+180;

        SDL_RenderCopyEx(Renderer, Sprites[index].Texture, NULL, &destinationRect, flipHorizontallyAndVerticallyDegreeFix
                         , NULL, SDL_FLIP_NONE);
    }
}
Exemple #7
0
void CApp::ResetMap(int mapIndex) {
    // remove all blocks
    for (auto itr = CBlock::BlockList.begin(); itr != CBlock::BlockList.end(); itr++) {
        CBlock* pBlock = *itr;
        if (pBlock) {
            pBlock->OnMove(-MAP_W, -MAP_H); // this will reset the tile if it was on its home
            delete pBlock;
        }
    }
    CBlock::BlockList.clear();

    CurrentMap = mapIndex;
    if (CurrentMap > highestLevel)
        highestLevel = CurrentMap;
    CMap* pMap = maps[mapIndex];
    ActionJackson.SetLoc(pMap->startX, pMap->startY);
    ActionJackson.map = pMap;
    ActionJackson.ClearUndoList();

    // place all blocks
    for (int i = 0; i < pMap->startBlocks.size(); i++) {
        SDL_Point p = pMap->startBlocks[i];
        CBlock* pBlock = new CBlock(p.x, p.y, pMap);
        pBlock->SetSpriteSheet(block);
        pBlock->OnMove(0, 0); // this will make the tile change to HOMEWITHBLOCK if applicable
        CBlock::BlockList.push_back(pBlock);
    }

    // add some flavor
    Uint8 redness = 2*(Uint8)CurrentMap;
    SDL_SetTextureColorMod(Texture, 255, 255 - redness, 255 - redness);
}
void Render_SW_SDL::renderTexture(PGE_Texture *texture, float x, float y)
{
    if(!texture) return;
    setRenderTexture( texture->texture );
    m_currentTextureRect.setRect( 0, 0, texture->w, texture->h );

    if(!m_currentTexture)
    {
        renderRect(x, y, texture->w, texture->h,
                   (unsigned char)(255.f*color_binded_texture[0]),
                   (unsigned char)(255.f*color_binded_texture[1]),
                   (unsigned char)(255.f*color_binded_texture[2]),
                   (unsigned char)(255.f*color_binded_texture[3]) );
        return;
    }

    SDL_Rect aRect = scaledRectIS(x, y, texture->w, texture->h);
    SDL_SetTextureColorMod( m_currentTexture,
                            (unsigned char)(255.f*color_binded_texture[0]),
                            (unsigned char)(255.f*color_binded_texture[1]),
                            (unsigned char)(255.f*color_binded_texture[2]));
    SDL_SetTextureAlphaMod( m_currentTexture, (unsigned char)(255.f*color_binded_texture[3]));

    SDL_RenderCopy( m_gRenderer, m_currentTexture, NULL, &aRect );
    setUnbindTexture();
}
Exemple #9
0
 void Sprite::setColor(int newR, int newG, int newB)
 {
     r = newR;
     g = newG;
     b = newB;
     SDL_SetTextureColorMod(texture, r, g, b);
 }
Exemple #10
0
    void Sprite::loadFromFile(string path, bool blending)
    {
        SDL_Surface* surface = IMG_Load(path.c_str());
        if (surface == NULL)
        {
            cout << "ERROR: " << IMG_GetError() << endl;
            return;
        }
        texture = SDL_CreateTextureFromSurface(renderer, surface);
        if (texture == NULL)
            cout << "ERROR: " << SDL_GetError() << endl;

        SDL_QueryTexture(texture, NULL, NULL, &w, &h);
        scale.w = w;
        scale.h = h;
        clip.x = 0;
        clip.y = 0;
        clip.h = h;
        clip.w = w;
        angle = 0;
        center.x = w / 2;
        center.y = h / 2;
        SDL_SetTextureColorMod(texture, r, g, b);
        setBlending(blending);
        SDL_FreeSurface(surface);
    }
Exemple #11
0
void
SDLRenderer::renderTexture(TextureProtocol* texture,
                           const vec2& position,
                           const vec2& anchor,
                           const vec2& scale,
                           float angle) {
    
    SDLTexture* _sdl = (SDLTexture*)texture;
    CPNullCheck(_sdl);
    
    // process source and destination rectangles.
    
    
    auto _rot = AffineTransform::rotationFromMatrix(_origin);
    auto _scale = AffineTransform::scaleFromMatrix(_origin);
    auto _pos = AffineTransform::applyTransform(_origin *
                                                AffineTransform::translate2D(position),
                                                vec2{0, 0});
    
    auto t = AffineTransform::translate2D(_pos) *
             AffineTransform::scale2D(_scale * vec2{fabsf(scale.x), fabsf(scale.y)});
    
    Rect destination = AffineTransform::applyTransform(t, Rect{
        -anchor.x * float(texture->clippingQuad().w),
        -anchor.y * float(texture->clippingQuad().h),
        float(texture->clippingQuad().w),
        float(texture->clippingQuad().h),
    });
    
    // prepare SDL types
    SDL_Rect srcRect = rectToSDL(_sdl->clippingQuad());
    SDL_Rect dstRect = rectToSDL(destination);
    SDL_Point center = {int(destination.w * anchor.x), int(destination.h * anchor.y)};
    
    // flip according to scale.
    int flip = SDL_FLIP_NONE;
    if(scale.x < 0) {
        flip |= SDL_FLIP_HORIZONTAL;
    }
    if(scale.y < 0) {
        flip |= SDL_FLIP_VERTICAL;
    }
    
    // SDL_Renderer calls
    SDL_SetTextureAlphaMod(_sdl->_hwTexture->raw(), _sdl->alpha() * 255);
    SDL_SetTextureColorMod(_sdl->_hwTexture->raw(),
                           _sdl->color().red * 255,
                           _sdl->color().green * 255,
                           _sdl->color().blue * 255);
    SDL_SetTextureBlendMode(_sdl->_hwTexture->raw(), sdlBlendMode(_sdl->blendMode()));
    
    SDL_RenderCopyEx(_renderer,
                     _sdl->_hwTexture->raw(),
                     &srcRect,
                     &dstRect,
                     -degrees(angle-_rot),
                     &center,
                     (SDL_RendererFlip)flip);
}
Pill::Pill(Field* field, Vector2 position, SDL_Color color) : Item(field, position)
{
	SDL_Texture* texture = FWApplication::GetInstance()->LoadTexture("pill.png");
	SDL_SetTextureColorMod(texture, color.r, color.g, color.b);

	SetTexture(texture);
	SetSize(50, 50);
}
Exemple #13
0
void apply_texture( int x, int y, int width, int height, SDL_Texture* source, double angle, Color color)
{
    //Make a temporary rectangle to hold the offsets
  SDL_Rect renderQuad = {x, y, width, height};
  //add the texture
  SDL_SetTextureColorMod(source, color.r, color.g, color.b); 
  SDL_RenderCopyEx( renderer, source, NULL, &renderQuad, angle, NULL, SDL_FLIP_NONE);
}
Exemple #14
0
void Enemy::Render()
{
    SDL_Rect r = { int(x)*SCREEN_MUL, int(y)*SCREEN_MUL,
                   width*SCREEN_MUL, height*SCREEN_MUL };
    Color c = level.Color();
    SDL_SetTextureColorMod(text.get(), c.r, c.g, c.b);
    SDL_RenderCopy(renderer, text.get(), nullptr, &r);
}
Exemple #15
0
d_define_method_override(label, set_maskRGB)(struct s_object *self, unsigned int red, unsigned int green, unsigned int blue) {
	d_using(label);
	label_attributes->last_mask_R = red;
	label_attributes->last_mask_G = green;
	label_attributes->last_mask_B = blue;
	SDL_SetTextureColorMod(label_attributes->image, red, green, blue);
	return self;
}
void StationSprite::render(SDL_Renderer* sdl_renderer, const Camera& camera, const Station& station) const
{
	SDL_Rect station_rect = 
	{ 
		renderutil::getScreenXForEntityByCameraAndDistance(station.current_state.pos.x*_scaling, _station_texture.rect.w*_scaling, renderer->width, camera, 1.0), 
		world->ship_limits.h * _scaling - _station_texture.rect.h * _scaling,
		_station_texture.rect.w*_scaling,
		_station_texture.rect.h*_scaling
	};

	if (station.is_docked)
		SDL_SetTextureColorMod(_station_texture.texture, 0, 0, 0);
	else
		SDL_SetTextureColorMod(_station_texture.texture, 255, 255, 255);

	SDL_RenderCopy(sdl_renderer, _station_texture.texture, &_station_texture.rect, &station_rect);
}
Exemple #17
0
void Texture::setColourTint(Colour c)
{
	//Set the texture colour tint or log an error.
	if (SDL_SetTextureColorMod(texture, c.r, c.g, c.b) != 0) 
	{
		Utility::log(Utility::W, "SDL_SetTextureColorMod failed in setColourTint");
	}
}
/**
 * @brief Blits doing color tests.
 *
 * \sa
 * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureColorMod
 * http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy
 * http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
 */
int
render_testBlitColor (void *arg)
{
   int ret;
   SDL_Rect rect;
   SDL_Texture *tface;
   SDL_Surface *referenceSurface = NULL;
   Uint32 tformat;
   int taccess, tw, th;
   int i, j, ni, nj;
   int checkFailCount1;
   int checkFailCount2;

   /* Create face surface. */
   tface = _loadTestFace();
   SDLTest_AssertCheck(tface != NULL, "Verify _loadTestFace() result");
   if (tface == NULL) {
       return TEST_ABORTED;
   }

   /* Constant values. */
   ret = SDL_QueryTexture(tface, &tformat, &taccess, &tw, &th);
   SDLTest_AssertCheck(ret == 0, "Verify result from SDL_QueryTexture, expected 0, got %i", ret);
   rect.w = tw;
   rect.h = th;
   ni     = TESTRENDER_SCREEN_W - tw;
   nj     = TESTRENDER_SCREEN_H - th;

   /* Test blitting with color mod. */
   checkFailCount1 = 0;
   checkFailCount2 = 0;
   for (j=0; j <= nj; j+=4) {
      for (i=0; i <= ni; i+=4) {
         /* Set color mod. */
         ret = SDL_SetTextureColorMod( tface, (255/nj)*j, (255/ni)*i, (255/nj)*j );
         if (ret != 0) checkFailCount1++;

         /* Blitting. */
         rect.x = i;
         rect.y = j;
         ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
         if (ret != 0) checkFailCount2++;
      }
   }
   SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
   SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);

   /* See if it's the same. */
   referenceSurface = SDLTest_ImageBlitColor();
   _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );

   /* Clean up. */
   SDL_DestroyTexture( tface );
   SDL_FreeSurface(referenceSurface);
   referenceSurface = NULL;

   return TEST_COMPLETED;
}
bool SetTextureColorMod( const SDL_Texture_Ptr &texture, Uint32 r, Uint32 g, Uint32 b )
{
    if( !texture ) {
        dbg( D_ERROR ) << "Tried to use a null texture";
        return true;
    }
    return printErrorIf( SDL_SetTextureColorMod( texture.get(), r, g, b ) != 0,
                         "SDL_SetTextureColorMod failed" );
}
Exemple #20
0
SDL_Texture* VsGameRenderer::renderGame() {

	SDL_Texture* gbq = _gbqr0.renderQueue();
	SDL_Texture* gbq2 = _gbqr1.renderQueue();

	SDL_SetRenderTarget(_SDLRenderer, _texture);
	SDL_SetRenderDrawColor(_SDLRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
	SDL_RenderClear(_SDLRenderer);

	SDL_RenderCopy(_SDLRenderer, _bg, NULL, NULL);
	SDL_RenderCopy(_SDLRenderer, _2pbg, NULL, NULL);

	if (!_game.isPaused()) {

		renderBoard(0);
		renderBoard(1);
		SDL_Rect gbqp = { 258, 307, 38, 120 };
		SDL_RenderCopy(_SDLRenderer, gbq, NULL, &gbqp);
		gbqp.x = 344;
		SDL_RenderCopy(_SDLRenderer, gbq2, NULL, &gbqp);
		renderParticles();

	}
	renderStatsText();
	renderMatchPoints();

	if (_game.isPaused()) {
		SDL_SetTextureColorMod(_texture, 0x50, 0x50, 0x50);
		SDL_RenderCopy(_SDLRenderer, _texture, NULL, NULL);
		SDL_SetTextureColorMod(_texture, 0xFF, 0xFF, 0xFF);
		_game.getPauseMenu().render();
	} else {
		SDL_SetTextureColorMod(_texture, 0xFF, 0xFF, 0xFF);
	}

	//TODO: make this state more fancy
	if (_game.getState() == Game::State::ENDED
			&& SDL_GetTicks() % 1000 >= 500) {
		_SDLContext.renderText("PUSH START", { 255, 255, 255 },
				_SDLContext._fontSquare, 134, 342);
	}

	return _texture;
}
Exemple #21
0
void textureDrawExt(Game* g, Texture* t, 
                    float x, float y, float w, float h,
                    float tX, float tY, float tW, float tH,
                    float originX, float originY,
                    float scaleX, float scaleY, float angle, float alpha,
                    bool additiveBlend, Color color)
{
    #ifdef OPENGL
    
        renderBatchDrawTextureExt(&g->renderBatch, t, x, y, w, h, tX, tY, tW, tH,
                                  originX, originY, angle, scaleX, scaleY, g);
        
    #else
        
        // TODO: Change the rotation implementation to match the OpenGL implementation.
        //       (Scale affects the rotation origin in this function)
        
        float scaleOffsetX = fabs(scaleX) * w * (originX / w);
        float scaleOffsetY = fabs(scaleY) * h * (originY / h);
        
        SDL_Rect dest = { 
            x - scaleOffsetX - roundf(g->camera.x) + originX, 
            y - scaleOffsetY - roundf(g->camera.y) + originY, 
            w *= fabs(scaleX), 
            h *= fabs(scaleY) 
        };
        
        int flip = 0;
        if(scaleX < 0)
            flip = flip | SDL_FLIP_HORIZONTAL;
        if(scaleY < 0)
            flip = flip | SDL_FLIP_VERTICAL;
        
        if(alpha > 1)
            alpha = 1;
        if(alpha < 0)
            alpha = 0;
        
        SDL_SetTextureColorMod(t->data, 
                               clampi((color.r * 255), 0, 255), 
                               clampi((color.g * 255), 0, 255), 
                               clampi((color.b * 255), 0, 255));
        SDL_SetTextureAlphaMod(t->data, alpha * color.a * 255);
        
        if(additiveBlend)
            SDL_SetTextureBlendMode(t->data, SDL_BLENDMODE_ADD);
        else
            SDL_SetTextureBlendMode(t->data, SDL_BLENDMODE_BLEND);
        
        SDL_Rect source = { tX, tY, tW, tH };
        SDL_Point center = { originX * scaleX, originY * scaleY };
        SDL_RenderCopyEx(g->renderer, t->data, &source, &dest, 
                         angle * 180 / PI, &center, flip);
                         
    #endif
} 
Exemple #22
0
void drawEffects(void)
{
	int i;
	Effect *e;

	SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);

	for (i = 0, e = effectsToDraw[i] ; e != NULL ; e = effectsToDraw[++i])
	{
		SDL_SetRenderDrawColor(app.renderer, e->r, e->g, e->b, e->a);

		SDL_SetTextureBlendMode(e->texture, SDL_BLENDMODE_ADD);
		SDL_SetTextureAlphaMod(e->texture, e->a);

		switch (e->type)
		{
			case EFFECT_POINT:
				SDL_RenderDrawPoint(app.renderer, e->x - battle.camera.x, e->y - battle.camera.y);
				break;

			case EFFECT_LINE:
				SDL_RenderDrawLine(app.renderer, e->x - battle.camera.x, e->y - battle.camera.y, e->x + (e->dx * 3) - battle.camera.x, e->y + (e->dy * 3) - battle.camera.y);
				break;

			case EFFECT_TEXTURE:
				SDL_SetTextureColorMod(e->texture, e->r, e->g, e->b);
				blitScaled(e->texture, e->x - battle.camera.x, e->y - battle.camera.y, e->size, e->size, 0);
				break;

			case EFFECT_HALO:
				SDL_SetTextureColorMod(e->texture, e->r, e->g, e->b);
				blitScaled(e->texture, e->x - battle.camera.x - (e->size / 2), e->y - battle.camera.y - (e->size / 2), e->size, e->size, 0);
				break;

			case EFFECT_ECM:
				SDL_SetTextureColorMod(e->texture, e->r, e->g, e->b);
				blitScaled(e->texture, SCREEN_WIDTH / 2 - (e->size / 2), SCREEN_HEIGHT / 2 - (e->size / 2), e->size, e->size, 0);
				break;
		}
	}

	SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
}
Exemple #23
0
void ttexture::draw(SDL_Renderer& renderer, const int x, const int y)
{
	SDL_Rect dstrect = create_rect(x, y, clip_.w * hscale_, clip_.h * vscale_);

	SDL_SetTextureAlphaMod(texture_, alpha_);
	SDL_SetTextureColorMod(texture_, mod_r_, mod_g_, mod_b_);
	SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, smooth_scaling_ ? "linear" : "nearest");
	SDL_RenderCopyEx(&renderer, texture_, &clip_, &dstrect,
					 rotation_, NULL, flip_);
}
Exemple #24
0
int 
texture_set_color(texture* img, Uint8 red, Uint8 green, Uint8 blue) {
	
	// http://wiki.libsdl.org/SDL_SetTextureColorMod
	if ( SDL_SetTextureColorMod(img->ref, red, green, blue) < 0 ) {
		printf("texture_set_color: color modulation err: %s\n", SDL_GetError());
	}
	
	return 0;
}
Exemple #25
0
/*
--------------------------------------------------------------------------------
                               RESTORE COLOR MOD
--------------------------------------------------------------------------------
 *  This method restores the texture's color mod from backup
*/
void Texture::restore_color_mod( void )
{
    /*  Get the original values */
    Uint8 r = mOriginalColorMod.r;
    Uint8 g = mOriginalColorMod.g;
    Uint8 b = mOriginalColorMod.b;

    /*  Set the texture color mod to those values */
    SDL_SetTextureColorMod( mTexture, r, g, b );
}
Exemple #26
0
bool RenderSystem::execute(){
	// Gets all regions that are currently visable
	std::vector<Region*> *active_regions = &MapManager::active_regions;
	if (renderer_ == nullptr || active_regions == nullptr)
		return false;
	//Loop through each visable region
	for (size_t r = 0; r < active_regions->size(); r++){
		Region *region = (*active_regions)[r];
		//Get a list of all entites inside the region that have a texture component
		std::vector<int> list = region->getEntityListOfComponents(Component::getNameFromEnum(Component::TEXTURE));
		for (size_t i = 0; i < list.size(); i++)
		{
			int entityID = list[i];
			//get the position and texture components
			PositionComponent *positionComp = Game::componentManager.getPositionComponent(entityID, *region);
			TextureComponent *textureComp = Game::componentManager.getTextureComponent(entityID, *region);
			//check if the entity has valid components for rendering
			if (positionComp != nullptr && textureComp != nullptr)
			{
				//set up the destination rectangle
				SDL_Rect destRect;
				destRect.x = positionComp->x + MapManager::get_view_x() * -16;
				destRect.y = positionComp->y + MapManager::get_view_y() * -16;
				destRect.w = textureComp->width;
				destRect.h = textureComp->height;

				//try to see if the entity is a map Tile by checking if it has a Tile Component
				TileComponent *tileComp = Game::componentManager.getTileComponent(entityID, *region);
				if (tileComp != nullptr)
				{
					//Seeing as it is a Tile we need to get the tile from the texture so we set up a source rectangle
					SDL_Rect srcRect = tileComp->srcrect;
					destRect.w = tileComp->tileSize;
					destRect.h = tileComp->tileSize;

					//Get the  tilesheet texture
					SDL_Texture *tex = *(&textureComp->tex);

					//If we have an elevation comp, add a tint to it give depth to the mountins
					ElevationComponent *elevationComp = Game::componentManager.getElevationComponent(entityID, *region);
					if (elevationComp != nullptr){
						int color = int(elevationComp->elevation * 128 + 128);
						SDL_SetTextureColorMod(tex, color, color, color);
					}
					//Render the tile
					SDL_RenderCopy(renderer_, tex, &srcRect, &destRect);
				}
				else
					//Render the texture
					SDL_RenderCopy(renderer_, textureComp->tex, NULL, &destRect);
			}
		}
	}
	return true;
}
Exemple #27
0
void game_render( void )
{
    SDL_RenderClear( render );
    for ( short i = 0; i < two_pole_size; i++ ) {
        if ( color[i] == 1 ) {
            SDL_SetTextureColorMod( tiles, 0, 100, 255 );
        } else {
            SDL_SetTextureColorMod( tiles, 255, 255, 255 );
        }
        tile_draw( render, tiles, pole[i%pole_size][i/pole_size], i );
    }
    if (draw_game_info) {
        SDL_Rect rectangle = { screen_width / 3, screen_height / 2 - 50, 230, 50 };
        SDL_SetRenderDrawColor( render, 0, 0, 255, 0 );
        SDL_RenderFillRect( render, &rectangle );
        SDL_SetRenderDrawColor( render, 0, 0, 0, 0 );
        font_draw(render, ft, game_info_text, screen_width / 3, screen_height / 2 - 45 );
    }
    SDL_RenderPresent( render );
}
void RenderManagerSDL::drawOverlay(float opacity, Vector2 pos1, Vector2 pos2, Color col)
{
    SDL_Rect ovRect;
    ovRect.x = (int)lround(pos1.x);
    ovRect.y = (int)lround(pos1.y);
    ovRect.w = (int)lround(pos2.x - pos1.x);
    ovRect.h = (int)lround(pos2.y - pos1.y);
    SDL_SetTextureAlphaMod(mOverlayTexture, lround(opacity * 255));
    SDL_SetTextureColorMod(mOverlayTexture, col.r, col.g, col.b);
    SDL_RenderCopy(mRenderer, mOverlayTexture, NULL, &ovRect);
}
void my_texture_set_color (MyTexture* self, guint8 red, guint8 green, guint8 blue) {
	SDL_Texture* _tmp0_ = NULL;
	guint8 _tmp1_ = 0U;
	guint8 _tmp2_ = 0U;
	guint8 _tmp3_ = 0U;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->texture;
	_tmp1_ = red;
	_tmp2_ = green;
	_tmp3_ = blue;
	SDL_SetTextureColorMod (_tmp0_, _tmp1_, _tmp2_, _tmp3_);
}
Exemple #30
0
static void DrawBackground(
	GraphicsDevice *g, SDL_Texture *tTgt, SDL_Texture *t, DrawBuffer *buffer,
	Map *map, const HSV tint, const struct vec2 pos, GrafxDrawExtra *extra)
{
	BlitClearBuf(g);
	DrawBufferSetFromMap(buffer, map, pos, X_TILES);
	DrawBufferDraw(buffer, svec2i_zero(), extra);
	BlitUpdateFromBuf(g, t);
	BlitClearBuf(g);
	const color_t mask = ColorTint(colorWhite, tint);
	if (SDL_SetTextureColorMod(t, mask.r, mask.g, mask.b) != 0)
	{
		LOG(LM_GFX, LL_ERROR, "cannot set background tint: %s",
			SDL_GetError());
	}
	if (SDL_SetTextureColorMod(tTgt, mask.r, mask.g, mask.b) != 0)
	{
		LOG(LM_GFX, LL_ERROR, "cannot set background tint: %s",
			SDL_GetError());
	}
}