SDL 窗口不显示。
SDL Window doesn't appear.
这是我在 SDL 的第二个程序。我尝试加载位置图像("C:/Users/user/Desktop/learning_sdl/bpn.bmp")并将其显示在 SDL 窗口中。程序编译时没有错误。但是,我只能看到控制台屏幕。请帮忙。
#include<iostream>
#include<sdl.h>
using namespace std;
bool init(); //initializes window and surface.
bool loadimage(); //loads image
void close(); //free surface and destroy pointer
SDL_Window* w; //window pointer
SDL_Surface*img; //image pointter
SDL_Surface*surf; //surface pointer
const int scrWidth=640;
const int scrLength=400;
int main(int argc, char*args[])
{
if(!init)
{
cout<<"Sorry, Cannot Initialize the window."<<SDL_GetError();
}
else
{
if(!loadimage())
{
cout<<"Cannot load images."<<SDL_GetError();
}
else
{
SDL_BlitSurface( img, NULL, surf, NULL );
SDL_UpdateWindowSurface(w);
SDL_Delay(10000);
}
}
close();
}
bool init()
{
bool status=true;
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
cout<<"Cannot initialize SDL"<<SDL_GetError();
status=false;
}
else
{
w=SDL_CreateWindow("bipin",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,scrWidth,scrLength,SDL_WINDOW_SHOWN);
if (w==NULL)
{
cout<<"Cannot create sdl window"<<SDL_GetError();
status=false;
}
else
{
surf=SDL_GetWindowSurface(w);
if (surf==NULL) status=false;
}
}
return status;
}
bool loadimage()
{
bool status=true;
img=SDL_LoadBMP("C:/Users/user/Desktop/learning_sdl/bpn.bmp");
if (img==NULL)
{
cout<<"Unable to find image."<<SDL_GetError();
status=false;
}
return status;
}
void close()
{
SDL_FreeSurface(img);
SDL_FreeSurface(surf);
img=NULL;
surf=NULL;
SDL_DestroyWindow(w);
w=NULL;
SDL_Quit();
}
int 你的代码,在 main 函数上:
if(!init)
{
cout<<"Sorry, Cannot Initialize the window."<<SDL_GetError();
}
请注意,init 是一个函数,但不是函数调用,而是使用:
if(!init())
{
cout<<"Sorry, Cannot Initialize the window."<<SDL_GetError();
}
相关文章:
- 使用 while 循环时不显示窗口
- 有没有办法拿一个opencv显示窗口并将其保存到GUI窗口?
- SDL视频显示窗口:如何连接窗口关闭事件回调
- Qt:缓慢启动时显示窗口内容
- 为什么MessageBox在我创建的桌面中显示窗口,而AllocConsole在上一个桌面中显示它
- 如何显示窗口大小不同的输出图像?通过使用 cv::Mat
- QMLApplicationViewer 多个实例仅首先显示窗口
- 为什么HWND_NOTTOPMOST无法在xp中显示窗口前景
- 基本C++SFML显示窗口错误
- 使用Richedit控件时,基于对话框的Win32 API程序将不会显示窗口
- 显示窗口的极简主义Visual C++应用程序
- Win32:是否可以显示窗口,但在任务栏中隐藏它
- OpenCV-关闭图像显示窗口
- IWebBrowser2在渲染完成后显示窗口
- 防止在调用SDL_SetVideoMode后显示窗口
- 如何使用rad studio显示窗口总数
- Opencv highgui显示窗口
- 使用sfml显示窗口
- 跨平台c++库/库:显示窗口,在屏幕上渲染2D形状,在屏幕上渲染文本
- 用于创建菜单栏的c++ win32程序(程序编译并运行,也显示窗口但不显示菜单栏)