Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL help

Started by ChiefArmstrong Jan 29, 2006 at 10:45 PM 3 replies 800+ views
Original Post
ChiefArmstrong
ChiefArmstrong
I have no idea why this won't compile, I keep getting an error around line 20. My libraries are set up correctly, and I'm using Dev-C++ beta 5. Here's the code:

#include <cstdlib>                                                  // for the atexit() function
#include "SDL\SDL.h"                                                // SDL header

// define our screen size constants if not going to use fullscreen
#define SCREEN_WIDTH 800;
#define SCREEN_HEIGHT 640;

int main(int argc, char **argv)
{
    // init SDL
    if(SDL_Init(SDL_INIT_VIDEO)<0)
    {
         printf("Unable to init SDL: %s\n", SDL_GetError());
         return 1;
    }
    
    atexit(SDL_Quit);
    
    // set up the video mode
    SDL_Surface *screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);
    if (screen == NULL)
    {
       printf("Unable to set video mode: %s\n", SDL_GetError());
       return 1;
    }
    
    // set up the window caption
    SDL_WM_SetCaption("SDL Framework", NULL);
    
    SDL_Event event;
    bool gameRunning = true;
    
    while (gameRunning)
    {
          if (SDL_PollEvent(&event))
          {
              switch (event.type)
              {
                  case SDL_QUIT:
                       gameRunning = false;
                       break;
                  
                  case SDL_KEYDOWN:
                  {
                       switch (event.key.keysym.sym)
                       {
                              case SDLK_ESCAPE:
                                   gameRunning = false;
                                   break;
                              default: break;
                       }
                  default: break;     
              }
          }    
    
    return 0;
}                           


And here are the errors I keep getting: C:\Dev-Cpp\SDL_framwork\main.cpp In function int SDL_main(int, char**)': 20 C:\Dev-Cpp\SDL_framwork\main.cpp expected )' before ';' token 20 C:\Dev-Cpp\SDL_framwork\main.cpp expected primary-expression before ',' token 20 C:\Dev-Cpp\SDL_framwork\main.cpp expected primary-expression before ',' token 20 C:\Dev-Cpp\SDL_framwork\main.cpp expected ;' before ')' token 59 C:\Dev-Cpp\SDL_framwork\main.cpp expected }' at end of input 59 C:\Dev-Cpp\SDL_framwork\main.cpp expected `}' at end of input C:\Dev-Cpp\SDL_framwork\Makefile.win [Build Error] [main.o] Error 1 I've been staring at this so long trying to figure out what's wrong that my eyes are getting crossed and blurry! Any help would be appreciated
BradDaBug
BradDaBug
You're missing a couple close brackets.
I like the DARK layout!
darookie
darookie
The only error I can spot is #include "SDL\SDL.h" should either read
#include "SDL\\SDL.h" or to avoid future confusion #include "SDL/SDL.h".
Note that the backslash is an escape character, e.g. to actually represent a backslash within a C-string, you'd have to use \\, since otherwise the preprocessor/parser assumed the character following the \ denotes an escape character like \n (newline) or \r (carriage return) or \t (tab).

HTH,
Pat
MatrixCubed
MatrixCubed
One glaring problem I see:
#define SCREEN_WIDTH 800;
#define SCREEN_HEIGHT 640;


Is 800x640 a fullscreen resolution your video card supports?
ChiefArmstrong
ChiefArmstrong
Thanks for the help, I found the missing close braces towards the end of main() (probably need to do this in Visual Studio since they put up those nice bracket reminders).

And the monitor resolution was incorrect, but another thing that was preventing it was that there are not supposed to be and ';'s after a #define statement, and I had it at the end of both.

Corrected it, working now.

Thanks again!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.