好久没有写代码了,VS太大不想去费时下载,就下载了eclipse-cpp-luna-SR1-win32-x86_64,系统win7 64bit具体下载地址如下:http://www.eclipse.org/downloads/下载所需要的版本接下来就是MingW下载地址http://www.mingw.org/语言环境搭建好了。
下载sdl,地址http://www.libsdl.org
注意版本
OK啦!!!
1 /*
2 * main.cpp
3 *
4 * Created on: 2014年12月10日
5 * Author: wgzll
6 */
7 #include <iostream>
8 #include <sdl2/sdl.h>
9 using namespace std;
10
11 SDL_Window* g_pWindow = 0;
12 SDL_Renderer* g_pRenderer = 0;
13
14 int main(int argc,char *args[])
15 {
16 if(SDL_Init(SDL_INIT_EVERYTHING)>=0)
17 {
18 g_pWindow = SDL_CreateWindow("Chapter 1: Setting up SDL",
19 SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,
20 640,480,
21 SDL_WINDOW_SHOWN);
22 if(g_pWindow !=0)
23 {
24 cout<<"初始化成功"<<endl;
25 g_pRenderer = SDL_CreateRenderer(g_pWindow,-1,0);
26 }
27 }
28 else
29 {
30 cout<<"初始化失败"<<endl;
31 return 1;
32 }
33
34 SDL_SetRenderDrawColor(g_pRenderer,0,0,0,255);
35
36 SDL_RenderClear(g_pRenderer);
37
38 SDL_RenderPresent(g_pRenderer);
39
40 SDL_Delay(500);
41
42 SDL_Quit();
43
44 return 0;
45 }
#define SDL_INIT_EVERYTHING ( \
SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | \
SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER \
)
Uint32 subsystem_init;
subsystem_init = SDL_WasInit(SDL_INIT_EVERYTHING);
if (subsystem_init & SDL_INIT_VIDEO)
{ printf("Video is initialized.\n");}
else
{ printf("Video is not initialized.\n");
}
if (SDL_WasInit(SDL_INIT_VIDEO) != 0)
{ printf("Video is initialized.\n");}
else
{ printf("Video is not initialized.\n");}
Uint32 subsystem_mask = SDL_INIT_VIDEO | SDL_INIT_AUDIO;
if (SDL_WasInit(subsystem_mask) == subsystem_mask)
{ printf("Video and Audio initialized.\n");}
else
{ printf("Video and Audio not initialized.\n");}
SDL_INIT_TIMER
timer subsystem
SDL_INIT_AUDIO
audio subsystem
SDL_INIT_VIDEO
video subsystem
SDL_INIT_JOYSTICK
joystick subsystem
SDL_INIT_HAPTIC
haptic (force feedback) subsystem
SDL_INIT_GAMECONTROLLER
controller subsystem
SDL_INIT_EVENTS
events subsystem
SDL_INIT_EVERYTHING
all of the above subsystems
SDL_INIT_NOPARACHUTE
compatibility; this flag is ignored