Jump to content
  • Advertisement
Sign in to follow this  
Kin the Pumpkin King

Help with SDL_SetVideoMode

This topic is 4052 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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() ?

Share this post


Link to post
Share on other sites
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);
}

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!