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

{SDL}Displaying multiple images at once

Started by MPG Apr 11, 2004 at 8:18 PM 13 replies 3.4k views
Original Post
MPG
MPG
I dos'nt show any of the pics
#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( 800,600, 24, SDL_ANYFORMAT|SDL_DOUBLEBUF );  
  SDL_Surface * tdisplay = SDL_SetVideoMode( 800,600, 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 Event              
	 ;SDL_Rect coord;
			 coord.x = 100;
			 coord.y = 100;
			 SDL_Surface * tdisplay;
  while(true);
  {
SDL_BlitSurface(img,NULL,screen, &dest);  
  SDL_Flip( screen );// wait for user exit

  }
  while( !( SDL_PollEvent(&event) && event.type == SDL_QUIT ) )  {}   
SDL_PollEvent(&Event);
if(Event.type == SDL_MOUSEBUTTONDOWN)
{      
	if(Event.button.button == SDL_BUTTON_LEFT)   
         {
			 SDL_Surface *imi =SDL_LoadBMP("ad.bmp")
                         SDL_Flip(tdisplay);          
 ;while(true);
			 {
				 SDL_BlitSurface(imi,NULL,tdisplay,&coord)
				;SDL_Flip(screen);
			 }
		 }
}
		 
        return 0;
  }

CODE UPDATE CODE UPDATE2 [edited by - MPG on April 17, 2004 11:31:19 AM] [edited by - MPG on April 17, 2004 11:15:39 PM]
Tiffany_Smith
Tiffany_Smith
I cleaned it up for you a little bit, but you have what seems like some really unnecessary code in there.

A more detailed description of what you want might help a little too.




#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( 800,600, 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_Rect coord;
coord.x = 100;
coord.y = 100;
SDL_Surface * tdi
splay;

while(true)
{
SDL_BlitSurface(img,NULL,screen, &dest);
SDL_Flip( screen );

SDL_PollEvent(&event);
if(event.type == SDL_MOUSEBUTTONDOWN)
{
if(event.button.button == SDL_BUTTON_LEFT)
{

// this code doesn''t really accompilish much

// and you should free the surface as well

SDL_Surface *imi =SDL_LoadBMP("ad.bmp");
SDL_BlitSurface(imi,NULL,tdisplay,&coord);
SDL_Flip(screen);
}
}
else if(event.type == SDL_QUIT)
return 0;
}

return -1;
}
leiavoia
leiavoia
i''ll try to do it even a little better. Flip() should come at the very end IMHO. The imi image should be pre-loaded first, then blitted when the button is pressed. You should only Flip() once in the loop as well.

Please excuse my exotic code indentation


#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( 800,600, 24, SDL_ANYFORMAT|SDL_DOUBLEBUF );
SDL_Surface * img = SDL_LoadBMP( "filename.bmp" );
SDL_Surface *imi =SDL_LoadBMP("ad.bmp"); // NEW

SDL_Rect dest;
dest.x = 200;
dest.y = 300;
SDL_Event event;
SDL_Rect coord;
coord.x = 100;
coord.y = 100;
SDL_Surface * tdisplay;

while(true) {
SDL_BlitSurface(img,NULL,screen, &dest);

SDL_PollEvent(&event);
if(event.type == SDL_MOUSEBUTTONDOWN) {
if(event.button.button == SDL_BUTTON_LEFT) {
SDL_BlitSurface(imi,NULL,tdisplay,&coord);
}
}
else if(event.type == SDL_QUIT) { return 0; }

SDL_Flip( screen );
}

return 0;
}
[source]
MPG
MPG
how do i set the width,hight,ect
Zahlman
Zahlman

#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( 800,600, 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 Event
;SDL_Rect coord;
coord.x = 100;
coord.y = 100;
SDL_Surface * tdisplay;
while(true);


Your code enters tight infinite loop here and doesn''t get to any of the actual function calls. This is not the first time you''ve had this problem IIRC. Don''t put the blasted semicolon here if you actually want to *do* something in your while loop. This form is only useful if the while condition does something useful. "true" does not do anything useful on its own.

Your indentation is rather strange too. It won''t harm anything but it makes it harder for others (and yourself) to figure out what''s going on.

{
SDL_BlitSurface(img,NULL,screen, &dest);
SDL_Flip( screen );// wait for user exit

}


Even after fixing that, you won''t get past this point.


while( !( SDL_PollEvent(&event) && event.type == SDL_QUIT ) ) {}


This is probably what you want as your condition for the previous while loop, or something along those lines.


SDL_PollEvent(&Event);


This re-polls for no good reason, the event you want to look at is already in ''event''. Having two variables whose names differ only in capitalization is bad idea, too. You *will* get them mixed up eventually even if you do need them both, which you don''t seem to here.


if(Event.type == SDL_MOUSEBUTTONDOWN)
{
if(Event.button.button == SDL_BUTTON_LEFT)
{
SDL_Surface *imi =SDL_LoadBMP("ad.bmp")

;while(true);


Another one of these extra semicolons. You don''t want to enter a separate tight loop once you receive a click. I get the general impression that you really don''t have any good concept of how the whole "control flow" thing is supposed to work.


{
SDL_BlitSurface(imi,NULL,tdisplay,&coord)
;SDL_Flip(screen);
}
}
}

return 0;
}


You didn''t initialize ''tdisplay'' to anything, so it''s not pointing at any particular SDL_Surface.
MPG
MPG
The reason why I put the semicolon the is because it gives me "missing ; BEFORE whatever." I need to set the w,h,ect for tdisplay because when i cliked it gave me a run-time error
Spudder
Spudder
If you get an error abour "missing ; before XXX" then look at the line of code (not braces etc) directly above it and add in the semi-colon.

EDIT: calling Flip() changes the surface to which you are drawing to so only call this after you have drawn all the images you need .

[edited by - Spudder on April 13, 2004 7:17:09 PM]
MPG
MPG
Run-Time Check Failure #3 - The variable ''tdisplay'' is being used without being defined.
Onemind
Onemind
Replace tdisplay with screen. Since you're having some problems, you may want to rewrite the code to use a single buffer.


#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( 800,600, 24, SDL_ANYFORMAT );
SDL_Surface * img = SDL_LoadBitmap("filename.bmp");

SDL_Rect coords;
coords.x = 0;
coords.y = 0;

while(!( SDL_PollEvent(&event) && event.type == SDL_QUIT))
{
SDL_BlitSurface(img,NULL,screen,&coords);
}
}



[edited by - Onemind on April 17, 2004 1:30:50 PM]
MPG
MPG
Is ther somting wrong with the coordinants
monkey_32606
monkey_32606
Cords count in from the top left I think
Quote: Michael TanczosCut that shit out. You shouldn't be spying on other people.. especially your parents. If your dad wanted to look at horses having sex with transexual eskimo midgets, that's his business and not yours.
MPG
MPG
filename shows up but ad dosn''t.
MPG
MPG
Can anyone help?
twix
twix
I''m thinking maybe you should try starting out with a simpler language? I seem to recall that you''ve been trying this for a long time now, but you''re still not grasping the basic concepts of C++. You''re just copying and pasting code without understanding how it works at all.

You might consider starting with one of those game-related flavors of Basic.
MPG
MPG
hehe, i didnt put .bmp at the end, sorry.

Topic Locked

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

Sign in to reply to this topic.