Hi again,
below is another bit of (arguably pointless) code that I would expect to
do the following:
- create a window (and hide it)
- show that window after 2 seconds
- hide that window after yet another 2 seconds
- destroy the window and wait 2 seconds.
- shut down sdl
Compiling this with SDL 1.3, zipped distribution, revision 4948, on a
Linux Ubuntu 10.04 running a 2.6.32-27-generic kernel and nvidia driver
195.36.24, the SDL_ShowWindow and SDL_HideWindow functions have
absolutely no effect (other than setting the window flags appropriately,
that is). Strangely enough, even after calling SDL_DestroyWindow, the
window remains visible (is actually also brought to the top of all
windows), and is only destroyed after SDL_Quit is called.
It seems that on Linux, SDL window management is still a little buggy.
Does anyone else here have these issues on Linux? As I do not have a
windows environment set up, could someone test what the code below
actually does on windows (perhaps also Mac)?
Thanks in advance. Here’s the code:
#include
#include <SDL/SDL.h>
struct Window
{
Window() : m_Window(0) {};
~Window() {}
bool create(int px,int py,int dx,int dy,Uint32 flags = 0)
{
bool rval = false;
if (!m_Window)
{
m_Window = SDL_CreateWindow("",px,py,dx,dy,flags |
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
m_Context = SDL_GL_CreateContext(m_Window);
if (m_Window && !(flags & SDL_WINDOW_SHOWN))
{
hide();
}
rval = (m_Window != 0);
}
return rval;
}
void destroy()
{
if (m_Window)
{
SDL_GL_DeleteContext(m_Context);
SDL_DestroyWindow(m_Window);
m_Window = 0;
std::cerr << “destroy(): done\n”;
}
}
void show()
{
if (m_Window)
{
SDL_ShowWindow(m_Window);
bool failed = (SDL_GetWindowFlags(m_Window) & SDL_WINDOW_SHOWN);
std::cerr << "show(): " << (failed ? “yes” : “no”) << std::endl;
}
}
void hide()
{
if (m_Window)
{
SDL_HideWindow(m_Window);
bool failed = !(SDL_GetWindowFlags(m_Window) & SDL_WINDOW_SHOWN);
std::cerr << "hide(): " << (failed ? “yes” : “no”) << std::endl;
}
}
SDL_Window * m_Window;
SDL_GLContext m_Context;
};
int main(int,char**)
{
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
exit(-1);
}
int posx = SDL_WINDOWPOS_CENTERED;
int posy = SDL_WINDOWPOS_CENTERED;
int winw = 320;
int winh = 200;
Window win;
win.create(posx,posy,winw,winh);
SDL_Delay(2000);
win.show();
SDL_Delay(2000);
win.hide();
SDL_Delay(2000);
win.destroy();
SDL_Delay(2000);
SDL_Quit();
// test if window is destroyed by SDL_Quit or program exit
//while (true) {}
return 0;
}