• 12
• 9
• 10
• 13
• 10

sdl problem[fixed]

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

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()
{

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 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 on other sites
I don't know where you are learning from, but I am learning from cone3d.gamedev.net
You should check their tutorials out, if you aren't already. Good stuff

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.
 Yay! Fixed. Yeah, I acually had to do that.

Share on other sites
Quote:
 Original post by supercrazy7474oh,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 on other sites
Yeah. I found out theres two ways: SDL_LoadBMP("C:\\somerootfolder\\image.bmp");
or include it in dev-cpp folder,like he said.
thanks all