Public Group

Archived

This topic is now archived and is closed to further replies.

Whats wrong with this sdl code???

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

Recommended Posts

Code: /* -- Include the precompiled libraries -- */ #ifdef WIN32 #pragma comment(lib, "SDL.lib") #pragma comment(lib, "SDLmain.lib") #endif #include "SDL.h" int main( int argc, char* argv[] ) { SDL_Init( SDL_INIT_VIDEO ); atexit( SDL_Quit ); SDL_Surface * screen = SDL_SetVideoMode( 640, 480, 24, SDL_ANYFORMAT|SDL_DOUBLEBUF ); SDL_Surface * img = SDL_LoadBMP( "filename.bmp" ); SDL_Rect dest; dest.x = 200; dest.y = 300; SDL_Event event; SDL_Event a; SDL_Event b ;SDL_Event c ;SDL_Event d; SDL_Event e; SDL_Event z ;while(true) { SDL_BlitSurface(img,NULL,screen, &dest); SDL_Flip( screen ); // wait for user exit while( !( SDL_PollEvent(&event) && event.type == SDL_QUIT ) ) {} } if(SDL_MouseButtonEvent(SDL_BUTTON_LEFT,SDL_PRESSED,200300) { SDL_FreeSurface(screen) ;} return 0; } ERROR: c:\Documents and Settings\Randle\Desktop\randyx''s stuff\PROJECTS\SDL\opp2604957sdl.cpp(29) : error C2661: ''SDL_MouseButtonEvent::SDL_MouseButtonEvent'' : no overloaded function takes 3 arguments c:\Documents and Settings\Randle\Desktop\randyx''s stuff\PROJECTS\SDL\opp2604957sdl.cpp(29) : error C2143: syntax error : missing '')'' before ''{''

Share on other sites
if(SDL_MouseButtonEvent(SDL_BUTTON_LEFT,SDL_PRESSED,200300)

should be

if(SDL_MouseButtonEvent(SDL_MOUSEBUTTONDOWN,SDL_BUTTON_LEFT,SDL_PRESSED,200,300))
or
if(SDL_MouseButtonEvent(SDL_MOUSEBUTTONUP,SDL_BUTTON_LEFT,SDL_PRESSED,200,300))

In all fairness though the errors pretty much told you exactly what to fix.

Share on other sites
why are you making 7 SDL_Event structors one after the other? i really absolutely no need for that

Share on other sites
First, don''t free a surface that you got from SDL_SetVideoMode. It will automatically be freed by SDL_Quit. DO free the surface you got from SDL_LoadBMP.

As for the error you''re getting: SDL_MouseButtonEvent is a struct. Your code isn''t going to do what (I assume) you want to do.

Actually, I was just reading your code, and I''m really not sure WHAT you''re trying to do. Blit the surface to the screen once, then exit if the user clicks the mouse button or if the SDL_QUIT event is received?

Share on other sites
First of all your code looks like crap. No offence but if you want anyone to look at your code at least make it look pleasant.

SDL_Event a;SDL_Event b;SDL_Event c       // dude the semi colon goes at the end

if you get into bad coding habits you are going to stick with them for a long time. try some tabs here and there. sorry about the nagging but its for your own good.

As for the problem with SDL what stro said should fix it.

Share on other sites
quote:
Original post by QzarBaron
First of all your code looks like crap. No offence but if you want anyone to look at your code at least make it look pleasant.

Yea, but I think it was more due to formatting errors from the sloppy copy/paste job. MPG make sure you either use the "{code}{/code}" tags to properly format short bits of code, or the "{source}{/source}" tags to properly format (and color) longer code snippets (since the source tags create code a scrollable box and thus take up less space).

Be sure to replace the {} brackets with [] - I had to use {} so the forums wouldn't do any formatting

_________________________________________________________________

Drew Sikora
Staff Writer, Newsletter Editor - GameDev.net
Community Relations - Game Institute

Share on other sites
Stro: It still dosnnt work
QuazarBron: It only takes it like that

Share on other sites
I''m gonna have to agree with TylerK here. What in the worlds are you trying to do? Anyways looking over that code makes me somewhat nauseous - do you have a better-formatted example and what are the new errors?

_________________________________________________________________

Drew Sikora
Staff Writer, Newsletter Editor - GameDev.net
Community Relations - Game Institute

Share on other sites
/* -- Include the precompiled libraries -- */#ifdef WIN32#pragma comment(lib, "SDL.lib")#pragma comment(lib, "SDLmain.lib")#endif#include "SDL.h"int main( int argc, char* argv[] ){  SDL_Init( SDL_INIT_VIDEO );    atexit( SDL_Quit );    SDL_Surface * screen = SDL_SetVideoMode( 640, 480, 24, SDL_ANYFORMAT|SDL_DOUBLEBUF );    SDL_Surface * img = SDL_LoadBMP( "filename.bmp" );     SDL_Rect dest;    dest.x = 200;    dest.y = 300;    SDL_Event event;  SDL_Event a;  SDL_Event b;    while(true);  {SDL_BlitSurface(img,NULL,screen, &dest);    SDL_Flip( screen );   // wait for user exit    while( !( SDL_PollEvent(&event) && event.type == SDL_QUIT ) )  {}        }  if(SDL_MouseButtonEvent(SDL_MOUSEBUTTONDOWN,SDL_BUTTON_LEFT,200,300))  {	  SDL_FreeSurface(img)  ;}  return 0;  }

c:\Documents and Settings\Randle\Desktop\randyx''s stuff\PROJECTS\SDL\opp2604957sdl.cpp(27): error C2661: ''SDL_MouseButtonEvent::SDL_MouseButtonEvent'' : no overloaded function takes 4 arguments

Share on other sites
See my added comments. As you may see, we might be able to help a lot more if you were to put into plain english what you are trying to do.

quote:
Original post by MPG
  while(true); // this will compile. this will loop infinitely due to the semicolon.  {// if you removed the semicolon above, this will blit and flip every cycle. you don''t change the image, though, so it''s not necessary.  SDL_BlitSurface(img,NULL,screen, &dest);   SDL_Flip( screen );   // wait for user exit  // here you wait for the SDL_QUIT event. the syntax is kinda weird, but it should do what you want it to do, I think, if you include a break. But you should rethink this whole loop.  while( !( SDL_PollEvent(&event) && event.type == SDL_QUIT ) )  {}        }// There are no more events polled after you poll SDL_QUIT above.  At this point in the program, you are exiting no matter what. You need no if statement. Free the surface, then exit. //if(SDL_MouseButtonEvent(SDL_MOUSEBUTTONDOWN,SDL_BUTTON_LEFT,200,300))//  {    SDL_FreeSurface(img)//  ;}      return 0;}

c:\Documents and Settings\Randle\Desktop\randyx''s stuff\PROJECTS\SDL\opp2604957sdl.cpp(27): error C2661: ''SDL_MouseButtonEvent::SDL_MouseButtonEvent'' : no overloaded function takes 4 arguments

• 11
• 20
• 12
• 10
• 35
• Forum Statistics

• Total Topics
631399
• Total Posts
2999857
×