[Solved] Need help with c++/sdl and drawing
Moderator: Coders of Rage
Re: Need help with c++/sdl and drawing
can you post the link when you've uploaded
- civicdude95
- Chaos Rift Newbie
- Posts: 26
- Joined: Mon Feb 21, 2011 9:55 am
- Current Project: Prospectus
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++, C#, Java
- Contact:
Re: Need help with c++/sdl and drawing
Sure I'm putting in my Google docs account.
Here is the link for the zip
https://docs.google.com/leaf?id=0B-7lPg ... y=CMSKkpQF
Here is the link for the zip
https://docs.google.com/leaf?id=0B-7lPg ... y=CMSKkpQF
Re: Need help with c++/sdl and drawing
I am not quite sure why this is happening because the top that goes missing is blue not pink, but removing the colour key that you set in your image load function lets the program pritn out the top of the screen as it should
- civicdude95
- Chaos Rift Newbie
- Posts: 26
- Joined: Mon Feb 21, 2011 9:55 am
- Current Project: Prospectus
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++, C#, Java
- Contact:
Re: Need help with c++/sdl and drawing
Wow, that's weird. What in the world would cause that to happen? Is there another way to set the transparency color that would make it work properly? I have not ever seen this problem before
*EDIT*
Ok, so I modified my LoadImage() method to be like the following:
This may be a hack-ish way to solve the problem but it works for this game at least.
*EDIT*
Ok, so I modified my LoadImage() method to be like the following:
Code: Select all
SDL_Surface* Game::LoadImage(const char *filename, bool hasTrans)
{
SDL_Surface *image = IMG_Load(filename);
if (image == NULL)
{
std::cerr << "IMG_Load() Failed: " << SDL_GetError() << std::endl;
exit(1);
}
if (hasTrans)
{
Uint32 colorkey = SDL_MapRGB(image->format, 0xFF, 0, 0xFF);
SDL_SetColorKey(image, SDL_SRCCOLORKEY, colorkey);
}
return image;
}
Re: Need help with c++/sdl and drawing
Well, you are using PNG's so just go into gimp(free) or photoshop(not free) and add an alpha channel. Alpha channels are transparent, so you can draw over them and it will be seen, but if you don't wnat to draw over a bit it will be invisible.
http://www.sdltutorials.com/sdl-image/
This tutorial shows what code you need to do to get it to work, its easier than other ways of doing it
http://www.sdltutorials.com/sdl-image/
This tutorial shows what code you need to do to get it to work, its easier than other ways of doing it
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
Re: Need help with c++/sdl and drawing
I don't use alpha in my engine, I just color mask (255,0,255), however, you have to make sure that it is exactly that color. Also, look up LazyFoo's tutorial on optimizing loaded images.
That's how I do it in my engine.
It's roughly the same as how lazyfoo does it.
Code: Select all
void CResourceManager::LoadImage( std::string filename )
{
//Surface for loading image
SDL_Surface* load_image = NULL;
//Second surface for optimizing
SDL_Surface* optim_image = NULL;
//Load the image ( requires SDL_image)
load_image = IMG_Load( filename.c_str() );
//If the image loaded
if( load_image != NULL )
{
//Create an optimized image
optim_image = SDL_DisplayFormat( load_image );
//Free the old image
SDL_FreeSurface( load_image );
}
Uint32 colorkey = SDL_MapRGB( optim_image->format, 255, 0, 255 );
SDL_SetColorKey( optim_Image, SDL_SRCCOLORKEY, colorkey );
//HERE YOU COULD RETURN THE IMAGE, BUT I ADD IT TO AN ARRAY
image[image_count] = optim_image;
cout << "Loaded Image: " << filename << " with image number " << image_count << ".\n";
image_count++;
cout << SDL_GetError();
}
It's roughly the same as how lazyfoo does it.
Re: Need help with c++/sdl and drawing
That looks nice
The reason why I was telling him to use alpha was that even though the bit that he wanted to show was blue and the colour key was pink, it still didn't show the blue... that kinda stumped me. Alpha would fix that short term, but do you know of this error/glitch happening before? because I haven't and it confused me ... :/
The reason why I was telling him to use alpha was that even though the bit that he wanted to show was blue and the colour key was pink, it still didn't show the blue... that kinda stumped me. Alpha would fix that short term, but do you know of this error/glitch happening before? because I haven't and it confused me ... :/
- civicdude95
- Chaos Rift Newbie
- Posts: 26
- Joined: Mon Feb 21, 2011 9:55 am
- Current Project: Prospectus
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++, C#, Java
- Contact:
Re: Need help with c++/sdl and drawing
Hey guys thanks for helping me out with this problem. I'm glad we were finally able to figure it out.
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
Re: Need help with c++/sdl and drawing
I really have no clue why it wouldn't output blue, i'm assuming it was an error loading the image or something, but he say's it's solved so I guess he's good to go. Change the topic to [Solved] man!
Re: [Solved] Need help with c++/sdl and drawing
took a while, but hooray
- civicdude95
- Chaos Rift Newbie
- Posts: 26
- Joined: Mon Feb 21, 2011 9:55 am
- Current Project: Prospectus
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++, C#, Java
- Contact:
Re: [Solved] Need help with c++/sdl and drawing
Now to continue with the separation of the code. I believe I'm going to end up with a handful of classes: Game, Entity -> Player/Pill, InputHandler, Timer are the main ones that I have thought about implementing. I can't think of any more at the moment.