Window not showing in 1.3 (newbie question)

Apologies for the naivety of this question:

I’ve adapted this code from the test sources, which compile and run on my
Ubuntu system, but in this form it doesn’t display a window at all. It
doesn’t display any errors, just doesn’t show a window. Can anybody cast
any light on what else I need to do please?

My reading indicates that it should be enough to include the flag
WINDOW_SHOWN in the init flags.

void showWindow(sdl_data *data, int bufferLength, char *buffer)
{
SDL_WindowID mainWnd;
if(SDL_Init(SDL_INIT_VIDEO) < 0){ fprintf(stderr,“Couldn’t initialize
SDL:%s\n”,SDL_GetError());}
if(SDL_VideoInit(NULL,0) < 0){ fprintf(stderr,“Couldn’t initialize
window:%s\n”,SDL_GetError());}
mainWnd = SDL_CreateWindow(“Title”, SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
if(mainWnd <= 0){ fprintf(stderr,“Couldn’t create
window:%s\n”,SDL_GetError());}
SDL_CreateRenderer(mainWnd, -1,
SDL_RENDERER_PRESENTFLIP2|SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_ACCELERATED);
SDL_SelectRenderer(mainWnd);
SDL_ShowWindow(mainWnd);
int width,height;
SDL_SetRenderDrawColor(85,85,85,85);
SDL_RenderFill(NULL);
SDL_RenderPresent();
}

Thanks!–
View this message in context: http://www.nabble.com/Window-not-showing-in-1.3-(newbie-question)-tp24009481p24009481.html
Sent from the SDL mailing list archive at Nabble.com.

Apologies for the naivety of this question:

I’ve adapted this code from the test sources, which compile and run on my
Ubuntu system, but in this form it doesn’t display a window at all. It
doesn’t display any errors, just doesn’t show a window. Can anybody cast
any light on what else I need to do please?

My reading indicates that it should be enough to include the flag
WINDOW_SHOWN in the init flags.

void showWindow(sdl_data *data, int bufferLength, char *buffer)
{
SDL_WindowID mainWnd;
if(SDL_Init(SDL_INIT_VIDEO) < 0){ fprintf(stderr,“Couldn’t initialize
SDL:%s\n”,SDL_GetError());}
if(SDL_VideoInit(NULL,0) < 0){ fprintf(stderr,“Couldn’t initialize
window:%s\n”,SDL_GetError());}
mainWnd = SDL_CreateWindow(“Title”, SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
if(mainWnd <= 0){ fprintf(stderr,“Couldn’t create
window:%s\n”,SDL_GetError());}
SDL_CreateRenderer(mainWnd, -1,

SDL_RENDERER_PRESENTFLIP2|SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_ACCELERATED);
SDL_SelectRenderer(mainWnd);
SDL_ShowWindow(mainWnd);
int width,height;
SDL_SetRenderDrawColor(85,85,85,85);
SDL_RenderFill(NULL);
SDL_RenderPresent();
}

No one replied? Hmm, looks like the window would be created and immediately
destroyed with the program ends. So, it would create a window, but it would
delete it so fast you wouldn’t ever see it.

Bob PendletonOn Sat, Jun 13, 2009 at 1:00 AM, Chris Hagan <captain.mister.hagan at gmail.com wrote:

Thanks!

View this message in context:
http://www.nabble.com/Window-not-showing-in-1.3-(newbie-question)-tp24009481p24009481.html
Sent from the SDL mailing list archive at Nabble.com.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------

Can’t get a window to display either… Adapted some of the code from testsprite2.c.

My code looks very similar, and I try to get an OpenGL window.

I also thought it may simply be disappearing so I added an SDL_Delay(10000);

Aside from wasting 10 seconds of my life each time, it didn’t do anything else.

Pat

PS: Happy anniversary =)
(Oh, and as for coding/compiling under Windows, I run XP in Sun’s Virtualbox… I feel less dirty that way)________________________________
From: bob@pendleton.com (Bob Pendleton)
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Wednesday, June 17, 2009 3:25:54 PM
Subject: Re: [SDL] Window not showing in 1.3 (newbie question)

On Sat, Jun 13, 2009 at 1:00 AM, Chris Hagan <captain.mister.hagan at gmail.com> wrote:

Apologies for the naivety of this question:

I’ve adapted this code from the test sources, which compile and run on my
Ubuntu system, but in this form it doesn’t display a window at all. It
doesn’t display any errors, just doesn’t show a window. Can anybody cast
any light on what else I need to do please?

My reading indicates that it should be enough to include the flag
WINDOW_SHOWN in the init flags.

void showWindow(sdl_data *data, int bufferLength, char *buffer)
{
SDL_WindowID mainWnd;
if(SDL_Init(SDL_INIT_VIDEO) < 0){ fprintf(stderr,“Couldn’t initialize
SDL:%s\n”,SDL_GetError());}
if(SDL_VideoInit(NULL,0) < 0){ fprintf(stderr,“Couldn’t initialize
window:%s\n”,SDL_GetError());}
mainWnd = SDL_CreateWindow(“Title”, SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
if(mainWnd <= 0){ fprintf(stderr,“Couldn’t create
window:%s\n”,SDL_GetError());}
SDL_CreateRenderer(mainWnd, -1,
SDL_RENDERER_PRESENTFLIP2|SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_ACCELERATED);
SDL_SelectRenderer(mainWnd);
SDL_ShowWindow(mainWnd);
int width,height;
SDL_SetRenderDrawColor(85,85,85,85);
SDL_RenderFill(NULL);
SDL_RenderPresent();
}

No one replied? Hmm, looks like the window would be created and immediately destroyed with the program ends. So, it would create a window, but it would delete it so fast you wouldn’t ever see it.

Bob Pendleton

Thanks!

View this message in context: http://www.nabble.com/Window-not-showing-in-1.3-(newbie-question)-tp24009481p24009481.html
Sent from the SDL mailing list archive at Nabble.com.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------

Well, I don’t understand the problem, so here is a simple SDL program that
runs on Ubuntu 9.04 using SDL 1.3 from svn. it just brings up 2 windows that
you can move around and resize. When you click close on one of the windows
it kills the program. It is included as an attachment.

Bob PendletonOn Wed, Jun 17, 2009 at 3:40 PM, Patryk Bratkowski wrote:

Can’t get a window to display either… Adapted some of the code from
testsprite2.c.

My code looks very similar, and I try to get an OpenGL window.

I also thought it may simply be disappearing so I added an
SDL_Delay(10000);

Aside from wasting 10 seconds of my life each time, it didn’t do anything
else.

Pat

PS: Happy anniversary =)
(Oh, and as for coding/compiling under Windows, I run XP in Sun’s
Virtualbox… I feel less dirty that way)


From: Bob Pendleton <@Bob_Pendleton>
To: A list for developers using the SDL library. (includes SDL-announce)

Sent: Wednesday, June 17, 2009 3:25:54 PM
Subject: Re: [SDL] Window not showing in 1.3 (newbie question)

On Sat, Jun 13, 2009 at 1:00 AM, Chris Hagan < captain.mister.hagan at gmail.com> wrote:

Apologies for the naivety of this question:

I’ve adapted this code from the test sources, which compile and run on my
Ubuntu system, but in this form it doesn’t display a window at all. It
doesn’t display any errors, just doesn’t show a window. Can anybody cast
any light on what else I need to do please?

My reading indicates that it should be enough to include the flag
WINDOW_SHOWN in the init flags.

void showWindow(sdl_data *data, int bufferLength, char *buffer)
{
SDL_WindowID mainWnd;
if(SDL_Init(SDL_INIT_VIDEO) < 0){ fprintf(stderr,“Couldn’t initialize
SDL:%s\n”,SDL_GetError());}
if(SDL_VideoInit(NULL,0) < 0){ fprintf(stderr,“Couldn’t initialize
window:%s\n”,SDL_GetError());}
mainWnd = SDL_CreateWindow(“Title”, SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
if(mainWnd <= 0){ fprintf(stderr,“Couldn’t create
window:%s\n”,SDL_GetError());}
SDL_CreateRenderer(mainWnd, -1,

SDL_RENDERER_PRESENTFLIP2|SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_ACCELERATED);
SDL_SelectRenderer(mainWnd);
SDL_ShowWindow(mainWnd);
int width,height;
SDL_SetRenderDrawColor(85,85,85,85);
SDL_RenderFill(NULL);
SDL_RenderPresent();
}

No one replied? Hmm, looks like the window would be created and immediately
destroyed with the program ends. So, it would create a window, but it would
delete it so fast you wouldn’t ever see it.

Bob Pendleton

Thanks!

View this message in context:
http://www.nabble.com/Window-not-showing-in-1.3-(newbie-question)-tp24009481p24009481.html
Sent from the SDL mailing list archive at Nabble.com.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------

Thanks, Bob.

You were right, I think. When I pushed the render into the loop it
maintained a visible window. The reason I hadn’t thought that would happen
is that it’s actually being run as an Erlang port driver, so the process
doesn’t technically end with the execution of that method.

Now that Erlang’s got control of the framerate and is forcing rerenders the
window persists.

Thanks again.

Bob Pendelton said: No one replied? Hmm, looks like the window would be
created and immediately
destroyed with the program ends. So, it would create a window, but it would
delete it so fast you wouldn’t ever see it.–
View this message in context: http://www.nabble.com/Window-not-showing-in-1.3-(newbie-question)-tp24009481p24084781.html
Sent from the SDL mailing list archive at Nabble.com.

2009/6/13 Chris Hagan <captain.mister.hagan at gmail.com>

void showWindow(sdl_data *data, int bufferLength, char *buffer)
{
SDL_WindowID mainWnd;
if(SDL_Init(SDL_INIT_VIDEO) < 0){ fprintf(stderr,“Couldn’t initialize
SDL:%s\n”,SDL_GetError());}
if(SDL_VideoInit(NULL,0) < 0){ fprintf(stderr,“Couldn’t initialize
window:%s\n”,SDL_GetError());}
mainWnd = SDL_CreateWindow(“Title”, SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN);
if(mainWnd <= 0){ fprintf(stderr,“Couldn’t create
window:%s\n”,SDL_GetError());}
SDL_CreateRenderer(mainWnd, -1,

SDL_RENDERER_PRESENTFLIP2|SDL_RENDERER_PRESENTVSYNC|SDL_RENDERER_ACCELERATED);
SDL_SelectRenderer(mainWnd);
SDL_ShowWindow(mainWnd);
int width,height;
SDL_SetRenderDrawColor(85,85,85,85);
SDL_RenderFill(NULL);
SDL_RenderPresent();
}

A few things here…

You don’t need both SDL_Init(SDL_INIT_VIDEO) and SDL_VideoInit(NULL,0).
You can either use SDL_Init(SDL_INIT_VIDEO) and later use SDL_Quit() or use
SDL_Init(0) followed by SDL_VideoInit(NULL,0) and later use SDL_VideoQuit()
followed by SDL_Quit(). Also, remember you really don’t need to call
SDL_Init or SDL_VideoInit more than once in your program, so you might want
to move it into main() instead.

Also, in each of your checks, you should really use != 0, not < 0, since
anything, positive or negative, other than 0 is an error, and in the case of
mainWnd <= 0, it should be mainWnd == 0, since SDL_WindowID is not signed.

You’re right about SDL_WINDOW_SHOW. If you have that in the
SDL_CreateWindow flags then the window should be visible by default, which
means you don’t need SDL_ShowWindow(mainWnd);

width and height are never used. Neither are any of the parameters you pass
in.

If you plan to do anything with this window outside of this function
(drawing to it, closing it, etc), you will probably want to return mainWnd.

What Bob mentioned isn’t quite right. There’s nothing here that would close
the window, but if all your program does is call this function and then
exit, then the user will not see the window. You still need to usual SDL
event loop. One thing worthy of note is that clicking the window’s close
button will not send an SDL_QUIT event as it would with a window created
using SDL_SetVideoMode. You should watch for SDL_WINDOWEVENT instead with
.window.event == SDL_WINDOWEVENT_CLOSE instead.

The last parameter to SDL_SetRenderDrawColor() is the alpha value, or
opacity, which will be used to blend the color with whatever is already
there. In this case, you would want 255 or 0xFF, not 85.

At present, when an error occurs, you print an error message, but keep on
going. You need to add a return statement after each fprintf.

SDL_CreateRenderer will fail if it can’t find a render driver that matches
the flags you pass in. You might want to use fewer flags for
SDL_CreateRenderer() and check the return value to see if you were
successful or not. For example, you could use:
if (SDL_CreateRenderer(mainWnd, -1, SDL_RENDERER_PRESENTFLIP2) != 0) {
fprintf(stderr,“Couldn’t initialize renderer: %s\n”,SDL_GetError());
return 0;
}

If you want an example of how to use rendering contexts to draw to the
screen, check out test/testdraw2.c in trunk/SDL on svn.