Exemplo n.º 1
0
void Text::setBlendMode(SDL_BlendMode blending)
{
	//Set blending function
	SDL_SetTextureBlendMode(mTexture, blending);
}
Exemplo n.º 2
0
static void sdl2_init_font(sdl2_video_t *vid, const char *font_path,
                          unsigned font_size)
{
   if (!g_settings.video.font_enable)
      return;

   if (font_renderer_create_default(&vid->font_driver, &vid->font_data,
                                    *font_path ? font_path : NULL, font_size))
   {
         int r = g_settings.video.msg_color_r * 255;
         int g = g_settings.video.msg_color_g * 255;
         int b = g_settings.video.msg_color_b * 255;

         r = r < 0 ? 0 : (r > 255 ? 255 : r);
         g = g < 0 ? 0 : (g > 255 ? 255 : g);
         b = b < 0 ? 0 : (b > 255 ? 255 : b);

         vid->font_r = r;
         vid->font_g = g;
         vid->font_b = b;
   }
   else
   {
      RARCH_WARN("[SDL]: Could not initialize fonts.\n");
      return;
   }

   const struct font_atlas *atlas = vid->font_driver->get_atlas(vid->font_data);

   SDL_Surface *tmp = SDL_CreateRGBSurfaceFrom(atlas->buffer, atlas->width,
                                               atlas->height, 8, atlas->width,
                                               0, 0, 0, 0);
   SDL_Color colors[256];
   int i;

   for (i = 0; i < 256; ++i)
   {
      colors[i].r = colors[i].g = colors[i].b = i;
      colors[i].a = 255;
   }

   SDL_Palette *pal = SDL_AllocPalette(256);
   SDL_SetPaletteColors(pal, colors, 0, 256);
   SDL_SetSurfacePalette(tmp, pal);
   SDL_SetColorKey(tmp, SDL_TRUE, 0);

   vid->font.tex  = SDL_CreateTextureFromSurface(vid->renderer, tmp);

   if (vid->font.tex)
   {
      vid->font.w      = atlas->width;
      vid->font.h      = atlas->height;
      vid->font.active = true;

      SDL_SetTextureBlendMode(vid->font.tex, SDL_BLENDMODE_ADD);
   }
   else
      RARCH_WARN("[SDL]: Failed to initialize font texture: %s\n", SDL_GetError());

   SDL_FreePalette(pal);
   SDL_FreeSurface(tmp);
}
Exemplo n.º 3
0
bool LTexture::loadFromFile( std::string path ) {
  //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 {
    //Convert surface to display format
    SDL_Surface* formattedSurface = SDL_ConvertSurfaceFormat( loadedSurface, SDL_PIXELFORMAT_RGBA8888, NULL );
    if( formattedSurface == NULL ) {
      printf( "Unable to convert loaded surface to display format! %s\n", SDL_GetError() );
    } else {
      //Create blank streamable texture
      newTexture = SDL_CreateTexture( gRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, formattedSurface->w, formattedSurface->h );
      if( newTexture == NULL ) {
        printf( "Unable to create blank texture! SDL Error: %s\n", SDL_GetError() );
      } else {
        //Enable blending on texture
        SDL_SetTextureBlendMode( newTexture, SDL_BLENDMODE_BLEND );

        //Lock texture for manipulation
        SDL_LockTexture( newTexture, &formattedSurface->clip_rect, &mPixels, &mPitch );

        //Copy loaded/formatted surface pixels
        memcpy( mPixels, formattedSurface->pixels, formattedSurface->pitch * formattedSurface->h );

        //Get image dimensions
        mWidth = formattedSurface->w;
        mHeight = formattedSurface->h;

        //Get pixel data in editable format
        Uint32* pixels = (Uint32*)mPixels;
        int pixelCount = ( mPitch / 4 ) * mHeight;

        //Map colors
        Uint32 colorKey = SDL_MapRGB( formattedSurface->format, 0, 0xFF, 0xFF );
        Uint32 transparent = SDL_MapRGBA( formattedSurface->format, 0x00, 0xFF, 0xFF, 0x00 );

        //Color key pixels
        for( int i = 0; i < pixelCount; ++i ) {
          if( pixels[ i ] == colorKey ) {
            pixels[ i ] = transparent;
          }
        }

        //Unlock texture to update
        SDL_UnlockTexture( newTexture );
        mPixels = NULL;
      }

      //Get rid of old formatted surface
      SDL_FreeSurface( formattedSurface );
    }

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

  //Return success
  mTexture = newTexture;
  return mTexture != NULL;
}
Exemplo n.º 4
0
void LTexture::setBlendMode(SDL_BlendMode blending)
{
	/* set blending function */
	SDL_SetTextureBlendMode(mTexture, blending);
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: Zix777/C
int main(int argc, char** argv)
{
    srand(time(0));
    int i = 0;
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Window* window = SDL_CreateWindow("SDL Practice 6.2",
                                          SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
                                          WINDOW_WIDTH, WINDOW_HEIGHT,
                                          SDL_WINDOW_SHOWN);
    SDL_Renderer* rend = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);

    SDL_Surface* surface[26];
    surface[0] = IMG_Load("alpha\\A.png");
    surface[1] = IMG_Load("alpha\\B.png");
    surface[2] = IMG_Load("alpha\\C.png");
    surface[3] = IMG_Load("alpha\\D.png");
    surface[4] = IMG_Load("alpha\\E.png");
    surface[5] = IMG_Load("alpha\\F.png");
    surface[6] = IMG_Load("alpha\\G.png");
    surface[7] = IMG_Load("alpha\\H.png");
    surface[8] = IMG_Load("alpha\\I.png");
    surface[9] = IMG_Load("alpha\\J.png");
    surface[10] = IMG_Load("alpha\\K.png");
    surface[11] = IMG_Load("alpha\\L.png");
    surface[12] = IMG_Load("alpha\\M.png");
    surface[13] = IMG_Load("alpha\\N.png");
    surface[14] = IMG_Load("alpha\\O.png");
    surface[15] = IMG_Load("alpha\\P.png");
    surface[16] = IMG_Load("alpha\\Q.png");
    surface[17] = IMG_Load("alpha\\R.png");
    surface[18] = IMG_Load("alpha\\S.png");
    surface[19] = IMG_Load("alpha\\T.png");
    surface[20] = IMG_Load("alpha\\U.png");
    surface[21] = IMG_Load("alpha\\V.png");
    surface[22] = IMG_Load("alpha\\W.png");
    surface[23] = IMG_Load("alpha\\X.png");
    surface[24] = IMG_Load("alpha\\Y.png");
    surface[25] = IMG_Load("alpha\\Z.png");

    SDL_Texture* texture[26];
    for(i=0; i<26; ++i)
        texture[i] = SDL_CreateTextureFromSurface(rend, surface[i]);

    SDL_Surface* black_surface = SDL_LoadBMP("black.bmp");
    SDL_Texture* black_texture = SDL_CreateTextureFromSurface(rend, black_surface);
    SDL_SetTextureBlendMode(black_texture, SDL_BLENDMODE_BLEND);
    SDL_SetTextureAlphaMod(black_texture, 50);

    bool quit = false;
    SDL_Event event;
    SDL_Rect window_rect;
    window_rect.h = WINDOW_HEIGHT;
    window_rect.w = WINDOW_WIDTH;
    window_rect.x = 0;
    window_rect.y = 0;

    SDL_Rect pos[NUMBER];
    for(i = 0; i<NUMBER; ++i)
    {
        pos[i].w = surface[0]->w;
        pos[i].h = surface[0]->h;
        pos[i].x = rand() % (WINDOW_WIDTH + 1);
        pos[i].y = rand() % (WINDOW_HEIGHT / 2) + WINDOW_HEIGHT / 2;
    }

    int alphabet[NUMBER];
    for(i = 0; i<NUMBER; ++i)
        alphabet[i] = rand() % 27;
    while(!quit)
    {
        while(SDL_PollEvent(&event))
        {
            if(event.type == SDL_QUIT)
                quit = true;
        }
        SDL_RenderCopy(rend, black_texture, NULL, &window_rect);
        for(i = 0; i<NUMBER; ++i)
        {
            SDL_RenderCopy(rend, texture[alphabet[i]], NULL, &pos[i]);
            pos[i].y += (rand() % 10 + 10);
            if(pos[i].y > WINDOW_HEIGHT)
            {
                alphabet[i] = rand() % 27;
                pos[i].x = rand() % (WINDOW_WIDTH + 1);
                pos[i].y = rand() % (WINDOW_HEIGHT + 1);
            }
        }
        SDL_RenderPresent(rend);
        SDL_Delay(100);
    }

    for(i=0; i<26; ++i)
        SDL_FreeSurface(surface[0]);
    SDL_FreeSurface(black_surface);
    SDL_DestroyWindow(window);
    SDL_Quit();
    return 0;
}
Exemplo n.º 6
0
	void 
	display::start(
		__in_opt const mirra::parameter_t &parameter
		)
	{
		std::string title;
		uint32_t height, width;
		mirra::parameter_t::const_iterator iter;
		mirra::object_parameter_t::const_iterator attribute_iter;

		if(!m_initialized) {
			THROW_MIRRA_DISPLAY_EXCEPTION(MIRRA_DISPLAY_EXCEPTION_UNINITIALIZED);
		}

		if(m_started) {
			THROW_MIRRA_DISPLAY_EXCEPTION(MIRAR_DISPLAY_EXCEPTION_STARTED);
		}

		height = DISPLAY_PARAMETER_DEFAULT_HEIGHT;
		title = DISPLAY_PARAMETER_DEFAULT_TITLE;
		width = DISPLAY_PRAAMETER_DEFAULT_WIDTH;

		iter = parameter.find(OBJECT_DISPLAY);
		if(iter != parameter.end()) {

			attribute_iter = iter->second.find(DISPLAY_PARAMETER_HEIGHT);
			if(attribute_iter != iter->second.end()) {

				if(attribute_iter->second.type != DATA_UNSIGNED) {
					THROW_MIRRA_DISPLAY_EXCEPTION_FORMAT(MIRRA_DISPLAY_EXCEPTION_INVALID_PARAMETER,
						"%s: %s (expecting %s)", DISPLAY_PARAMETER_STRING(DISPLAY_PARAMETER_HEIGHT),
						DATA_STRING(attribute_iter->second.type), DATA_STRING(DATA_UNSIGNED));
				}

				height = attribute_iter->second.data.uvalue;
			}

			attribute_iter = iter->second.find(DISPLAY_PARAMETER_TITLE);
			if(attribute_iter != iter->second.end()) {

				if(attribute_iter->second.type != DATA_STRING) {
					THROW_MIRRA_DISPLAY_EXCEPTION_FORMAT(MIRRA_DISPLAY_EXCEPTION_INVALID_PARAMETER,
						"%s: %s (expecting %s)", DISPLAY_PARAMETER_STRING(DISPLAY_PARAMETER_TITLE),
						DATA_STRING(attribute_iter->second.type), DATA_STRING(DATA_STRING));
				}

				title = (attribute_iter->second.data.strvalue ? attribute_iter->second.data.strvalue :
					STRING_EMPTY);
			}

			attribute_iter = iter->second.find(DISPLAY_PARAMETER_WIDTH);
			if(attribute_iter != iter->second.end()) {

				if(attribute_iter->second.type != DATA_UNSIGNED) {
					THROW_MIRRA_DISPLAY_EXCEPTION_FORMAT(MIRRA_DISPLAY_EXCEPTION_INVALID_PARAMETER,
						"%s: %s (expecting %s)", DISPLAY_PARAMETER_STRING(DISPLAY_PARAMETER_WIDTH),
						DATA_STRING(attribute_iter->second.type), DATA_STRING(DATA_UNSIGNED));
				}

				width = attribute_iter->second.data.uvalue;
			}
		}

		m_window = SDL_CreateWindow(STRING_CHECK(title), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
			width, height, WINDOW_INIT_FLAGS);

		if(!m_window) {
			THROW_MIRRA_DISPLAY_EXCEPTION_FORMAT(MIRRA_DISPLAY_EXCEPTION_EXTERNAL,
				"SDL_CreateWindow: %s", SDL_GetError());
		}

		m_window_renderer = SDL_CreateRenderer(m_window, SCALAR_INVALID(int), WINDOW_RENDERER_INIT_FLAGS);
		if(!m_window_renderer) {
			THROW_MIRRA_DISPLAY_EXCEPTION_FORMAT(MIRRA_DISPLAY_EXCEPTION_EXTERNAL,
				"SDL_CreateRenderer: %s", SDL_GetError());
		}

		if(SDL_GetRendererOutputSize(m_window_renderer, &m_renderer_width, &m_renderer_height)) {
			THROW_MIRRA_DISPLAY_EXCEPTION_FORMAT(MIRRA_DISPLAY_EXCEPTION_EXTERNAL,
				"SDL_GetRendererOutputSize: %s", SDL_GetError());
		}

		if(SDL_SetRenderDrawBlendMode(m_window_renderer, SDL_BLENDMODE_BLEND)) {
			THROW_MIRRA_DISPLAY_EXCEPTION_FORMAT(MIRRA_DISPLAY_EXCEPTION_EXTERNAL,
				"SDL_SetRenderDrawBlendMode: %s", SDL_GetError());
		}

		m_window_texture = SDL_CreateTexture(m_window_renderer, SDL_PIXELFORMAT_BGRA8888, SDL_TEXTUREACCESS_STREAMING,
			width, height);

		if(!m_window_texture) {
			THROW_MIRRA_DISPLAY_EXCEPTION_FORMAT(MIRRA_DISPLAY_EXCEPTION_EXTERNAL,
				"SDL_CreateTexture: %s", SDL_GetError());
		}

		if(SDL_SetTextureBlendMode(m_window_texture, SDL_BLENDMODE_BLEND)) {
			THROW_MIRRA_DISPLAY_EXCEPTION_FORMAT(MIRRA_DISPLAY_EXCEPTION_EXTERNAL,
				"SDL_SetTextureBlendMode: %s", SDL_GetError());
		}

		m_started = true;
		clear();
	}
Exemplo n.º 7
0
SDL_Texture *
SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface)
{
    const SDL_PixelFormat *fmt;
    SDL_bool needAlpha;
    Uint32 i;
    Uint32 format;
    SDL_Texture *texture;

    CHECK_RENDERER_MAGIC(renderer, NULL);

    if (!surface) {
        SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface");
        return NULL;
    }

    /* See what the best texture format is */
    fmt = surface->format;
    if (fmt->Amask || SDL_GetColorKey(surface, NULL) == 0) {
        needAlpha = SDL_TRUE;
    } else {
        needAlpha = SDL_FALSE;
    }
    format = renderer->info.texture_formats[0];
    for (i = 0; i < renderer->info.num_texture_formats; ++i) {
        if (!SDL_ISPIXELFORMAT_FOURCC(renderer->info.texture_formats[i]) &&
            SDL_ISPIXELFORMAT_ALPHA(renderer->info.texture_formats[i]) == needAlpha) {
            format = renderer->info.texture_formats[i];
            break;
        }
    }

    texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
                                surface->w, surface->h);
    if (!texture) {
        return NULL;
    }

    if (format == surface->format->format) {
        if (SDL_MUSTLOCK(surface)) {
            SDL_LockSurface(surface);
            SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
            SDL_UnlockSurface(surface);
        } else {
            SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
        }
    } else {
        SDL_PixelFormat *dst_fmt;
        SDL_Surface *temp = NULL;

        /* Set up a destination surface for the texture update */
        dst_fmt = SDL_AllocFormat(format);
        temp = SDL_ConvertSurface(surface, dst_fmt, 0);
        SDL_FreeFormat(dst_fmt);
        if (temp) {
            SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch);
            SDL_FreeSurface(temp);
        } else {
            SDL_DestroyTexture(texture);
            return NULL;
        }
    }

    {
        Uint8 r, g, b, a;
        SDL_BlendMode blendMode;

        SDL_GetSurfaceColorMod(surface, &r, &g, &b);
        SDL_SetTextureColorMod(texture, r, g, b);

        SDL_GetSurfaceAlphaMod(surface, &a);
        SDL_SetTextureAlphaMod(texture, a);

        if (SDL_GetColorKey(surface, NULL) == 0) {
            /* We converted to a texture with alpha format */
            SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
        } else {
            SDL_GetSurfaceBlendMode(surface, &blendMode);
            SDL_SetTextureBlendMode(texture, blendMode);
        }
    }
    return texture;
}
Exemplo n.º 8
0
void hc_map::draw(SDL_Rect *viewport, vector<hc_npc*> npcs, hc_npc *player)
{
	//hc_debug << "tiles: " << background.size() << " from: " << info.height * info.width << endl;
	if(background.size() != info.height * info.width || info.height * info.width == 0)
	{
		return;
	}

	if(!background_texture)
	{
		background_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, info.width * 16, info.height * 16);
		if(!background_texture)
		{
			hc_fatal << "Unable to create Texture: " << SDL_GetError() << endl;
			exit(0);
		}
		SDL_SetTextureBlendMode(background_texture, SDL_BLENDMODE_NONE);
	}

	if(!objects_texture)
	{
		objects_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, info.width * 16, info.height * 16);
		if(!objects_texture)
		{
			hc_fatal << "Unable to create Texture: " << SDL_GetError() << endl;
			exit(0);
		}
		SDL_SetTextureBlendMode(objects_texture, SDL_BLENDMODE_BLEND);
	}

	if(!npc_texture)
	{
		npc_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, info.width * 16, info.height * 16);
		if(!npc_texture)
		{
			hc_fatal << "Unable to create Texture: " << SDL_GetError() << endl;
			exit(0);
		}
		SDL_SetTextureBlendMode(npc_texture, SDL_BLENDMODE_BLEND);
	}


	//hc_debug << "Draw map: " << info.name << endl;
	if(background_changed)
	{
		hc_debug << "Rerender background" << endl;
		SDL_Texture *old_texture;
		old_texture = SDL_GetRenderTarget(renderer);
		SDL_SetRenderTarget(renderer, background_texture);
		SDL_SetRenderDrawColor(renderer, 255, 0, 255, 255);
		SDL_RenderClear(renderer);

		for(auto tile:background)
		{
			bool around[3][3];
			uint32_t here_x, here_y;
			tile.get_coordinates(&here_x, &here_y);

			for(int32_t y = -1; y < 2; y++)
			{
				for(int32_t x = -1; x < 2; x++)
				{
					if(here_x + x == -1 || here_x + x == info.width || here_y + y == -1 || here_y + y == info.height)
					{
						around[x + 1][y + 1] = true;
					}
					for(auto tile_around:background) // TODO: bad solution, very slow
					{
						uint32_t there_x, there_y;
						tile_around.get_coordinates(&there_x, &there_y);
						if(there_x == here_x + x && there_y == here_y + y)
						{
							if(tile.get_tileset() == tile_around.get_tileset())
							{
								around[x + 1][y + 1] = true;
							}
							else
							{
								around[x + 1][y + 1] = false;
							}

							break;
						}
					}

				}
			}
			tile.draw_as_background(tileset, around);
		}


		background_changed = false;
		SDL_SetRenderTarget(renderer, old_texture);
	}

	if(objects_changed)
	{
		hc_debug << "Rerender objects" << endl;
		SDL_Texture *old_texture;
		old_texture = SDL_GetRenderTarget(renderer);
		SDL_SetRenderTarget(renderer, objects_texture);
		SDL_SetRenderDrawColor(renderer, 255, 0, 255, 0);
		SDL_RenderClear(renderer);

		for(auto tile:objects)
		{
			tile.draw_as_sprite(tileset);
		}
		objects_changed = false;
		SDL_SetRenderTarget(renderer, old_texture);
	}

	{
		SDL_Texture *old_texture;
		old_texture = SDL_GetRenderTarget(renderer);
		SDL_SetRenderTarget(renderer, npc_texture);
		SDL_SetRenderDrawColor(renderer, 255, 0, 255, 0);
		SDL_RenderClear(renderer);
		for(auto npc:npcs)
		{
			npc->draw();
		}
		SDL_SetRenderTarget(renderer, old_texture);
	}

	SDL_Rect source;
	SDL_Rect target;

	int32_t player_x = 0;
	int32_t player_y = 0;

	player->get_pos(&player_x, &player_y);

	player_x += 8; //Half the NPC-sprite-size
	player_y += 8;

	uint32_t map_w = info.width * 16;
	uint32_t map_h = info.height * 16;

	if(map_w <= viewport->w)
	{
		source.w = map_w;
		target.w = map_w;

		source.x = 0;
		target.x = viewport->x + viewport->w / 2 - map_w / 2;
	}
	else
	{
		source.w = viewport->w;
		target.w = viewport->w;

		source.x = player_x - viewport->w / 2;
		target.x = viewport->x;
	}

	if(map_h <= viewport->h)
	{
		source.h = map_h;
		target.h = map_h;

		source.y = 0;
		target.y = viewport->y + viewport->h / 2 - map_h / 2;
	}
	else
	{
		source.h = viewport->h;
		target.h = viewport->h;

		source.y = player_y - viewport->h / 2;
		target.y = viewport->y;
	}

	if(source.x < 0)
	{
		source.x = 0;
	}

	if(source.y < 0)
	{
		source.y = 0;
	}

	if(source.x > map_w - source.w)
	{
		source.x = map_w - source.w;
	}

	if(source.y > map_h - source.h)
	{
		source.y = map_h - source.h;
	}





	SDL_RenderCopy(renderer, background_texture, &source, &target);
	SDL_RenderCopy(renderer, objects_texture, &source, &target);
	SDL_RenderCopy(renderer, npc_texture, &source, &target);
}
Exemplo n.º 9
0
void Video::WriteNextFrame()
{
    int frameFinished = 0;
    AVPacket packet;

    if (texturesRecreatedCount != gTexturesRecreatedCount)
    {
        texturesRecreatedCount = gTexturesRecreatedCount;

        SDL_DestroyTexture(pTexture);
        pTexture =
            SDL_CreateTexture(
                gpRenderer,
                IsYUVFormat(pCodecContext->pix_fmt) ? SDL_PIXELFORMAT_YV12 : SDL_PIXELFORMAT_ARGB8888,
                SDL_TEXTUREACCESS_STREAMING,
                width,
                height);
        SDL_SetTextureBlendMode(pTexture, SDL_BLENDMODE_BLEND);

        unsigned char *pPixels = NULL;
        int pitch = 0;

        SDL_LockTexture(pTexture, NULL, reinterpret_cast<void **>(&pPixels), &pitch);
        memcpy(pPixels, pCachedTexturePixels, pitch * height);
        SDL_UnlockTexture(pTexture);
    }

    while (!frameFinished)
    {
        if (av_read_frame(pFormatContext, &packet) != 0)
        {
            break;
        }

        if (packet.stream_index == videoStream && avcodec_decode_video2(pCodecContext, pFrame, &frameFinished, &packet) >= 0)
        {
            if (frameFinished)
            {
                AVPicture picture;
                unsigned char *pPixels = NULL;
                int pitch = 0;

                SDL_LockTexture(pTexture, NULL, reinterpret_cast<void **>(&pPixels), &pitch);

                if (IsYUVFormat(pCodecContext->pix_fmt))
                {
                    picture.data[0] = pFrame->data[0];
                    picture.data[1] = pFrame->data[1];
                    picture.data[2] = pFrame->data[2];
                    picture.linesize[0] = pFrame->linesize[0];
                    picture.linesize[1] = pFrame->linesize[1];
                    picture.linesize[2] = pFrame->linesize[2];
                }
                else
                {
                    picture.data[0] = pPixels;
                    picture.linesize[0] = pitch;
                }

                sws_scale(pImageConvertContext, pFrame->data, pFrame->linesize, 0, pFrame->height, picture.data, picture.linesize);

                if (IsYUVFormat(pCodecContext->pix_fmt))
                {
                    if (pitch == picture.linesize[0])
                    {
                        int size = pitch * pFrame->height;

                        memcpy(pPixels, picture.data[0], size);
                        memcpy(pPixels + size, picture.data[2], size / 4);
                        memcpy(pPixels + size * 5 / 4, picture.data[1], size / 4);
                    }
                    else
                    {
                        unsigned char *y1, *y2, *y3, *i1, *i2, *i3;
                        y1 = pPixels;
                        y3 = pPixels + pitch * pFrame->height;
                        y2 = pPixels + pitch * pFrame->height * 5 / 4;

                        i1 = picture.data[0];
                        i2 = picture.data[1];
                        i3 = picture.data[2];

                        for (int i = 0; i < pFrame->height / 2; i++)
                        {
                            memcpy(y1, i1, pitch);
                            i1 += picture.linesize[0];
                            y1 += pitch;
                            memcpy(y1, i1, pitch);

                            memcpy(y2, i2, pitch / 2);
                            memcpy(y3, i3, pitch / 2);

                            y1 += pitch;
                            y2 += pitch / 2;
                            y3 += pitch / 2;
                            i1 += picture.linesize[0];
                            i2 += picture.linesize[1];
                            i3 += picture.linesize[2];
                        }
                    }
                }

                memcpy(pCachedTexturePixels, pPixels, pitch * height);
                SDL_UnlockTexture(pTexture);
            }
        }

        av_free_packet(&packet);
    }
}
Exemplo n.º 10
0
/**
 * @brief Creates / Recreate Textures
 * @param textureType
 * @param surface
 */
void SurfaceManager::createTexture(int textureType, SDL_Surface *surface)
{
    // Handle to Window Manager
    window_manager_ptr window = m_weak_window_manager.lock();
    if (!window)
    {
        return;
    }

    switch(textureType)
    {
        case TEXTURE_MAIN_SCREEN:
            {
                // If Exists, Recreate it.
                if(textureExists(textureType))
                {
                    delTexture(textureType);
                }

                 // Handle to Window Manager
                window_manager_ptr window = m_weak_window_manager.lock();
                if (!window)
                {
                    return;
                }

                // Get the Actual size of the Renderer to match the surface for scaling.

                // m_is_scalling_surface!!  Add Toggle for Scaling here,
                // Otherwise should use same size as main surface!
                int screenWidth, screenHeight;
                SDL_GetRendererOutputSize(
                    window->getRenderer(),
                    &screenWidth,
                    &screenHeight
                );

                // Create Texture: SDL_TEXTUREACCESS_STREAMING
                texture_ptr texture(
                    new Textures(
                        SDL_CreateTexture(
                            window->getRenderer(),
                            SDL_PIXELFORMAT_ARGB8888,
                            SDL_TEXTUREACCESS_STREAMING,
                            screenWidth, screenHeight
                        )
                    )
                );

                addTexture(textureType, texture);

                // Set the Blend Mode of the Texture NONE
                if(SDL_SetTextureBlendMode(
                            texture->getTexture(),
                            SDL_BLENDMODE_NONE) < 0)
                {
                    SDL_Log("Error Setting Blend on Texture - %s", SDL_GetError());
                }
            }
            break;

        case TEXTURE_SELECTION:
        case TEXTURE_HILIGHT:
            {
                // If Exists, Recreate it.
                if(textureExists(textureType))
                {
                    delTexture(textureType);
                }

                // Create Texture: SDL_TEXTUREACCESS_TARGET
                texture_ptr texture(
                    new Textures(
                        SDL_CreateTexture(
                            window->getRenderer(),
                            SDL_PIXELFORMAT_ARGB8888,
                            SDL_TEXTUREACCESS_TARGET,
                            surface->w, surface->h
                        )
                    )
                );

                addTexture(textureType, texture);

                // Set the Blend Mode of the Texture ADD
                if(SDL_SetTextureBlendMode(
                            texture->getTexture(),
                            SDL_BLENDMODE_ADD) < 0)
                {
                    SDL_Log("Error Setting Blend on Texture - %s", SDL_GetError());
                }
            }
            break;

        default:
            break;
    }
}
Exemplo n.º 11
0
void setBlendMode(LTexture* s, SDL_BlendMode blending )
{
	SDL_SetTextureBlendMode(s->mTexture, blending );
}
Exemplo n.º 12
0
void LTexture::SetBlendMode(SDL_BlendMode blending)
{
	SDL_SetTextureBlendMode( mTexture, blending);
}