Simplest SDL 2.0 Code

Hello, I’m really new to SDL 2.0, I used to make little projects with SDL 1.2 with no trouble, but as soon as I tried to do something with the new stable release I don’t seem to make it work.

This code is basically the same in the wiki, but I was expecting this to make a window visible and leave it open, what happens is that it creates the window but it closes immediately. Is there something missing here?

Here’s the code.

#include “SDL2/SDL.h”

int main (int argc, char *argv[]){

SDL_Window *window;
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow(
    "Test Window",
    SDL_WINDOWPOS_UNDEFINED,
    SDL_WINDOWPOS_UNDEFINED,
    800,
    600,
    SDL_WINDOW_OPENGL);

if (window == NULL) {
    printf("Could not create window: %s\n", SDL_GetError());
    return 1;
}

SDL_Quit();
return 0;

}

Also, if I put a SDL_Delay(5000); just before de SDL_Quit();, the window stays for 5 seconds, but when I hover the mouse over the window, it changes to the “busy” cursor.------------------------
~C8>
Mouse!

SDL 2 still uses the same general event loop work, and without the loop,
the window manager assumes it’s busy and not processing events and Vince’s
the busy cursor. The code you posted works exactly as expected. Sorry for
the lack of details I’m on my mobile. Search the SDL 2 wiki for event
handling.On 21 Dec 2013 11:49, “unCerdo” <nosgoth_k at hotmail.com> wrote:

Hello, I’m really new to SDL 2.0, I used to make little projects with
SDL 1.2 with no trouble, but as soon as I tried to do something with the
new stable release I don’t seem to make it work.

This code is basically the same in the wiki, but I was expecting this to
make a window visible and leave it open, what happens is that it creates
the window but it closes immediately. Is there something missing here?

Here’s the code.

#include “SDL2/SDL.h”

int main (int argc, char *argv[]){

SDL_Window *window;
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow(
“Test Window”,
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
800,
600,
SDL_WINDOW_OPENGL);

if (window == NULL) {
printf(“Could not create window: %s\n”, SDL_GetError());
return 1;
}

SDL_Quit();
return 0;
}

Also, if I put a SDL_Delay(5000); just before de SDL_Quit();, the window
stays for 5 seconds, but when I hover the mouse over the window, it changes
to the “busy” cursor.


~C8>
Mouse!


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

Thank you very much for your reply MrOzBarry, I’ll check the event handling wiki.------------------------
~C8>
Mouse!

Add the new code below. The SDL_QUIT event will occur when you click on the
close button at the upper right corner of your window.

Hello, I’m really new to SDL 2.0, I used to make little projects with SDL
1.2 with no trouble, but as soon as I tried to do something with the new
stable release I don’t seem to make it work.

This code is basically the same in the wiki, but I was expecting this to
make a window visible and leave it open, what happens is that it creates
the window but it closes immediately. Is there something missing here?

Here’s the code.

#include “SDL2/SDL.h”

int main (int argc, char *argv[]){

int done = 0;
SDL_Event event;
SDL_Window *window;
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow(
    "Test Window",
    SDL_WINDOWPOS_UNDEFINED,
    SDL_WINDOWPOS_UNDEFINED,
    800,
    600,
    SDL_WINDOW_OPENGL);

if (window == NULL) {
    printf("Could not create window: %s\n", SDL_GetError());
    return 1;
}
while (!done)
{
	while (SDL_PollEvent(&event))
	{
		switch (event.type)
		{
			case SDL_QUIT:
				done = true;
				break;

// process other SDL events with appropriate cases

		}

// add a delay (sleep) if appropriate for your app

	}
}On Friday 20 December 2013 20:40:56 unCerdo wrote:
SDL_Quit();
return 0;

}

Also, if I put a SDL_Delay(5000); just before de SDL_Quit();, the window
stays for 5 seconds, but when I hover the mouse over the window, it
changes to the “busy” cursor.


~C8>
Mouse!


“Women don’t want to hear what you think.
Women want to hear what they think - in a deeper voice.”
–Bill Cosby

j_post wrote:

Add the new code below. The SDL_QUIT event will occur when you click on the
close button at the upper right corner of your window.

Works like a charm j_post, thanks a lot, I had gotten to the event part, I was missing the general “while(!done)” loop.------------------------
~C8>
Mouse!