Crazy SDL prog.

This is a discussion on Crazy SDL prog. within the C++ Programming forums, part of the General Programming Boards category; Ok here is the code: Code: #include "stdlib.h" #include "SDL/SDL.h" int main(int argc, char *argv[]) { SDL_Surface *screen; //This pointer ...

  1. #1
    IM!
    IM! is offline
    Freak! IM!'s Avatar
    Join Date
    Dec 2004
    Location
    Zagreb, Croatia
    Posts
    30

    Crazy SDL prog.

    Ok here is the code:

    Code:
    #include "stdlib.h"
    #include "SDL/SDL.h"
    
    int main(int argc, char *argv[])
    {
    	SDL_Surface *screen;	//This pointer will reference the backbuffer
    	SDL_Surface *image;	//This pointer will reference our bitmap sprite
    	SDL_Surface *temp;	//This pointer will temporarily reference our bitmap sprite
    	SDL_Rect src, dest;	//These rectangles will describe the source and destination regions of our blit
    	
    	//We must first initialize the SDL video component, and check for success
    	if (SDL_Init(SDL_INIT_VIDEO) != 0) {
    		printf("Unable to initialize SDL: %s\n", SDL_GetError());
    		return 1;
    	}
    	
    	//When this program exits, SDL_Quit must be called
    	atexit(SDL_Quit);
    	
    	//Set the video mode to fullscreen 1024x768 with 16bit colour and double-buffering
    	screen = SDL_SetVideoMode(1024, 768, 16, SDL_DOUBLEBUF | SDL_FULLSCREEN);
    	if (screen == NULL) {
    		printf("Unable to set video mode: %s\n", SDL_GetError());
    		return 1;
    	}
    	
    	//Load the bitmap into a temporary surface, and check for success
    	temp = SDL_LoadBMP("screen.bmp");
    	if (temp == NULL) {
    		printf("Unable to load bitmap: %s\n", SDL_GetError());
    		return 1;
    	}
    	
    	//Convert the surface to the appropriate display format
    	image = SDL_DisplayFormat(temp);
    	
    	//Release the temporary surface
    	SDL_FreeSurface(temp);
    	
    	//Construct the source rectangle for our blit
    	src.x = 0;
    	src.y = 0;
    	src.w = image->w;	//Use image->w to display the entire width of the image
    	src.h = image->h;	//Use image->h to display the entire height of the image
    	
    	//Construct the destination rectangle for our blit
    	dest.x = 0;		//Display the image at the (X,Y) coordinates (100,100)
    	dest.y = 0;
    	dest.w = image->w;	//Ensure the destination is large enough for the image's entire width/height
    	dest.h = image->h;
    	
    	//Blit the image to the backbuffer
    	SDL_BlitSurface(image, &src, screen, &dest);
    	
    	//Flip the backbuffer to the primary
    	SDL_Flip(screen);
        
        SDL_Delay(10000);
     	
       //Release the surface
    	SDL_FreeSurface(image);
    
        return 0;
    }
    The prog. is displaying a image on the whole screen, well how could I pause it without using SDL_Delay, the best would be if it would just run until I press Esc or P? Any ideas?
    Last edited by IM!; 04-17-2005 at 06:09 AM.
    Check out my Linux/C++ Programming DC++ HUB!
    5 GB min.// 2 slots// 1 GB must be Linux/C++

    HackLinux++

    Cya there!

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,676
    >> if it would just run until I press Esc or P?
    http://sdldoc.csn.ul.ie/guideinputkeyboard.php

    gg

  3. #3
    IM!
    IM! is offline
    Freak! IM!'s Avatar
    Join Date
    Dec 2004
    Location
    Zagreb, Croatia
    Posts
    30
    THX problem solved...;-)
    Check out my Linux/C++ Programming DC++ HUB!
    5 GB min.// 2 slots// 1 GB must be Linux/C++

    HackLinux++

    Cya there!

  4. #4
    IM!
    IM! is offline
    Freak! IM!'s Avatar
    Join Date
    Dec 2004
    Location
    Zagreb, Croatia
    Posts
    30
    Allright the prog. is ready now, so If I want to give it to a friend, what do I have to include the .exe file, the .bmp file with the image and do I have to include the SDL.dll or something?
    Check out my Linux/C++ Programming DC++ HUB!
    5 GB min.// 2 slots// 1 GB must be Linux/C++

    HackLinux++

    Cya there!

  5. #5
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    Quote Originally Posted by IM!
    Allright the prog. is ready now, so If I want to give it to a friend, what do I have to include the .exe file, the .bmp file with the image and do I have to include the SDL.dll or something?
    Yes.
    To code is divine

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems compiling this SDL app
    By Rider in forum C++ Programming
    Replies: 3
    Last Post: 03-27-2007, 12:22 PM
  2. need help making a dot bounce up and down y axis in this prog
    By redwing26 in forum Game Programming
    Replies: 10
    Last Post: 08-05-2006, 12:48 PM
  3. SDL and MinGW Studio
    By Vicious in forum Tech Board
    Replies: 0
    Last Post: 07-30-2004, 09:59 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. sdl in c++
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-07-2002, 07:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21