Promotion Ffplay + SDL2 + vs2010
SDL2 modified and added a part of the interface, and increased the support of the opponent's system platform (IOS,ANDRIOD), the display part of the change is larger, and not backward-compatible, specific reference to the official http://wiki.libsdl.org/MigrationGuide# Other_renderer_api_notes
Here is a demo using SDL2 to display a BMP picture
#include "stdafx.h" #include "SDL.h" #pragma comment (lib, "Sdl2.lib") int _tmain (int argc, _tchar* argv[]) {Sdl_windo W *window; Declare A pointer sdl_init (SDL_INIT_VIDEO);
Initialize SDL2//sdl_eventstate (sdl_windowevent_focus_gained, Sdl_ignore);
Sdl_eventstate (Sdl_syswmevent, Sdl_ignore);
Sdl_eventstate (Sdl_userevent, Sdl_ignore); Create an application windows with the following Settings:window = Sdl_createwindow ("An SDL2 window", Window title,//initial x position,//initial y position 640, width, in pixels,//height, in pixels sdl_window_opengl |
Sdl_window_resizable//Flags-see below); Check that the window is successfully made if (window = = NULL) {//In the event this window could not is made.
..
printf ("Could not create window:%s\n", Sdl_geterror ()); Return 1;
}//sdl_setwindowfullscreen (Window,sdl_window_fullscreen); int W =1024,h=768;
W,h should be set to the original size of the picture sdl_renderer* render = sdl_createrenderer (window, -1,0); sdl_texture* texture = sdl_createtexture (Render,
<span style= "White-space:pre" > </span>sdl_pixelformat_bgr24,sdl_textureaccess_streaming,w,h);
file* f = fopen ("D:\\media\\1.bmp", "RB");
Fseek (F,0,seek_end);
Long size = Ftell (f);
Fseek (F,0,seek_set);
char* buffer = new Char[size];
Fread (BUFFER,SIZE,1,F);
int offset = * ((int*) (buffer+10));
char* p = buffer + offset;
char* bmp = new Char[size-offset];
for (int i=0; i< h;i++) {memcpy (bmp+i*1024*3,buffer+offset+ (h-i-1) *1024*3,1024*3);
} Sdl_rect Rect;
rect.x = 0;
Rect.y = 0;
RECT.W = W;
Rect.h = h;
Sdl_updatetexture (TEXTURE,0,BMP,3*W);
Sdl_renderclear (render);
Sdl_rendercopy (render, texture, NULL, NULL);
Sdl_renderpresent (render);
Sdl_event event1; The window is Open:enter program loop (= sdl_pollevent) while (true) {//sdl_delay (300);
Pause execution for 3000 milliseconds, for example sdl_pumpevents ();
Sdl_peepevents (&event1, 1, sdl_getevent, sdl_firstevent,sdl_lastevent);
if (Event1.type = = sdl_windowevent) { Switch (event1.window.event) {case sdl_windowevent_resized:sdl_updatetexture (texture,0,bmp,3*w);
Sdl_renderclear (render);
Sdl_rendercopy (render, texture, NULL, NULL);
Sdl_renderpresent (render);
Break
Default:break; } else if (event1.type==sdl_keydown) {switch (event1.key.keysym.sym) {case sdlk_f:sdl_setwindowful
Lscreen (Window,sdl_window_fullscreen_desktop);
Break
Case Sdlk_g:sdl_setwindowfullscreen (window,0);
Break
Case Sdlk_q:exit (-1);
Break
{}} delete[] bmp;
delete[] buffer;
Close and destroy the window Sdl_destroywindow (window);
Clean up sdl_quit ();
return 0;
}