Sign in to follow this  

sdl problem[fixed]

This topic is 4691 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

This is my first time using images. here is my code:
#include <SDL/SDL.h>
#include <iostream>
#include <windows.h>
using namespace std;
SDL_Surface *screen,*back;
int initimages()
{
    
     back=SDL_LoadBMP("c++test.bmp");
    return 0;
     }
     int DrawIMG(SDL_Surface *img,SDL_Surface *screen, int x, int y)
{
  SDL_Rect dest;
  dest.x = x;
  dest.y = y;
  SDL_BlitSurface(img, NULL, screen, &dest);
  return 0;
}


int drawback()
{
     DrawIMG(back,screen,0,0);
     return 0;
     }
     
   int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
           atexit(SDL_Quit);
        
         if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )
  {
    printf("Unable to init SDL: %s\n", SDL_GetError());
    exit(1);
  }
  
  
  screen=SDL_SetVideoMode(640,480,0,SDL_HWSURFACE|SDL_DOUBLEBUF);
  if ( screen == NULL )
  {
    printf("Unable to set 640x480 video: %s\n", SDL_GetError());
    exit(1);
  }
  initimages();
  int done=0;
  
  while(done==0)
  { SDL_Flip(screen);
     SDL_Event event;
     drawback();
     while(SDL_PollEvent(&event))
     {  SDL_Flip(screen);
                                 drawback();
        if(event.type==SDL_QUIT)
        {
        done=1;
        }
        
        }
        }
        exit(0);
        }




I'm trying to make a .bmp file appear on the screen. What is the bug in the program? I have it included in the project file. (dev-cpp 4.9.9.1) [Edited by - supercrazy7474 on February 11, 2005 10:28:42 AM]

Share this post


Link to post
Share on other sites
I'm sure your asking why it does not compile - am I right?

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)


needs to be

int main( int argc, char* argv[])


After that you will need to link in:

-lmingw32
-lsdlmain
-lsdl


To do that, click on "Project"->"Project Options"->"Parameters" and add that into the Linker box.

If it does then compile, but the bmp does not work, in your initimages function, add in this check:

back=SDL_LoadBMP("c++test.bmp");
if( back == 0 )
exit(-1);


Now if the program does not work at all, it means that the bmp file cannot be loaded. Make sure the file is in the correct directory and is valid. Check for misspelling as well.

- Drew

Share this post


Link to post
Share on other sites
oh,duh. Yes, sence I had windows.h included, I did that so I didnt have an annoying dos window pop up too. Yeah, for some reason it doesnt work. so do you load bmps like ("C:\somefolder\images\c++test.bmp")? Cause at cone-3d they didnt need to do that.
[edit] Yay! Fixed. Yeah, I acually had to do that.

Share this post


Link to post
Share on other sites
Quote:
Original post by supercrazy7474
oh,duh. Yes, sence I had windows.h included, I did that so I didnt have an annoying dos window pop up too. Yeah, for some reason it doesnt work. so do you load bmps like ("C:\somefolder\images\c++test.bmp")? Cause at cone-3d they didnt need to do that.


Just make sure the images are in the same directory that your program is in for Dev-CPP. It should then work. If not the "c++test.bmp" file might be of the wrong format. Try using a different format, such as 16bit or 256 colors or the the like.

Share this post


Link to post
Share on other sites

This topic is 4691 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this