"SDL_SetVideoMode":找不到标识符

'SDL_SetVideoMode': identifier not found

本文关键字:找不到 标识符 SetVideoMode SDL      更新时间:2023-10-16

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

下面是如何在SDL2中替换SDL_SetVideoMode()的示例。为了进行比较,对初始化SDL的旧方法进行了注释,并将其与新方法一起保留。基本上,SDL2创建一个带有标题的窗口,然后创建一个附加到它的曲面,而SDL1单独创建一个曲面,然后调用窗口管理器为其命名。

if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    fprintf(stderr, "SDL video init failed: %sn", 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: %sn", SDL_GetError());
    return 1;
}
screenSurface = SDL_GetWindowSurface(window);
if (!screenSurface) {
    fprintf(stderr, "Screen surface could not be created: %sn", SDL_GetError());
    SDL_Quit();
    return 1;
}
// SDL_WM_SetCaption("Sphere Rendering", NULL);

再次查看该教程页面。您的代码与它不匹配(例如SDL_SetVideoMode()已不存在)。您的代码使用SDL1.2,(更新的)教程使用SDL2.0。您是否使用该页面的旧缓存版本?