1. Installing SDL 2
2. It is also a variety of dynamic and static issues. You can also use the official website directly.
Basically, he can only display images in BMP format by default. Also Add (Sdl_delay (2000000000000);//Delay 2000 milliseconds, auto-close after 2s) Otherwise you won't see it.
#-------------------------------------------------# # Project created by Qtcreator 2018-03-09t13:30:28##------------ -------------------------------------QT + + core Guigreaterthan (Qt_major_version, 4): qt + = Widgetstarget = Testsdlte Mplate = app# The following define makes your compiler emit warnings if you use# any feature of Qt which as been marked as Deprecated (the exact warnings# depend on your compiler). Please consult the documentation of the# deprecated APIs in order to know what to ports your code away from it. Defines + = qt_deprecated_warnings# You can also make your code fail to compile if you use DEPRECATED apis.# in order to do So, uncomment the following line.# your can also select to disable deprecated APIs with up to a certain version of Qt. #DEF INES + = qt_disable_deprecated_before=0x060000 # Disables all the APIs DEPRECATED before QT 6.0.0SOURCES + = main.cpp Mainwindow.cppheaders + = mainwindow.hforms + Mainwindow.uiincludepath+=/usr/local/include#includepaTh+=/usr/local/cellar/sdl2/2.0.8/includelibs + =-l/usr/local/cellar/sdl2/2.0.8/lib-lsdl2_test-lsdl2-lsdl2main
#include "mainwindow.h" #include <QApplication> #include "sdl2/sdl.h" #include <iostream> #undef mainusing namespace Std;const int screen_width = 640;const int screen_height = 480;int main (int argc, char *argv[]) {qapplication A (argc, argv); MainWindow w;//w.show (); The window we ' ll be rendering to sdl_window* Gwindow = NULL; The surface contained by the window sdl_surface* gscreensurface = NULL; The image we'll load and show on the screen sdl_surface* ghelloworld = NULL; Initialize first initialize the SD video subsystem if (Sdl_init (sdl_init_video) <0) {printf ("window could not is created! Sdl_error:%s\n ", Sdl_geterror ()); return false; }//Create Window Gwindow=sdl_createwindow ("SHOW BMP",//window title sdl_windowpos_undefined,/ /Window Position setting sdl_windowpos_undefined, screen_width,//window width screen_height,//window's Height sdl_window_shown//display window); if (gwindow==null) {printf ("window could not being created! Sdl_error:%s\n ", Sdl_geterror ()); return false; }//use This function to get the SDL surface associated with the window. Gets the window corresponding to surface gscreensurface=sdl_getwindowsurface (Gwindow); Load Picture Ghelloworld = Sdl_loadbmp ("/users/allenboy/desktop/allen.bmp");//Load picture if (Ghelloworld = = NULL) {printf ("Unable to load image%s! SDL Error:%s\n "," Hello_world.bmp ", Sdl_geterror ()); return false; }//use This function to perform a fast surface copy to a destination surface. Quick copy of Surface//parameters for the following functions are: sdl_surface* src, const sdl_rect* srcrect, sdl_surface* DST, sdl_rect* dstrect Sdl_blitsurface (Ghelloworld, null,gscreensurface,null); Sdl_updatewindowsurface (GwindoW);//Update shows copy the window surface to the screen sdl_delay (2000000000000);//Delay 2000 msec, 2s after auto-off//release memory SDL _freesurface (Ghelloworld);//free space Ghelloworld = NULL; Sdl_destroywindow (Gwindow);//Destroy Window Gwindow = NULL; Sdl_quit ();//exit SDL return 0; return a.exec ();}
Configuring SDL 2 in your Mac with QT