c++ - 将 SDL 表面传递给函数

标签 c++ sdl

我有点困惑如何将我的 SDL_Surface 传递给我的函数,以便我可以在 SDL 中设置我的屏幕。

这是我的错误:

 No operator "=" matches these operands

我的功能是这样的:

void SDL_Start(SDL_Surface screen){
Uint32 videoflags = SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT;// | SDL_FULLSCREEN;

// Initialize the SDL library 
    if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
         fprintf(stderr, "Couldn't initialize SDL: %s\n",
         SDL_GetError());
         exit(500);
    }   
//get player's screen info
const SDL_VideoInfo* myScreen = SDL_GetVideoInfo();


//SDL screen

int reso_x = myScreen->current_w;
int reso_y = myScreen->current_h;
Uint8  video_bpp = 32;

//setup Screen [Error on the line below]
screen = SDL_SetVideoMode(reso_x, reso_y, video_bpp, videoflags|SDL_FULLSCREEN); 
}

这个函数在我的主函数中是这样调用的:

SDL_Surface *screen;
SDL_Start(*screen); 

知道错误是什么吗?

最佳答案

SDL_SetVideoMode 返回一个 SDL_Surface*(指针类型),但您将其分配给一个 SDL_Surface(非指针)。

编辑:这可能就是您想要的。返回指向新表面的指针。

SDL_Surface* SDL_Start() {
Uint32 videoflags = SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT;// | SDL_FULLSCREEN;

// Initialize the SDL library 
    if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
         fprintf(stderr, "Couldn't initialize SDL: %s\n",
         SDL_GetError());
         exit(500);
    }   
//get player's screen info
const SDL_VideoInfo* myScreen = SDL_GetVideoInfo();


//SDL screen

int reso_x = myScreen->current_w;
int reso_y = myScreen->current_h;
Uint8  video_bpp = 32;

//setup Screen [Error on the line below]
return SDL_SetVideoMode(reso_x, reso_y, video_bpp, videoflags|SDL_FULLSCREEN); 
}

// ...

SDL_Surface *screen = SDL_Start();

关于c++ - 将 SDL 表面传递给函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13151175/

相关文章:

c++ - 变量指针的成员函数没有绘制到 SDL_Surface?

c++ - 在 C++ 中分配泛型类

c++ - 无符号/有符号不匹配

c++ - 所有模板参数包的默认值都是 "empty"吗?

c++ - glReadPixels 从错误的位置读取

c++ - 从 SDL_Surface 读取像素并转换为颜色值

c++ - Linux、C++、第三方库

c++ - 为什么cppreference在介绍bitsets的时候没有得到_Base_bitset的知识点呢?

c++ - 用 vector 重载 ostream 运算符

c - 如何将 SDL_Surface 转换为 GtkImage