void Ball::RenderBall(SDL_Renderer* sdlRenderer, SDL_Texture* pointDest, SDL_Texture* ballDest){
//    if(CApp::drawPath){
//        Point tempPoint(x , y);
//        pointAry.push_back(tempPoint);
//    }
//        for(int i = 0; i < pointAry.size(); i++){
//            pointAry[i].renderPoint(sdlRenderer);
//        }
    if(CApp::drawPath){
        SDL_Rect tempRect;
        tempRect.x = x;
        tempRect.y = y;
        tempRect.w = 1;
        tempRect.h = 1;
        SDL_SetRenderTarget(sdlRenderer, pointDest);//pointDest is the texture which to draw points on the positions that the ball has been on.
        SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 0, 255);
        SDL_RenderFillRect(sdlRenderer,&tempRect);

        SDL_SetRenderDrawColor(sdlRenderer,255,255,255,255);
    }
    SDL_SetRenderTarget(sdlRenderer, ballDest);

    SDL_Rect DestR = {round(x - (Width/2.0)) + CApp::scrollModifierX ,round(y - (Height/ 2.0)) + CApp::scrollModifierY,Width, Height};
    CTexture::OnDraw(sdlRenderer,Tex_Ball,&DestR);
    SDL_SetRenderTarget(sdlRenderer, NULL);
}
void TransformableViewScene::Render(SDL_Renderer *renderer)
{
	SDL_Rect srcrect;
	srcrect.x = 0;
	srcrect.y = 0;
	srcrect.w = targetSize.x;
	srcrect.h = targetSize.y;
    
	SDL_Rect dstrect;
	dstrect.x = origin.x;
	dstrect.y = origin.y;
	dstrect.w = size.x;
	dstrect.h = size.y;
    
	auto target = SDL_GetRenderTarget(renderer);
    
	int res = SDL_SetRenderTarget(renderer, renderTarget.get());
    
    Uint8 r,g,b,a;
    SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a);
    
    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
    SDL_RenderClear(renderer);
    
    SDL_SetRenderDrawColor(renderer, r, g, b, a);
    
	scene->Render(renderer);
    
	res = SDL_SetRenderTarget(renderer, target);
	
	res = SDL_SetTextureAlphaMod(renderTarget.get(), opacity * 255);
    
	//SDL_RenderCopy(renderer, renderTarget.get(), &srcrect, &dstrect);
	SDL_RenderCopyEx(renderer, renderTarget.get(), &srcrect, &dstrect, rotation, &axis, SDL_FLIP_NONE);
}
Beispiel #3
0
static void DrawBackgroundWithRenderer(
	GraphicsDevice *g, SDL_Renderer *renderer, SDL_Texture *target,
	SDL_Texture *src, DrawBuffer *buffer,
	const HSV tint, const struct vec2 pos, GrafxDrawExtra *extra)
{
	SDL_RendererInfo ri;
	if (SDL_GetRendererInfo(renderer, &ri) != 0)
	{
		LOG(LM_GFX, LL_ERROR, "cannot set render target: %s", SDL_GetError());
	}
	else
	{
		if (!(ri.flags & SDL_RENDERER_TARGETTEXTURE))
		{
			LOG(LM_GFX, LL_ERROR,
				"renderer does not support render to texture");
		}
	}
	if (SDL_SetRenderTarget(renderer, target) != 0)
	{
		LOG(LM_GFX, LL_ERROR, "cannot set render target: %s", SDL_GetError());
	}
	DrawBackground(g, target, src, buffer, &gMap, tint, pos, extra);
	if (SDL_SetRenderTarget(renderer, NULL) != 0)
	{
		LOG(LM_GFX, LL_ERROR, "cannot set render target: %s", SDL_GetError());
	}
}
Beispiel #4
0
Image* Image::cutFrame(int frame)
{
    if (frame > nframes) {
        printf("Frame nao existe - %d. Limit: %d\n", frame, nframes);
        return NULL;
    }

    SDL_Renderer* renderer = Game::getGlobalGame()->getRenderer();

//    printCut(frame);

    // Criar surface
    SDL_Texture* tex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,
                                         SDL_TEXTUREACCESS_TARGET, cut[0].w, cut[0].h);

    if(tex == NULL)
    {
        printf("SDL_CreateTexture failed: %s\n", SDL_GetError());
        return NULL;
    }

    SDL_SetRenderTarget(Game::getGlobalGame()->getRenderer(), tex);
    SDL_RenderCopy(renderer, picture, &cut[frame], 0 );
    SDL_SetRenderTarget(Game::getGlobalGame()->getRenderer(), 0);

    // Desenhar na surface o frame correspondente
    SDL_Rect offset;
    offset.x = offset.y = 0;

    return new Image(tex, 1, NULL, centerX, centerY);
}
Beispiel #5
0
void Engine::Graphics::draw(Camera * camera_, Sprite *sprite_, int x_, int y_, int width_, int height_, int frame_, int zIndex_) {

	SDL_Rect dstrect;
	dstrect.x = x_ - camera_->getX();
	dstrect.y = y_ - camera_->getY();
	dstrect.w = width_;
	dstrect.h = height_;

	//find or create the correct renderlayer
	struct RenderLayer *layer = getRenderLayer(zIndex_);

	SDL_SetRenderTarget(renderer, layer->texture); //sets the render target to a texture
	if (sprite_) {
		SDL_Rect srcrect;
		srcrect.x = sprite_->getFrameWidth() * frame_;
		srcrect.y = 0;
		srcrect.w = sprite_->getFrameWidth();
		srcrect.h = sprite_->getFrameHeight();
		SDL_RenderCopy(renderer, sprite_->getTexture(), &srcrect, &dstrect); //render to the texture
	}
	else { 	//draw a purple rectangle
		SDL_SetRenderDrawColor(renderer, 255, 0, 255, 255);
		SDL_RenderDrawRect(renderer, &dstrect);
	}
	SDL_SetRenderTarget(renderer, NULL); //reset the render target to the renderer
}
SDL_Texture* TextureFactory::CreateTiledSprite(Renderer *renderer, 
                                               SDL_Texture *base, 
                                               SDL_Rect baseLocation,
                                               int newWidth,
                                               int newHeight
                                               )
{
  Uint32 format;
  SDL_QueryTexture(base, &format, nullptr, nullptr, nullptr);

  SDL_Texture *texture = SDL_CreateTexture(renderer->GetRenderingContext(), 
    format, SDL_TEXTUREACCESS_TARGET, newWidth*baseLocation.w, newHeight*baseLocation.h);
  SDL_SetRenderTarget(renderer->GetRenderingContext(), texture);
  
  SDL_Rect dstLocation;
  dstLocation.w = baseLocation.w;
  dstLocation.h = baseLocation.h;

  for (int x = 0; x < newWidth; ++x)
  {
    for (int y = 0; y < newHeight; ++y)
    {
      dstLocation.x = x*baseLocation.w;
      dstLocation.y = y*baseLocation.h;
      SDL_RenderCopy(renderer->GetRenderingContext(), base, &baseLocation, &dstLocation);
    }
  }

  SDL_SetRenderTarget(renderer->GetRenderingContext(), nullptr);

  return texture;
}
Beispiel #7
0
PackedTextures::PackedTextures(SDL_Renderer * ren, std::vector<SDL_Texture *> & texVec, std::vector<SDL_Rect> & srcRect) {
	int sum_height=0;
	int max_width = 0;
	SDL_Rect tRect;
	tRect.x = 0;
	for( int i=0; i<texVec.size(); i++) {
		tRect.w = srcRect[i].w;
		tRect.h = srcRect[i].h;

		if( max_width < tRect.w )
			max_width = tRect.w;
		tRect.y = sum_height;
		sum_height += tRect.h;
		placements.push_back(tRect);
	}

	packedTexture = SDL_CreateTexture(ren, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, max_width, sum_height);
	SDL_SetTextureBlendMode(packedTexture, SDL_BLENDMODE_NONE);

	SDL_Texture * pTarget = SDL_GetRenderTarget(ren);
	printf("Pack prev-renderer: %i\n",pTarget);
	printf("Pack new-texture: %i\n",packedTexture);
	SDL_SetRenderTarget(ren, packedTexture);
	SDL_SetRenderDrawColor(ren, 0, 0, 0, SDL_ALPHA_TRANSPARENT);
	SDL_RenderClear(ren);

	for( int i=0; i<texVec.size(); i++) {
		SDL_RenderCopy(ren, texVec[i], &srcRect[i], &placements[i]);
	}

	SDL_SetRenderTarget(ren, pTarget);
	SDL_SetTextureBlendMode(packedTexture, SDL_BLENDMODE_BLEND);
}
Beispiel #8
0
void FadeScene::Render(SDL_Renderer *renderer)
{
	SDL_Rect rect;
	rect.x = 0;
	rect.y = 0;
	rect.w = _w;
	rect.h = _h;

	auto target = SDL_GetRenderTarget(renderer);

	int res = SDL_SetRenderTarget(renderer, _renderTarget.get());
	_scene->Render(renderer);
	res = SDL_SetRenderTarget(renderer, target);
	
	if (_scene->Running() && _opacity != 255)
	{
		_opacity = std::min(_opacity + _speed, 255.0);
	}
	else if (!_scene->Running() && _opacity != 0)
	{
		_opacity = std::max(_opacity - _speed, 0.0);
	}

	res = SDL_SetTextureAlphaMod(_renderTarget.get(), _opacity);

	SDL_RenderCopy(renderer, _renderTarget.get(), &rect, &rect);
}
Beispiel #9
0
void Button::SetText(SDL_Renderer* renderer, TTF_Font* font, std::string s, SDL_Color color) {
	//make the surface (from SDL_ttf)
	SDL_Surface* surf = TTF_RenderText_Solid(font, s.c_str(), color);
	if (!surf) {
		throw(std::runtime_error("Failed to create a TTF surface"));
	}

	//convert to texture
	SDL_Texture* text = SDL_CreateTextureFromSurface(renderer, surf);
	SDL_FreeSurface(surf);
	if (!text) {
		throw(std::runtime_error("Failed to create a TTF texture"));
	}

	//get the dimensions & rects
	int x, y, w, h;
	SDL_QueryTexture(text, nullptr, nullptr, &w, &h);
	x = (image.GetClipW() - w) / 2;
	y = (image.GetClipH() - h) / 2;
	SDL_Rect src = {0, 0, w, h};
	SDL_Rect dst;

	//draw the text to the background
	SDL_SetRenderTarget(renderer, image.GetTexture());

	for (int i = 0; i < 3; i++) {
		dst = {x, y + image.GetClipH() * i, w, h};
		SDL_RenderCopy(renderer, text, &src, &dst);
	}

	SDL_SetRenderTarget(renderer, nullptr);

	//free the texture
	SDL_DestroyTexture(text);
}
Beispiel #10
0
bool Label::onDraw(SDL_Renderer *renderer) {
    //SDL_Texture *oldTarget;
    //oldTarget = SDL_GetRenderTarget(renderer);

    SDL_Texture *oldTarget = SDL_GetRenderTarget(renderer);
    SDL_SetRenderTarget(renderer, _texture);

    SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, bgColor.a);
    SDL_RenderClear(renderer);
    SDL_Rect dst = {0, 0, 0, 0};

    SDL_QueryTexture(label, NULL, NULL, &dst.w, &dst.h);
    dst.x = (frame.w - dst.w) / 2;
    dst.y = (frame.h - dst.h) / 2;

    dst.w += padding.x + padding.w;
    dst.h += 8;
    LOGD("%dx%d%+d%+d\n", dst.x, dst.y, dst.w, dst.h);

    SDL_RenderCopy(renderer, label, NULL, &dst);
    SDL_SetRenderDrawColor(renderer, 0,0,0,255);

    dirty = false;
    SDL_SetRenderTarget(renderer, oldTarget);
}
Beispiel #11
0
void Range::generateTexture(SDL_Renderer * renderer)
{
    if(texture != nullptr)
    {
        SDL_DestroyTexture(texture);
        texture = nullptr;
    }

    setWidth(value * 2);
    setHeight(value * 2);

    SDL_Texture * prevRenderTarget = SDL_GetRenderTarget(renderer);
    texture = SDL_CreateTexture(renderer,SDL_PIXELFORMAT_UNKNOWN,SDL_TEXTUREACCESS_TARGET,getWidth(),getHeight());
    SDL_SetTextureBlendMode(texture,SDL_BLENDMODE_BLEND);

    SDL_SetRenderTarget(renderer,texture);
    SDL_SetRenderDrawColor(renderer,0,0,0,0);
    SDL_RenderClear(renderer);
    SDL_SetRenderDrawColor(renderer,255,0,0,255);



    for(double i = 0; i<=360; i+=0.01)
    {
        int x = value + value * cos(i);
        int y = value + value * sin(i);

        SDL_RenderDrawPoint(renderer,x,y);
    }




    SDL_SetRenderTarget(renderer,prevRenderTarget);
}
Image* SDLHardwareImage::resize(int width, int height) {
	if(!surface || width <= 0 || height <= 0)
		return NULL;

	SDLHardwareImage *scaled = new SDLHardwareImage(device, renderer);
	if (!scaled) return NULL;

	scaled->surface = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width, height);

	if (scaled->surface != NULL) {
		// copy the source texture to the new texture, stretching it in the process
		SDL_SetRenderTarget(renderer, scaled->surface);
		SDL_RenderCopyEx(renderer, surface, NULL, NULL, 0, NULL, SDL_FLIP_NONE);
		SDL_SetRenderTarget(renderer, NULL);

		// Remove the old surface
		this->unref();
		return scaled;
	}
	else {
		delete scaled;
	}

	return NULL;
}
Beispiel #13
0
static void VL_SDL2_Present(void *surface, int scrlX, int scrlY)
{
	// TODO: Verify this is a VL_SurfaceUsage_FrontBuffer
	VL_SDL2_ResizeWindow();
	SDL_Surface *surf = (SDL_Surface *)surface;
	SDL_Rect srcr = {(Sint16)scrlX, (Sint16)scrlY, VL_EGAVGA_GFX_WIDTH, VL_EGAVGA_GFX_HEIGHT};
	SDL_Rect integerRect = {0, 0, vl_integerWidth, vl_integerHeight};
	SDL_Rect renderRect = {(Sint16)vl_renderRgn_x, (Sint16)vl_renderRgn_y, vl_renderRgn_w, vl_renderRgn_h};
	SDL_Rect fullRect = {(Sint16)vl_fullRgn_x, (Sint16)vl_fullRgn_y, vl_fullRgn_w, vl_fullRgn_h};

	SDL_BlitSurface(surf, &srcr, vl_sdl2_stagingSurface, 0);
	SDL_UpdateTexture(vl_sdl2_texture, 0, vl_sdl2_stagingSurface->pixels, vl_sdl2_stagingSurface->pitch);
	SDL_SetRenderTarget(vl_sdl2_renderer, vl_sdl2_scaledTarget);
	SDL_SetRenderDrawColor(vl_sdl2_renderer,
		VL_EGARGBColorTable[vl_emuegavgaadapter.bordercolor][0],
		VL_EGARGBColorTable[vl_emuegavgaadapter.bordercolor][1],
		VL_EGARGBColorTable[vl_emuegavgaadapter.bordercolor][2],
		255);
	SDL_RenderClear(vl_sdl2_renderer);
	SDL_RenderCopy(vl_sdl2_renderer, vl_sdl2_texture, 0, &renderRect);
	SDL_SetRenderTarget(vl_sdl2_renderer, 0);
	SDL_SetRenderDrawColor(vl_sdl2_renderer, 0, 0, 0, 255);
	SDL_RenderClear(vl_sdl2_renderer);

	SDL_RenderSetViewport(vl_sdl2_renderer, 0);
	SDL_RenderCopy(vl_sdl2_renderer, vl_sdl2_scaledTarget, 0, &fullRect);

	SDL_RenderPresent(vl_sdl2_renderer);
}
Beispiel #14
0
void render()
{
  if(quit)
    return;
  //clear renderer
  SDL_SetRenderTarget(renderer, NULL);
  SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
  SDL_RenderClear(renderer);

  //clear camera
  SDL_SetRenderTarget(renderer, camera.game_texture.sdl_texture);
  SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
  SDL_RenderClear(renderer);

  render_board(&board);
  render_striker(&striker);
  render_chips();

  if(game_state == PLAY && striker.state == WITH_PLAYER)
  {
    render_orientation(&striker);
  }


  //render camera in viewport
  SDL_SetRenderTarget(renderer, NULL);
  SDL_Rect dest_rect = { VIEWPORT_X, VIEWPORT_Y, VIEWPORT_HEIGHT, VIEWPORT_WIDTH };
  SDL_RenderCopy(renderer, camera.game_texture.sdl_texture, NULL, &dest_rect);
  

  if(game_state == MAIN_MENU)
  {
    render_main_menu();
  }

  if(game_state == INSTRUCTION)
  {
    render_instructions();
  }

  if(game_state == GAME_OVER)
  {
    render_game_over_state();
  }

  if(game_state == PLAY && striker.state == WITH_PLAYER)
  {
    render_speed(&striker);
    // render_orientation_text(&striker);
  }

  if(game_state == PLAY)
  {
    render_main_instruction();
  }

  render_scores();
  SDL_RenderPresent(renderer);
}
void SDLHardwareRenderDevice::blankScreen() {
	SDL_SetRenderDrawColor(renderer, background_color.r, background_color.g, background_color.b, background_color.a);
	SDL_SetRenderTarget(renderer, NULL);
	SDL_RenderClear(renderer);
	SDL_SetRenderTarget(renderer, texture);
	SDL_RenderClear(renderer);
	return;
}
Beispiel #16
0
void Cursor::clearRingTexture() {
  SDL_Renderer *r{Image::sdl_renderer()};
  // Clear out the render target for the cursor.
  SDL_SetRenderTarget(r, m_target);
  SDL_SetRenderDrawColor(r, 0x00, 0x00, 0x00, 0x0);
  SDL_RenderClear(r);
  SDL_SetRenderTarget(r, nullptr);
}
/*
 * Set the pixel at (x, y) to the given value
 */
void SDLHardwareImage::drawPixel(int x, int y, const Color& color) {
	if (!surface) return;

	SDL_SetRenderTarget(renderer, surface);
	SDL_SetTextureBlendMode(surface, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
	SDL_RenderDrawPoint(renderer, x, y);
	SDL_SetRenderTarget(renderer, NULL);
}
Beispiel #18
0
void SpriteBatch::sbSetRenderTarget(SDL_Texture *target)
{
    if(target == nullptr)
        SDL_SetRenderTarget(__renderer, nullptr);
    else
        SDL_SetRenderTarget(__renderer, target);

    this->__target = target;
}
void SDLHardwareImage::fillWithColor(const Color& color) {
	if (!surface) return;

	SDL_SetRenderTarget(renderer, surface);
	SDL_SetTextureBlendMode(surface, SDL_BLENDMODE_BLEND);
	SDL_SetRenderDrawColor(renderer, color.r, color.g , color.b, color.a);
	SDL_RenderClear(renderer);
	SDL_SetRenderTarget(renderer, NULL);
}
Beispiel #20
0
void
SDLRenderer::popTarget() {
    _targetStack.pop_back();
    if(_targetStack.size() > 0) {
        SDL_SetRenderTarget(_renderer, ((ARC<SDLTexture>)_targetStack.back())->_hwTexture->raw());
    }
    else {
        SDL_SetRenderTarget(_renderer, nullptr);
    }
}
Beispiel #21
0
void XDL_SpriteBatch::Begin()//begin clears the screen and creates a new texture for us to draw to.
{
	SDL_SetRenderDrawColor(_renderer,XDL_Game::_r,XDL_Game::_g,XDL_Game::_b,255);
	SDL_SetRenderTarget(_renderer, XDL_SpriteBatch::_drawTexture);//target the drawTexture so we can clear it.
	SDL_RenderCopy(_renderer,_clearTexture,NULL,NULL);//clear it
	SDL_SetRenderTarget(_renderer, NULL);//then change focus back to the screen

	SDL_RenderClear(_renderer);//and clear it
	_thingsToBeDrawn.clear();//remove all items that need to be drawn so we start with a blank slate
}
Beispiel #22
0
SDL_Texture* Card::loadShadow(SDL_Renderer* r) {
    SDL_Texture* newTexture = SDL_CreateTexture( r, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, 100 , 100 );
    SDL_SetRenderTarget( r, newTexture );

    SDL_SetRenderDrawColor( r, 0x20, 0x20, 0x20, 0xFF );
    SDL_RenderFillRect( r , NULL );

    SDL_SetRenderTarget( r, NULL );
    return newTexture;
}
Beispiel #23
0
void MenuState::draw(double dt){
	auto renderer = m_game->renderer();

	SDL_SetRenderTarget(renderer, m_drawtex);
	SDL_SetRenderDrawColor(renderer, 0, 100, 200, 0);
	SDL_RenderClear(renderer);
	//return;

	entityx::ComponentHandle<Position> position;
	// entityx::ComponentHandle<Drawable> drawable;


	for(entityx::Entity entity: m_entities.entities_with_components(position)){
		(void) entity;

		glm::vec2 pos = position->position();

		auto drawable = entity.component<Drawable>();
		auto textitem = entity.component<TextItem>();
		if(drawable){
			SDL_Rect dest;
			dest.x = pos.x;
			dest.y = pos.y;

			dest.w = drawable->width();
			dest.h = drawable->height();

			SDL_Rect* src;
			AnimTemplate anim = drawable->anim();
			if (anim.frame_width() == 0 || anim.frame_height() == 0) {
				src = nullptr;
			} else {
				SDL_Rect s;
				s.x = anim.frame_width() * drawable->animation_index();
				s.y = anim.frame_height() * anim.y_index();
				s.w = anim.frame_width();
				s.h = anim.frame_height();
				drawable->tick(dt);
				src = &s;
			}

			SDL_Texture* tex = m_game->res_manager().texture(drawable->texture_key());
			(void)tex;(void)dest;(void)src;
			SDL_RenderCopyEx(m_game->renderer(), tex, src, &dest, 0, nullptr, SDL_FLIP_NONE);
		}

		if(textitem){
			draw_text(m_game->renderer(), m_game->res_manager(), textitem->text(), textitem->font_key(), pos.x, pos.y, textitem->color());
		}
	}

	SDL_SetRenderTarget(renderer, nullptr);
	SDL_RenderCopy(renderer, m_drawtex, &m_camera, nullptr);
	SDL_RenderPresent(renderer);
}
Beispiel #24
0
void EmuinoSDL::render()
{
    if (!setup) return;
    
    renderTiles();
    
    SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
    
    SDL_UpdateTexture(screenTexture, NULL, screenSurface->pixels, screenSurface->pitch);
    
    // get camera offset
    int16_t camX = 0, camY = 0;
    
    SharedRAM.read(REG_SCROLL_X | 0x8000, &camX, 2);
    SharedRAM.read(REG_SCROLL_Y | 0x8000, &camY, 2);
    
    // render everything on the screen texture such as sprites and tilemaps
    SDL_SetRenderTarget(renderer, screenTexture);
    for (int i = 0; i < NUM_TILE_LAYERS; i++) {
        int16_t offsetX, offsetY;
        int w = tileMapSurfaces[i]->w;
        int h = tileMapSurfaces[i]->h;
        SharedRAM.read(TILE_LAYER_REG(i, TILE_OFFSET_X) | 0x8000, &offsetX, 2);
        SharedRAM.read(TILE_LAYER_REG(i, TILE_OFFSET_Y) | 0x8000, &offsetY, 2);
        
        // add camera offset
        offsetX -= camX;
        offsetY -= camY;
        
        // hacky repetition, will need to be replaced with proper OpenGL texture repetition
        offsetX = offsetX % w;
        if (offsetX < 0)
            offsetX += w;
        
        offsetY = offsetY % h;
        if (offsetY < 0)
            offsetY += w;
        
        SDL_Rect offsetRect = {offsetX, offsetY, w, h};
        SDL_RenderCopy(renderer, tileMapTextures[i], NULL, &offsetRect);
        offsetRect.x -= w;
        SDL_RenderCopy(renderer, tileMapTextures[i], NULL, &offsetRect);
        offsetRect.y -= w;
        SDL_RenderCopy(renderer, tileMapTextures[i], NULL, &offsetRect);
        offsetRect.x = offsetX;
        SDL_RenderCopy(renderer, tileMapTextures[i], NULL, &offsetRect);
    }
    SDL_SetRenderTarget(renderer, NULL);
    
    // render the screen texture
    SDL_RenderClear(renderer);
    SDL_RenderCopy(renderer, screenTexture, NULL, NULL);
    SDL_RenderPresent(renderer);
}
Beispiel #25
0
void Box(int x, int y, int w, int h, int angle, int r, int g, int b, int a){
	SDL_Rect rect = {x, y, w, h};
	SDL_Texture * texture = SDL_CreateTexture(gfx.renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, w, h);
	SDL_SetRenderTarget(gfx.renderer, texture);
	SDL_SetRenderDrawColor(gfx.renderer, r, g, b, a);
	SDL_RenderClear(gfx.renderer);
	SDL_SetRenderTarget(gfx.renderer, NULL);
	SDL_RenderCopyEx(gfx.renderer, texture, NULL, &rect, angle, NULL, SDL_FLIP_NONE);
	SDL_DestroyTexture(texture);

}
Beispiel #26
0
/**
* \fn int displayMap(sInterface *p_interface, sMap *p_map)
* \brief Fonction qui initialise les graphismes de la map
*
* \param *p_interface pointeur vers une structure de type sInterface
* \param *p_map pointeur vers une structure de type sMap
* \return int représentant le déroulement de la fonction
*/
int displayMap(sInterface *p_interface, sMap *p_map) {
	int l_i, l_j;
	
	SDL_Rect l_posCase, l_arbre;
	SDL_Surface *l_sprite;
	SDL_Texture *l_texture;

	l_posCase.x = 0;
	l_posCase.y = 0;
	l_posCase.h = WINDOW_HEIGHT / CASE_LINE_AMOUNT;
	l_posCase.w = WINDOW_WIDTH / CASE_COLUMN_AMOUNT;

	SDL_SetRenderTarget(p_interface->renderer, p_interface->backgroundSprite);
	SDL_SetRenderDrawColor(p_interface->renderer, 0, 0, 0, 0);
	SDL_RenderClear(p_interface->renderer);

	for (l_i = 0; l_i < p_map->mapDimension.height; ++l_i) {
			for (l_j = 0; l_j < p_map->mapDimension.width; ++l_j) {
						
				SDL_RenderCopy(p_interface->renderer, p_interface->caseSprite[0], NULL, &l_posCase);
				SDL_RenderCopy(p_interface->renderer, p_interface->caseSprite[p_map->path[l_i][l_j].type], NULL, &l_posCase );
				if ((l_i == 0 || l_j == 0 || l_i == 9 || l_j == 9) && (p_map->path[l_i][l_j].type == 2)) {
					l_arbre = l_posCase;
					//l_arbre.x += (rand() % 10) - 5;
					//l_arbre.y += (rand() % 10) - 5;
					l_sprite = IMG_Load("./assets/sprite/tree_0.png");
					l_texture = SDL_CreateTextureFromSurface(p_interface->renderer, l_sprite);
					SDL_FreeSurface(l_sprite);
					SDL_RenderCopy(p_interface->renderer, l_texture, NULL, &l_arbre);
				}

			if (p_map->starting.y == l_i && p_map->starting.x == l_j) {
				l_sprite = IMG_Load("./assets/sprite/start.png");
				l_texture = SDL_CreateTextureFromSurface(p_interface->renderer, l_sprite);
				SDL_FreeSurface(l_sprite);
				SDL_RenderCopy(p_interface->renderer, l_texture, NULL, &l_posCase);
			}
			if (p_map->ending.y == l_i && p_map->ending.x == l_j) {
				l_sprite = IMG_Load("./assets/sprite/goal.png");
				l_texture = SDL_CreateTextureFromSurface(p_interface->renderer, l_sprite);
				SDL_FreeSurface(l_sprite);
				SDL_RenderCopy(p_interface->renderer, l_texture, NULL, &l_posCase);
			}
			l_posCase.x += WINDOW_WIDTH / CASE_COLUMN_AMOUNT;
		}
		l_posCase.x = 0;
		l_posCase.y += WINDOW_HEIGHT / CASE_LINE_AMOUNT;
	}

	SDL_SetRenderTarget(p_interface->renderer, NULL);

	return 0;
}	
Beispiel #27
0
void Simulation::Render()
{
    SDL_Renderer *renderer = Game::getGlobalGame()->getRenderer();

    Game::getGlobalGame()->setBackgroundColor(0, 0, 0);

    // Render do Fundo
//    SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_ADD);
    SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);

    drawBG(background[0], bgOffsetX, bgOffsetY, -0.1, renderer);
    drawBG(background[1], bgOffsetX, bgOffsetY, -0.13, renderer);
    drawBG(background[2], bgOffsetX, bgOffsetY, -0.2, renderer);
    drawBG(background[3], bgOffsetX, bgOffsetY, -0.28, renderer);
//    background[0]->DrawImage(bgOffsetX*0.10, bgOffsetY*0.10, renderer);
//    background[1]->DrawImage(bgOffsetX*0.13, bgOffsetY*0.13, renderer);
//    background[2]->DrawImage(bgOffsetX*0.20, bgOffsetY*0.20, renderer);
//    background[3]->DrawImage(bgOffsetX*0.28, bgOffsetY*0.28, renderer);

//    background->DrawImage(bgOffsetX, bgOffsetY, renderer);
//    background->DrawImage(bgOffsetX + Game::getGlobalGame()->getWidth(),
//                          bgOffsetY + Game::getGlobalGame()->getHeight(), renderer);
//
//    background->DrawImage(bgOffsetX + Game::getGlobalGame()->getWidth(), bgOffsetY, renderer);
//    background->DrawImage(bgOffsetX, bgOffsetY + Game::getGlobalGame()->getHeight(), renderer);

    //Just TESTING
    SDL_SetRenderTarget(renderer, renderCombat);
        // Limpar textura
        SDL_SetTextureBlendMode(renderCombat, SDL_BLENDMODE_BLEND);
        SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
        SDL_RenderClear(renderer);

        SDL_SetRenderDrawBlendMode(renderer, SDL_BlendMode::SDL_BLENDMODE_NONE);
        SDL_SetTextureBlendMode(renderCombat, SDL_BLENDMODE_BLEND);

        simulationWorld->render();
    SDL_SetRenderTarget(renderer, 0);

    // Renderizar imagem de combate na tela
    SDL_Rect rect;
    rect.x = -camera->getX();  rect.w = 2048;
    rect.y = -camera->getY();  rect.h = 2048;

    SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
    SDL_SetRenderDrawBlendMode(renderer, SDL_BlendMode::SDL_BLENDMODE_NONE);
    SDL_RenderCopy( renderer, renderCombat, 0, &rect);

    if(selectedUnit)
    {
        filledCircleRGBA( renderer, selectedUnit->getAvgX(), selectedUnit->getAvgY(), 64, 0, 0, 255, 128 );
    }
}
Beispiel #28
0
void Engine::Graphics::flipBuffer() {
	SDL_RenderClear(renderer); //clears the renderer
	struct RenderLayer *i = &zeroLayer;
	while (i != NULL) {
		SDL_RenderCopy(renderer, i->texture, NULL, NULL); //blits the texture to the renderer
		SDL_SetRenderTarget(renderer, i->texture); //sets the render target to the texture
		SDL_RenderClear(renderer); //clears the texture
		SDL_SetRenderTarget(renderer, NULL); //resets the render target
		i = i->next;
	}
	SDL_RenderPresent(renderer);
}
Beispiel #29
0
void DrawGame(GameRenderer* g, World* world)
{
	CheckResize(g, world);
	//Prepare to render to texture.
	SDL_SetRenderTarget(g->renderer, g->gameTexture);
	
	//Clear screen
	SDL_SetRenderDrawColor( g->renderer, 0xFF, 0xFF, 0xFF, 0xFF );
	SDL_RenderClear( g->renderer );
	
	//Draw our grid
	//Resizing the background grid looks terrible.
	if(g->zoom >= 0)
	{
		DrawBackgroundGrid( g->renderer, g->screenGame.w, g->screenGame.h, &g->gridProps );		
	}
	DrawCells(g->renderer, &g->gridProps, world);		
	SDL_RenderPresent( g->renderer );

	//Now draw the rest of the screen
	SDL_SetRenderTarget(g->renderer, NULL);
	SDL_SetRenderDrawColor( g->renderer, 180, 180, 180, 255 );
	SDL_RenderClear( g->renderer );

	SDL_RenderCopy(g->renderer, g->gameTexture, NULL, &(g->screenGame));
	//Draw the ring of greyed-out game areas around our game area, to represent world wrapping to the user.
	SDL_SetTextureColorMod(g->gameTexture, 240, 240, 240);
	int startX = g->screenGame.x - g->screenGame.w;
	int startY = g->screenGame.y - g->screenGame.h;
	SDL_Rect current;
	current.w = g->screenGame.w;
	current.h = g->screenGame.h;
	for(int iterX = 0; iterX < 3; ++iterX)
	{
		for(int iterY = 0; iterY < 3; ++iterY)
		{
			//Don't draw over primary game area.
			if( ! ((iterX == 1) && (iterY == 1)))
			{
				current.x = startX + (current.w	* iterX);
				current.y = startY + (current.h	* iterY);
				SDL_RenderCopy(g->renderer, g->gameTexture, NULL, &current);
			}
		}
	}

	SDL_SetTextureColorMod(g->gameTexture, 255, 255, 255);
	SDL_RenderPresent(g->renderer);
}
Beispiel #30
0
void LightSurface::draw()
{
    SDL_Rect offset = this->getRect();

    if(Surface::videoBuffer!= NULL && this->getSurface() != NULL)
    {
        SDL_BlitSurface(this->getSurface(),&this->clip,Surface::videoBuffer,&offset);
    }

    SDL_SetRenderTarget(LightSurface::render, LightSurface::sdlTexture2);
    SDL_RenderCopy(LightSurface::render, this->texture, &this->clip, &offset);
    SDL_SetRenderTarget(LightSurface::render, NULL);


}