当前位置:   article > 正文

SDL2.0配置说明_c# sdl2 界面库

c# sdl2 界面库

这篇文章主要是介绍如何在windows上部署SDL

1、首先在浏览器中输入网址http://libsdl.org/download-2.0.php,找到Development Libraries,下面会有windowsmax oslinux不同版本的库,我们可以选择自己电脑操作系统的版本进行下载,我的电脑是windows64位,就选择了图中画圈处进行下载。


2、将上一步中下载好的SDL文件进行解压缩,得到如下的文件,这里面我们将会用到的是lib和include两个文件夹:



3、找到自己的vs中vc文件夹,我的是D:\Program Files (x86)\Microsoft Visual Studio 10.0\VC,首先打开vc文件夹中的include文件夹,在里面新建一个SDL(路径为:D:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\SDL,这里我要啰嗦一句,新建这个SDL文件夹是为了使头文件的放置更加规范,但这也有一个副作用,那就是我们在写程序include这些头文件时,要加上SDL/,比如我们要使用SDL.h,那就是include<SDL/SDL.h>,这点要切记哦),然后将刚刚解压缩的SDL文件夹中的include中的文件全部拷贝到这个新建的SDL中,如下图所示:



4、在刚刚的vc文件夹中打开lib文件夹(路径为:D:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib),将刚刚我们解压缩的SDL库的文件夹中的lib/x86文件夹打开,会看到四个文件,如下图所示:



此时我们将三个以lib结尾的文件拷贝到上面我们提到的lib文件夹中,如下图所示:



5、到这里,我们会发现,lib下文件夹中怎么出现以dll结尾的文件,这是程序在运行时用到的一个动态链接文件,处理的办法有两种,一种是将它放在C:WINDOW/system32中(这是添加到系统中),另一种是将这个dll文件放在我们项目编译所得的exe文件所在的文件夹中,这里我们采用这一种方法,下面将会介绍。


6、首先在vs中新建一个项目,这个步骤我这里就省略了,建完项目如下图:



7、下面我们来配置这个项目的属性,打开项目属性,进入到如下界面中:



接下来,我们点开左侧的c/c++,然后点击代码生成,在右侧栏目运行库中选择多线程 DLL (/MD),然后点击确认:



再然后,我们点击左侧的链接库,然后点击输入,在右侧栏目的附加依赖项中点编辑,然后将SDL2.lib、SDL2main.lib和SDL2test.lib(这里先声明,这三个名字是我们解压缩得到的文件夹中x86文件夹中的,依照具体填写)填写进去,然后点击确认:



8、至此,我们离成功便只差一步了,大家一定会想到了那个dll文件吧,是的,你没猜错,就是这个文件,下面我们在文件夹中打开这个文件(我的是在D:\myhomewok\Second),并将SDL2文件添加到exe所在文件夹中(在vs中是Debug文件夹,当然我们也可以把dll放在D:\myhomewok\Second\Second中,我选择此种做法):



到此为止,我们的SDL已经部署好了,之后便可以使用了,下面我们找个示例程序进行测试,运行截图如下:



到此,我们的SDL已经部署完成了(最后,附上我部署SDL的一个视频链接:http://pan.baidu.com/s/1qYAgtE8)。

关于测试的代码,我是在github上找的,如下:

  1. /*
  2. Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
  3. This software is provided 'as-is', without any express or implied
  4. warranty. In no event will the authors be held liable for any damages
  5. arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it
  8. freely.
  9. */
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #ifdef __EMSCRIPTEN__
  13. #include <emscripten/emscripten.h>
  14. #endif
  15. #include "SDL/SDL_test_common.h"
  16. static SDLTest_CommonState *state;
  17. int done;
  18. static const char *cursorNames[] = {
  19. "arrow",
  20. "ibeam",
  21. "wait",
  22. "crosshair",
  23. "waitarrow",
  24. "sizeNWSE",
  25. "sizeNESW",
  26. "sizeWE",
  27. "sizeNS",
  28. "sizeALL",
  29. "NO",
  30. "hand",
  31. };
  32. int system_cursor = -1;
  33. SDL_Cursor *cursor = NULL;
  34. /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
  35. static void
  36. quit(int rc)
  37. {
  38. SDLTest_CommonQuit(state);
  39. exit(rc);
  40. }
  41. void
  42. loop()
  43. {
  44. int i;
  45. SDL_Event event;
  46. /* Check for events */
  47. while (SDL_PollEvent(&event)) {
  48. SDLTest_CommonEvent(state, &event, &done);
  49. if (event.type == SDL_WINDOWEVENT) {
  50. if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
  51. SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
  52. if (window) {
  53. SDL_Log("Window %d resized to %dx%d\n",
  54. event.window.windowID,
  55. event.window.data1,
  56. event.window.data2);
  57. }
  58. }
  59. if (event.window.event == SDL_WINDOWEVENT_MOVED) {
  60. SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
  61. if (window) {
  62. SDL_Log("Window %d moved to %d,%d (display %s)\n",
  63. event.window.windowID,
  64. event.window.data1,
  65. event.window.data2,
  66. SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window)));
  67. }
  68. }
  69. }
  70. if (event.type == SDL_KEYUP) {
  71. SDL_bool updateCursor = SDL_FALSE;
  72. if (event.key.keysym.sym == SDLK_LEFT) {
  73. --system_cursor;
  74. if (system_cursor < 0) {
  75. system_cursor = SDL_NUM_SYSTEM_CURSORS - 1;
  76. }
  77. updateCursor = SDL_TRUE;
  78. } else if (event.key.keysym.sym == SDLK_RIGHT) {
  79. ++system_cursor;
  80. if (system_cursor >= SDL_NUM_SYSTEM_CURSORS) {
  81. system_cursor = 0;
  82. }
  83. updateCursor = SDL_TRUE;
  84. }
  85. if (updateCursor) {
  86. SDL_Log("Changing cursor to \"%s\"", cursorNames[system_cursor]);
  87. SDL_FreeCursor(cursor);
  88. cursor = SDL_CreateSystemCursor((SDL_SystemCursor)system_cursor);
  89. SDL_SetCursor(cursor);
  90. }
  91. }
  92. }
  93. for (i = 0; i < state->num_windows; ++i) {
  94. SDL_Renderer *renderer = state->renderers[i];
  95. SDL_RenderClear(renderer);
  96. SDL_RenderPresent(renderer);
  97. }
  98. #ifdef __EMSCRIPTEN__
  99. if (done) {
  100. emscripten_cancel_main_loop();
  101. }
  102. #endif
  103. }
  104. int
  105. main(int argc, char *argv[])
  106. {
  107. int i;
  108. /* Enable standard application logging */
  109. SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
  110. SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS);
  111. /* Initialize test framework */
  112. state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
  113. if (!state) {
  114. return 1;
  115. }
  116. for (i = 1; i < argc;) {
  117. int consumed;
  118. consumed = SDLTest_CommonArg(state, i);
  119. if (consumed == 0) {
  120. consumed = -1;
  121. }
  122. if (consumed < 0) {
  123. SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
  124. quit(1);
  125. }
  126. i += consumed;
  127. }
  128. if (!SDLTest_CommonInit(state)) {
  129. quit(2);
  130. }
  131. for (i = 0; i < state->num_windows; ++i) {
  132. SDL_Renderer *renderer = state->renderers[i];
  133. SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
  134. SDL_RenderClear(renderer);
  135. }
  136. /* Main render loop */
  137. done = 0;
  138. #ifdef __EMSCRIPTEN__
  139. emscripten_set_main_loop(loop, 0, 1);
  140. #else
  141. while (!done) {
  142. loop();
  143. }
  144. #endif
  145. SDL_FreeCursor(cursor);
  146. quit(0);
  147. /* keep the compiler happy ... */
  148. return(0);
  149. }




声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/1018887
推荐阅读
  

闽ICP备14008679号