![]() ![]() There is also IMG_LoadTexture_RW(), which is equivalent to this function except that it will rely on SDL_image to determine what type of data it is loading, much like passing a NULL for type. There is a separate function to read files from disk without having to deal with SDL_RWops: IMG_LoadTexture("filename.jpg") will call this function and manage those details for you, determining the file type from the filename's extension. If type is NULL, SDL_image will rely solely on its ability to guess the format. SDL_image reads everything it needs from the RWops during this call in any case.Įven though this function accepts a file type, SDL_image may still try other decoders that are capable of detecting file type from the contents of the image data, but may rely on the caller-provided type string for formats that it cannot autodetect. If freesrc is non-zero, the RWops will be closed before returning, whether this function succeeds or not. Otherwise, SDL_image will attempt to create an SDL_Texture in the most format that most reasonably represents the image data (but in many cases, this will just end up being 32-bit RGB or 32-bit RGBA). If the loaded image has transparency or a colorkey, a texture with an alpha channel will be created. This can be significantly more efficient than using a CPU-bound SDL_Surface if you don't need to manipulate the image directly after loading it. RemarksĪn SDL_Texture represents an image in GPU memory, usable by SDL's 2D Render API. Non-zero to close/free the SDL_RWops before returning, zero to leave it open.Ī filename extension that represent this data ("BMP", "GIF", "PNG", etc). The SDL_Renderer to use to create the GPU texture.Īn SDL_RWops that data will be read from. SDL_QueryTexture(pTripodTexture, NULL, NULL, &l_sourceRect.w, &l_sourceRect.SDL_Texture * IMG_LoadTextureTyped_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc, const char *type) Function Parameters renderer SDL_Texture *pBackgroundTexture = SDL_CreateTexture(pRenderer, SDL_PIXELFORMAT_RGBX8888, SDL_TEXTUREACCESS_TARGET, 1250, 700) SDL_Texture *pConsoleBackgroundTexture = SDL_CreateTextureFromSurface(pRenderer, pConsoleBackground) SDL_Texture *pTripodTexture = SDL_CreateTextureFromSurface(pRenderer, pTripod) SDL_Surface *pConsoleBackground = IMG_Load( "images/consoleBackground1.png") SDL_Surface *pTripod = IMG_Load( "images/tripod.png") ![]() SDL_Surface *pScreen = SDL_GetWindowSurface(pWindow) Other SDL parameters bool quit = false SDL_RenderSetLogicalSize(pRenderer, SCREEN_WIDTH, SCREEN_HEIGHT) SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear") // make the scaled rendering look smoother. PRenderer = SDL_CreateRenderer(pWindow, -1, SDL_RENDERER_TARGETTEXTURE) PWindow = SDL_CreateWindow( "TDPB HMI", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ) tiff files, must go after window has been created //Declare window and renderer IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG | IMG_INIT_TIF) //Initialise SDL_Image to load. SDL_Init( SDL_INIT_VIDEO ) //Initialize SDL Screen attributes const int SCREEN_WIDTH = 1250 Example trying to render texture to another texture #include #include #include #include #include #include #include #include #include #include "SDL.h" #include "SDL_image.h" using namespace std I am aware that the textures created using CreateTextureFromSurface have access SDL_TEXTUREACCESS_STATIC, but I am not using these as the target. After all that I set the render target back to be the window and render the background texture (which should now have all the other textures rendered on to it) to the window. I set the background texture to be the rendering target using SDL_SetRenderTarget, then render my other textures onto it. I load a bunch of images as surfaces and convert them to textures using SDL_CreateTextureFromSurface, these are the textures I want to use to build up sub-texture layers. My approach has been to create a background texture with SDL_CreateTexture setting its access to SDL_TEXTUREACCESS_TARGET. Since my GUI is built up in layers, I would like to be able to render one texture onto another before rendering a final set of built up textures to the window. These sub-surfaces are then blitted to the main background screen before doing a final SDL_Flip().įor my SDL2.0 conversion I have tried to move away from Surfaces and use Textures wherever possible. My GUI uses a bunch of png images loaded from file which are rotated, re-sized and then blitted to various sub-surfaces. I am trying to convert a graphical user interface that I developed using SDL1.2 to SDL2.0. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |