Need help in my SDL window

This is a discussion on Need help in my SDL window within the Game Programming forums, part of the General Programming Boards category; >///< i feel like a noob having trouble in SDL but i get an error In function `int SDL_main(int, char**)': ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    123

    Need help in my SDL window

    >///< i feel like a noob having trouble in SDL but
    i get an error In function `int SDL_main(int, char**)':
    `void SDL_Quit()' cannot appear in a constant-expression
    Makefile.win [Build Error] [window.o] Error 1

    Code:
    int main(int argc, char *argv[])
    {
       
      if(SDL_Init(SDL_INIT_VIDEO) < 0) {
      fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
      exit(1);
      }
      SDL_Surface *screen;
      
      screen = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,SDL_SWSURFACE);
      if(screen == NULL)
      {
          printf("Unable to set video mode:%s\n",SDL_GetError());
          exit(1);
    }
    
      SDL_WM_SetCaption("Justin's game",0);
     { 
      SDL_Event event;
      
      SDL_WaitEvent(&event);
      
             switch(event.type)
             {
               case SDL_KEYDOWN:
                printf("The %s key was pressed!\n",
                       SDL_GetKeyName(event.key.keysym.sym));
                break;
                case SDL_Quit:
                    exit(0);
             }
      
    }  
      
      
      
    }
    oohh i didn't add the includes up in that copy but there cstdlib,cstdio, SDL.h, and the defines for WIDTH,HEIGHT, and BPP :P

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    123
    Never mind i found the problem it was case SDL_QUIT instead of SDL_Quit XD idiot me

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    New York
    Posts
    123
    The only problem now is that that window instantly closes

  4. #4
    Registered User
    Join Date
    Apr 2007
    Location
    Malta
    Posts
    9
    I think you need a variable for the 'game loop'. Declare a variable like:

    bool quit = false;

    Then put your event handling in a loop that checks whether quit is still false.

    Code:
    while (quit == false)
    {
     SDL_WaitEvent(&event);
      
             switch(event.type)
             {
               case SDL_KEYDOWN:
                printf("The %s key was pressed!\n",
                       SDL_GetKeyName(event.key.keysym.sym));
                break;
                case SDL_Quit:
                    quit = true;
             }
    }
    Note how I've changed your SDL_Quit case.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Note how I've changed your SDL_Quit case.
    You didn't:
    Code:
    case SDL_Quit:
    It should be SDL_QUIT as mentioned.

    BTW, you should be calling SDL_Quit() when your program exits. Often this is done by calling
    Code:
    atexit(SDL_Quit);
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    C maniac
    Join Date
    Aug 2004
    Location
    Cyberwarping to Middle Earth
    Posts
    154
    Code:
    SDL_WM_SetCaption("<EDITED>'s game",0);
    Try not to put that kind of thing on the internet. Now we all know your real name is. At least it's not your full name and phone number . . .

    Quote Originally Posted by dwks
    BTW, you should be calling SDL_Quit() when your program exits. Often this is done by calling

    Code:
    atexit(SDL_Quit);
    That's considered bad SDL programming practise. Read the SDL Tutorials section of the SDL documentation for why, as I don't remember
    Last edited by kawk; 04-18-2007 at 11:57 AM.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Quote Originally Posted by kawk View Post
    Try not to put that kind of thing on the internet. Now we all know your real name is [---]. At least it's not your full name and phone number . . .
    Try not to make posts like that, so that if the OP decides to edit his or her post, it's not recorded in your post.

    That's considered bad SDL programming practise. Read the SDL Tutorials section of the SDL documentation for why, as I don't remember
    There's nothing wrong with it AFAIK; it's actually in the tutorials. (That having been said, I never use it myself. )
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    C maniac
    Join Date
    Aug 2004
    Location
    Cyberwarping to Middle Earth
    Posts
    154
    There's nothing wrong with it AFAIK; it's actually in the tutorials. (That having been said, I never use it myself. )
    According to the SDL 1.2.9 tutorials, it's "fine for small applications, but should not be used in larger programs". I imagine it's because if your program has crashed so badly that you have corrupted the loaded SDL libraries (Which I _have_ done, BTW) and you try to call SDL_Quit . . . well, lets just say it's not pretty.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 09:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 11:17 AM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 11:50 AM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 01:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21