4/24/2024 0 Comments Load png sdl2![]() Remember: A Makefile must respect the tabs as the code is here, otherwise it won’t work.Īfter saving, still inside your project folder, such as PowerShell or CMD, run the command:Īlso remember to have previously renamed the mingw32-make file to just make in the path: C:\mingw64\bin\ make To speed it up and type less when compiling, you can create a file (no extension, again don’t use Notepad) named Makefile and insert this content below: all : If it doesn’t work it’s because you must have ′′ skipped ′′ some step, review all of them! To compile the command is similar to what we did in the video, there is only one difference, add the flag: -lSDL2_image at the end, example: g++ main.cpp -I SDL2 \x86_64-w64-mingw32 \include -L SDL2 \x86_64-w64-mingw32 \lib -lmingw32 -lSDL2main -lSDL2 -lSDL2_image Note that in this code we have 4 fundamental lines to read and display the image correctly, they are the lines: // Include the SDL2_image #include // Read the image: pikachu.png SDL_Texture * img = IMG_LoadTexture ( renderer, "pikachu.png" ) // Display our image // NOTE that: the `rect` will "snap" the image SDL_RenderCopy ( renderer, img, NULL, & rect ) // Free up the space used by the image in memory SDL_DestroyTexture ( img ) #include int main ( int argc, char ** argv ) Of course, in the same place as the SDL2 folder (with the files copied from SDL2_image) and the image. ![]() Now copy the code below and paste it inside a main.cpp file (Do not use Notepad to create it, use a code editor: VS Code, for example). To run our example we will use this PNG image below: TIP: If you want, make a backup of this SDL2 folder that already has all the SDL2_image files somewhere else to always use them in possible new projects and save time. To finish this step of the copies, also copy the file: SDL2_image.dll which is in SDL2_image\x86_64-w64-mingw32\bin\SDL2_image.dll to the “root” of your project. Its path would be: SDL2_image\x86_64-w64-mingw32\include\SDL2\SDL2_image.h and paste it in SDL2\x86_64-w64-mingw32\include\SDL2\, where there will be other files.ĭo the same, but this time for ALL FILES in the bin and lib folder in SDL2_image and paste them in the corresponding paths in SDL2, example: All files inside the bin folder: SDL2_image\x86_64-w64-mingw32\bin for ``SDL2\x86_64-w64-mingw32\bin` All files inside the lib folder: SDL2_image\x86_64-w64-mingw32\lib for ``SDL2\x86_64-w64-mingw32\lib` Unzip the downloaded file (right mouse button: Extract here), enter the unzipped folder and copy the SDL_image.h file and paste it in the path corresponding to the SDL2 folder you have pasted in your project. ĭownload the package: SDL2_image-devel-X.X.X-mingw.zip, where X.X.X is the version, if you want the one according to this article click on the button below: Access this address: and select the latest version of SDL2_image, according to the publication date of this article is 2.6.3. Now cut or copy this folder to your project. I renamed the folder that was unzipped to SDL2 only, it’s easier when we use it. Once downloaded, right-click and select Extract here (needs Winrar installed). In this article we will see how to use these formats in SDL2 on Windows.įirst, first of all, you must have GCC MinGW properly installed on your Windows, see the article below to see how to do this: How to Install GCC/G++ MinGW on WindowsĪfter properly installed on your system and working correctly, download SDL2 at this link, choose version SDL2-devel-X.XX.X -mingw.zip, where X.XX.X is the latest version number.Īccording to the publication date of this article, the latest version is 2.26.4, if you want to download it directly from here, just click the button below: However, there is an additional package made available by the SDL2 development team itself that allows you to use PNG and JPG in your games. The SDL2, natively, image formats png and jpg/jpeg are not supported, only ` bmp`.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |