Sign in to follow this  

How do you make a resource file?

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

I have the book sams: Teach your self game programming in 24 hours and it is great so far but I don't understand how to make an .rc file with devC and its bothering me because I won't be able to load sprites from files I have created. So if anyone can tell me step by step how to make one and implement it in code (wether I should use headers, functions, classes, etc.) I would be very grateful. [Edited by - forestlaw89 on January 25, 2006 9:59:25 PM]

Share this post


Link to post
Share on other sites
To be perfectly honest, I don't remember Dev-CPP shipping with a Windows Resource File Editor (.rc). It's probably a bad idea to store all of your resources inside of your own compiled program, so you might want to look at other tutorials for reading from resources outside of your program.

Sorry I can't be any more help than that right now. I'll have to get on a Windows box to tell you if/how to use the resource editor with your IDE.

Share this post


Link to post
Share on other sites
Go here if you're having problems when you start using the Win32 API. It has a section on how and why to use resource files, and should answer your questions. If not, post again. By the way, that site is great for learning the rest of the basis of that API.

If you are just trying to get some images on the screen and aren't too interested in the GUI, try SDL, which is a thousand times easier to use - try ten lines instead of fifty to make a basic program with graphics. It's a bit bare-bones, but I have thoroughly enjoyed using it. Just a tip!

Here's some sample code for how you would display a bitmap image in SDL:


#include <SDL/sdl.h>

SDL_Surface * screen = NULL;

/*This will store the image you're loading, and will be loaded in main().*/
SDL_Surface * image = NULL;

void Render();

int main(int argc, char * argv[])
{
bool quit = false;

if (SDL_Init(SDL_INIT_VIDEO) < 0)
return 1;

screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF);

/*Load the bitmap*/
image = SDL_LoadBMP("picture.bmp");

if (screen == NULL)
return 1;

while (!quit)
{
SDL_Event event;

while (PollEvent(&event))
{
if (event.type == SDL_QUIT)
quit = true;
}

Render();
}

/*Free the allocated memory in the image*/
SDL_FreeSurface(image);

SDL_Quit();
}

void Render()
{
//Calculate the coordinates of the center of the screen.
int screen_center_x = screen->w / 2;
int screen_center_y = screen->h / 2;

SDL_Rect location = {screen_center_x, screen_center_y};

/*Displays the image with its top-left corner in the center of the screen.*/
SDL_BlitSurface(image, NULL, screen, &location);
SDL_Flip(screen);
}



Maybe that will entice you :)

Share this post


Link to post
Share on other sites
OK I got the prgram built but I keep getting an error stating I don't have that existing file in that directory. I know I should check and I have. But what is weird is i only get the error for one of the icons and not both. By the way i am using DevC++. Can someone tell me the reason why I am getting this error or should I use more than one resource file?

Share this post


Link to post
Share on other sites

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