Surface Class Loading a BMP
Surface Class Loading a BMP
Hello again need your help to solve a problem , so i am following a chili intermediate tutorials lesson 8 and doing a surface class , not as chili , i do it my way , and face a problem , could not load an image , once i run game its just crash and when i break it its returns me into my BMP.ccp file i have done no major changes there just pass two more parameters to a functions "unsinged int& width, unsinged int& height" and then inside a function just assign a values that was read from a file , basically i am using my whole old code from my last game (load bitmap , draw sprite and so on ) all those functions are same as it was on my last game and everything was working so i assume that there is a problem with my surface class , the framework are empty only a surface class and some functions inside graphic.h
- Attachments
-
- Chili Framework 2016.rar
- (110.84 KiB) Downloaded 155 times
-
- Posts: 197
- Joined: August 4th, 2016, 10:05 am
Re: Surface Class Loading a BMP
so i ran it in debug mode and it crashes when making the surface inside the bmpload function, i dont know how vectors work and bit unsure about pointers but i am gessing your problem is there, maybe the vector pointer need to be set to something?
EDIT if that dosent help you, you need to wait for the big boys :p
EDIT if that dosent help you, you need to wait for the big boys :p
Re: Surface Class Loading a BMP
Yea its works if i make sprite without a pointer and pass like this :freebattie wrote:so i ran it in debug mode and it crashes when making the surface inside the bmpload function, i dont know how vectors work and bit unsure about pointers but i am gessing your problem is there, maybe the vector pointer need to be set to something?
EDIT if that dosent help you, you need to wait for the big boys :p
Code: Select all
class Surface {
public:
Surface(std::string filename) {
LoadBMP(filename, sprite,width,height);
}
~Surface() {
sprite.clear();
}
void Draw(int xoff ,int yoff , int tr,int tg,int tb,Graphics &gfx) {
gfx.DrawSprite(xoff, yoff, width, height, sprite, tr, tg, tb);
}
private:
unsigned int width;
unsigned int height;
std::vector<Color> sprite;
};
-
- Posts: 197
- Joined: August 4th, 2016, 10:05 am
Re: Surface Class Loading a BMP
yeah thats a problem whit your drawfunction, yellow is 255,255,0 so you hit 1 of the checks for != 0
Re: Surface Class Loading a BMP
i dont really see a problem in a draw function :freebattie wrote:yeah thats a problem whit your drawfunction, yellow is 255,255,0 so you hit 1 of the checks for != 0
Code: Select all
void Graphics::DrawSprite(int x, int y, int width, int heigth, std::vector<Color>& image, int tr, int tg, int tb)
{
for (int a = 0; a < heigth; a++) {
for (int b = 0; b < width; b++) {
unsigned char rd = image[b + a * width].GetR();
unsigned char gr = image[b + a * width].GetG();
unsigned char bl = image[b + a * width].GetB();
if (rd != (unsigned char)tr &&
gr != (unsigned char)tg &&
bl != (unsigned char)tb) {
PutPixel(x + b, y + a,rd,gr,bl);
}
}
}
}
-
- Posts: 197
- Joined: August 4th, 2016, 10:05 am
Re: Surface Class Loading a BMP
you are saying that rd AND gr AND bl needs to NOT be 0, but when you have yellow, it is 255,255,0 so it will not draw yellow since bl will be 0 and your check will be untrue and skip, need to rethink how you check for 0,
Re: Surface Class Loading a BMP
that if tells if rd != tr(0) and gr != tg(0) and bl != tb(0) then draw
so if its yellow if would look like this
if 255 != 0 and 255 != 0 && 0 != 0
witch is false
edited:
ah okay i got this now, but still now sure about the problem i mentioned before about those pointers should it be a pointer or its good without :/
so if its yellow if would look like this
if 255 != 0 and 255 != 0 && 0 != 0
witch is false
edited:
ah okay i got this now, but still now sure about the problem i mentioned before about those pointers should it be a pointer or its good without :/
-
- Posts: 197
- Joined: August 4th, 2016, 10:05 am
Re: Surface Class Loading a BMP
ok so it needs to be !( bla == 0 && bla1 == 0 && bla2 ==0)
the way you did it you are saying if rd or gr or bl is 0, skip it, what i posted will check if all 3 is 0 and only skip if that is true
EDIT hope that makes it bit clearer how it works, if you still have some problem understanding it
the way you did it you are saying if rd or gr or bl is 0, skip it, what i posted will check if all 3 is 0 and only skip if that is true
EDIT hope that makes it bit clearer how it works, if you still have some problem understanding it
Re: Surface Class Loading a BMP
yea i did it same way was not getting this at first
Code: Select all
if (!(rd == tr && gr == tg && bl == tb)) {
PutPixel(x + b, y + a,rd,gr,bl);
}
Re: Surface Class Loading a BMP
cool that you guys solved w/o me having to jump in (was here for a while xD)
just to help you guys in the futureso yea
just to help you guys in the future
Code: Select all
if( a && b ) // all have to eval to true to pass (you know lol)
so for the yellow check
if( rd(255) != tr(0) && gr(255) != tg(255) && bl(0) != tb(0) ) // if( true && true && false ) == false
so yea, checking that all be true and then negate would be the way to go
if( not ( rd(255) == tr(0) && gr(255) == tg(0) && bl(0) == tb(0) ) )
// if( not( false && false && true ) ) -> if( not( false ) ) == true
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --