Sample code for using SDL 1.3

Hi,

      Can any one tell, how to use SDL 1.3, some sample code, which 

is used to creat SDL window, and etc…

I wrote one test.c but I didn’t get output for that,

#include <SDL/SDL.h>
int main()
{
SDL_Window *win = NULL;
int width = 320, height = 240;

    if (SDL_Init(SDL_INIT_VIDEO)) {
            printf("ERROR: SDL_INIT_VIDEO filed\n");
            return -1;
    }

    printf("INFO : win = %p\n", win);            // printing (nil)

    win = SDL_CreateWindow ("Hello World", 10, 10, width, height, 

SDL_SWSURFACE);
// win = SDL_CreateWindow (“Hello World”, 10, 10, width, height,
SDL_HWSURFACE);
if(win == NULL) {
printf(“ERROR: SDL_CreateWindow Failed\n”);
return -1;
}
printf(“INFO : SDL_CreateWindow Success win = %p\n”, win);

    SDL_ShowWindow(win);
    sleep(10);
    SDL_DestroyWindow(win);

    return 0;

}

I don’t why I’m not getting error or proper output, Please guide me…
I think i’m not using the APIs properly…–
Lohitha R

You can check out examples in the source distribution of SDL 1.3.

Jonny DOn Tue, May 18, 2010 at 5:17 AM, Lohitha R <lohitha.r at globaledgesoft.com>wrote:

Hi,

    Can any one tell, how to use SDL 1.3, some sample code, which is

used to creat SDL window, and etc…

I wrote one test.c but I didn’t get output for that,

#include <SDL/SDL.h>
int main()
{
SDL_Window *win = NULL;
int width = 320, height = 240;

  if (SDL_Init(SDL_INIT_VIDEO)) {
          printf("ERROR: SDL_INIT_VIDEO filed\n");
          return -1;
  }

  printf("INFO : win = %p\n", win);            // printing (nil)

  win = SDL_CreateWindow ("Hello World", 10, 10, width, height,

SDL_SWSURFACE);
// win = SDL_CreateWindow (“Hello World”, 10, 10, width, height,
SDL_HWSURFACE);
if(win == NULL) {
printf(“ERROR: SDL_CreateWindow Failed\n”);
return -1;
}
printf(“INFO : SDL_CreateWindow Success win = %p\n”, win);

  SDL_ShowWindow(win);
  sleep(10);
  SDL_DestroyWindow(win);

  return 0;

}

I don’t why I’m not getting error or proper output, Please guide me… I
think i’m not using the APIs properly…


Lohitha R


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

If you’re compiling on Windows, make sure you are compiling as a
console app or you might not get any output from printf() even when
program is run from a console. Also, there’s a minimum window size on
Windows, 320x240 is probably OK, but try increasing it to 640x480.

Try assigning a renderer before showing the window and call
SDL_UpdateWindow() after SDL_ShowWindow().

Don’t use sleep(10), you could try SDL_Delay(10000), but you’re better
to implement an event loop. Look up SDL_WaitEvent() and SDL_PollEvent
in the documentation wiki. On Windows, and probably other platforms,
SDL may need to respond to events for the window to actually show up,
which means SDL_PumpEvents() needs to be called a few times after the
window is created and shown. SDL_WaitEvent() or SDL_PollEvent() will
take care of this for you.On 18/05/2010, Lohitha R <lohitha.r at globaledgesoft.com> wrote:

Hi,

      Can any one tell, how to use SDL 1.3, some sample code, which

is used to creat SDL window, and etc…

I wrote one test.c but I didn’t get output for that,

#include <SDL/SDL.h>
int main()
{
SDL_Window *win = NULL;
int width = 320, height = 240;

    if (SDL_Init(SDL_INIT_VIDEO)) {
            printf("ERROR: SDL_INIT_VIDEO filed\n");
            return -1;
    }

    printf("INFO : win = %p\n", win);            // printing (nil)

    win = SDL_CreateWindow ("Hello World", 10, 10, width, height,

SDL_SWSURFACE);
// win = SDL_CreateWindow (“Hello World”, 10, 10, width, height,
SDL_HWSURFACE);
if(win == NULL) {
printf(“ERROR: SDL_CreateWindow Failed\n”);
return -1;
}
printf(“INFO : SDL_CreateWindow Success win = %p\n”, win);

    SDL_ShowWindow(win);
    sleep(10);
    SDL_DestroyWindow(win);

    return 0;

}

I don’t why I’m not getting error or proper output, Please guide me…
I think i’m not using the APIs properly…

I believe the best test to see is testsprite2.cOn Tue, May 18, 2010 at 10:39 AM, Kenneth Bull wrote:

On 18/05/2010, Lohitha R <lohitha.r at globaledgesoft.com> wrote:

Hi,

      Can any one tell, how to use SDL 1.3, some sample code, which

is used to creat SDL window, and etc…

I wrote one test.c but I didn’t get output for that,

#include <SDL/SDL.h>
int main()
{
SDL_Window *win = NULL;
int width = 320, height = 240;

    if (SDL_Init(SDL_INIT_VIDEO)) {
            printf("ERROR: SDL_INIT_VIDEO filed\n");
            return -1;
    }

    printf("INFO : win = %p\n", win);            // printing (nil)

    win = SDL_CreateWindow ("Hello World", 10, 10, width, height,

SDL_SWSURFACE);
// win = SDL_CreateWindow (“Hello World”, 10, 10, width, height,
SDL_HWSURFACE);
if(win == NULL) {
printf(“ERROR: SDL_CreateWindow Failed\n”);
return -1;
}
printf(“INFO : SDL_CreateWindow Success win = %p\n”, win);

    SDL_ShowWindow(win);
    sleep(10);
    SDL_DestroyWindow(win);

    return 0;

}

I don’t why I’m not getting error or proper output, Please guide me…
I think i’m not using the APIs properly…

If you’re compiling on Windows, make sure you are compiling as a
console app or you might not get any output from printf() even when
program is run from a console. Also, there’s a minimum window size on
Windows, 320x240 is probably OK, but try increasing it to 640x480.

Try assigning a renderer before showing the window and call
SDL_UpdateWindow() after SDL_ShowWindow().

Don’t use sleep(10), you could try SDL_Delay(10000), but you’re better
to implement an event loop. Look up SDL_WaitEvent() and SDL_PollEvent
in the documentation wiki. On Windows, and probably other platforms,
SDL may need to respond to events for the window to actually show up,
which means SDL_PumpEvents() needs to be called a few times after the
window is created and shown. SDL_WaitEvent() or SDL_PollEvent() will
take care of this for you.


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


David