将SDL表面传递到功能
Passing an SDL surface to a function
我有点困惑如何将我的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: %sn",
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: %sn",
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();
SDL_SetVideoMode
将指针返回到sdl_surface。但是screen
不是指针。无论如何,您都不应该按值传递SDL_SURFACE对象,这会弄乱其参考计数,甚至可能是其他问题。如我所见,您在这里有两个选择。通过参考传递SDL_SURFACE指针:
void SDL_Start(SDL_Surface*& screen) {
...
screen = SDL_SetVideoMode(reso_x, reso_y, video_bpp, videoflags|SDL_FULLSCREEN);
}
或让该函数没有参数,然后返回指针:
SDL_Surface* SDL_Start() {
...
return SDL_SetVideoMode(reso_x, reso_y, video_bpp, videoflags|SDL_FULLSCREEN);
}
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 多态性和功能结合
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 带内存和隔离功能的SQLite
- 在CMakeLists.txt的安装功能中使用.cmake文件有什么用
- Mix_Init和Mix_OpenAudio SDL之间的区别是什么
- 类模板的成员功能的定义在单独的TU中完全专业化
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- SDL 窗口不会弹出
- 如何在C++中获得"静态纯虚拟"功能?
- 两个文件使用彼此的功能-如何解决
- 我应该实现右值推送功能吗?我应该使用std::move吗
- QML按钮点击功能执行顺序
- 无法理解此 return 语句的功能,没有它就会发生运行时错误
- 有没有可能有一个只有ADL才能找到的非好友功能
- 功能样式转换从 'int' 到 'ItemType' 的匹配转换
- 文件系统:复制功能的速度秘诀是什么
- 将SDL表面传递到功能
- C++ SDL 功能在首次启动后似乎不会改变主表面
- SDL 找不到我的主要功能