'SDL_SetVideoMode':找不到标识符

时间:2015-02-08 23:01:43

标签: c++ visual-studio sdl

我的SDL lib有问题。我正在使用VS2012 Ultimate,我实际上正在使用本教程:http://lazyfoo.net/tutorials/SDL/01_hello_SDL/index2.php设置所有内容,我一步一步地做了几次,但我仍然有问题这是我的代码,非常简单:

#include <iostream> 
#include <SDL.h>

SDL_Surface * ekran = NULL;

int main (int argc, char *args [] )
{
   SDL_Init( SDL_INIT_EVERYTHING );
   ekran = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
   SDL_Flip( ekran );
   SDL_Delay( 2000 );
   SDL_Quit();
   return 0;
} 

并且我有这个错误:

error C3861: 'SDL_SetVideoMode': identifier not found
error C3861: 'SDL_Flip': identifier not found

2 个答案:

答案 0 :(得分:2)

再次查看该教程页面。您的代码与之不匹配(例如,SDL_SetVideoMode()不再存在)。您的代码使用SDL 1.2,而(更新的)教程使用SDL 2.0。您使用的是该页面的旧缓存版本吗?

答案 1 :(得分:2)

下面是如何替换SDL2中的SDL_SetVideoMode()的示例。初始化初始化SDL的方法被评论并与新方法一起用于比较目的。基本上,SDL2创建一个带有标题的窗口,然后是一个附加到它的表面,而SDL1单独创建一个表面,然后调用窗口管理器为它命名。

if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    fprintf(stderr, "SDL video init failed: %s\n", SDL_GetError());
    return 1;
}

// SDL_Surface *screenSurface = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_SWSURFACE);

SDL_Window* window = NULL;
SDL_Surface* screenSurface = NULL;

window = SDL_CreateWindow("Sphere Rendering", 
    SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 
    SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);

if (window == NULL) {
    fprintf(stderr, "Window could not be created: %s\n", SDL_GetError());
    return 1;
}

screenSurface = SDL_GetWindowSurface(window);

if (!screenSurface) {
    fprintf(stderr, "Screen surface could not be created: %s\n", SDL_GetError());
    SDL_Quit();
    return 1;
}

// SDL_WM_SetCaption("Sphere Rendering", NULL);