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

Help with SDL_SetVideoMode

Started by Kin the Pumpkin King Jun 13, 2007 at 9:12 AM 6 replies 1.4k views
Original Post
Kin the Pumpkin King
Kin the Pumpkin King
I decided yesterday to use SDL, and I'm starting today and almost everything works out so far. Except.... I'm getting this message when I try to compile: "expected primary-expression before '=' token" That's in the SDL_SetVideoMode. My line for that is: "screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);" Where SCREEN_WIDTH = 640, SCREEN_HEIGHT = 480 and SCREEN_BPP = 32, set with #define. I'm initializing screen in the global scope with: "SDL_Surface *screen = 0;" So what's wrong? Thanks in advance for the replies. If you need all of the code, please tell me how to put it in a vertical scroll thingy that people use that I don't know how to use.
samuraicrow
samuraicrow
The scroll thingies with syntax highlighting for your source code are from the [ source="C" ] and [ /source ] tags (with the spaces taken out). Or substitute [ source="cpp" ] if you're using C++. The full instructions for all of the tags for this forum are in the forum faq.

Now for your question about SDL. Are you intitializing the video subsystem before you call SDL_SetVideoMode() ?
Kin the Pumpkin King
Kin the Pumpkin King
I think so, since I'm using SDL_INIT_EVERYTHING.

Here's my code:

[source="cpp"]#include "SDL/SDL.h"#include <string>#define SCREEN_WIDTH = 640;#define SCREEN_HEIGHT = 480;#define SCREEN_BPP = 32;using namespace std;SDL_Surface *message = 0;SDL_Surface *background = 0;SDL_Surface *screen = 0;SDL_Surface *load_image(string filename);void apply_surface(int x, int y, SDL_Surface *source, SDL_Surface *destination);int main( int argc, char* args[] ){    if(SDL_Init(SDL_INIT_EVERYTHING) == -1)        return 1;        screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);        if(screen == 0)        return 1;        SDL_WM_SetCaption("Hello World", 0);        message = load_image("hello_world.bmp");    background = load_image("background.bmp");        apply_surface(0, 0, background, screen);    apply_surface(180, 140, message, screen);        if(SDL_Flip(screen) == -1)         return 1;        SDL_Delay(2000);        SDL_FreeSurface(message);    SDL_FreeSurface(background);        SDL_Quit();        return 0;}SDL_Surface *load_image(string filename){    SDL_Surface *loadedImage = 0;    SDL_Surface *optimizedImage = 0;        loadedImage = SDL_LoadBMP(filename.c_str());        if(loadedImage != 0)    {        optimizedImage = SDL_DisplayFormat(loadedImage);        SDL_FreeSurface(loadedImage);    }        return optimizedImage;}void apply_surface(int x, int y, SDL_Surface *source, SDL_Surface *destination){    SDL_Rect offset;    offset.x = x;    offset.y = y;        SDL_BlitSurface(source, 0, destination, &offset);}
skwee
skwee
Replace

#define SCREEN_WIDTH = 640;
#define SCREEN_HEIGHT = 480;
#define SCREEN_BPP = 32;

with

#define SCREEN_WIDTH 640;
#define SCREEN_HEIGHT 480;
#define SCREEN_BPP 32;
I would love to change the world, but they won’t give me the source code.
rip-off
rip-off
Quote:
Original post by s.kwee
Replace

#define SCREEN_WIDTH = 640;
#define SCREEN_HEIGHT = 480;
#define SCREEN_BPP = 32;

with

#define SCREEN_WIDTH 640;
#define SCREEN_HEIGHT 480;
#define SCREEN_BPP 32;


Close, but not quite. [smile]

Replace with:

const int SCREEN_WIDTH = 640;const int SCREEN_HEIGHT = 480;const int SCREEN_BPP = 32;
Kin the Pumpkin King
Kin the Pumpkin King
Oh, it works! I could swear that using #define would work, but what does a newbie know?

Well, thanks for all of your help.

By the way, I tried both and '#define' without '=' works just like 'const int'. But if I run into trouble like that again, I'll definetly use 'const it'.

Thank you so much again.
rip-off
rip-off
Quote:
Original post by Kin the Pumpkin King
Oh, it works! I could swear that using #define would work, but what does a newbie know?

Well, thanks for all of your help.

By the way, I tried both and '#define' without '=' works just like 'const int'. But if I run into trouble like that again, I'll definetly use 'const it'.

Thank you so much again.


#define is basically search and replace done at compile time. In C++ it is almost completely unnecessary, replaced by const values, templates etc.

The only time I would use #define is when I want to get the values of __FILE__ and __LINE__ in a convenient manner. Other than that there isn't really a need for it.

and include guards, but that's too obvious
Jaiminho
Jaiminho
Quote:
Original post by Kin the Pumpkin King
Oh, it works! I could swear that using #define would work, but what does a newbie know?

Well, thanks for all of your help.

By the way, I tried both and '#define' without '=' works just like 'const int'. But if I run into trouble like that again, I'll definetly use 'const it'.

Thank you so much again.

If you are programming in C, stick to #define -- AFAIK, const stuff in C isn't replaced at compile time, it just adds some unvariable stuff to the stack. If C++, constant stuff is the way to go.

Topic Locked

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

Sign in to reply to this topic.