Re: Question about libwiisprite transparency August 08, 2008 08:21PM | Admin Registered: 16 years ago Posts: 5,132 |
void DrawableImage::SetAlpha(u32 i, u8 a){ _pixels[i+3] = a;//This is the problem line }
Re: Question about libwiisprite transparency August 09, 2008 08:51AM | Registered: 16 years ago Posts: 109 |
Re: Question about libwiisprite transparency August 09, 2008 05:09PM | Admin Registered: 16 years ago Posts: 5,132 |
#ifndef LIBWIISPRITE_DRAWABLEIMAGE #define LIBWIISPRITE_DRAWABLEIMAGE #includenamespace wsp{ //The namespace used in libwiisprite class DrawableImage : public Image{ public: DrawableImage(); //Constructor virtual ~DrawableImage(); //Destructor u8 GetRed(u32 i);//Retrieve the red value of a designated pixel on the DrawableImage u8 GetGreen(u32 i);//Retrieve the blue value of a designated pixel on the DrawableImage u8 GetBlue(u32 i);//Retrieve the green value of a designated pixel on the DrawableImage u8 GetAlpha(u32 i);//Retrieve the alpha value of a designated pixel on the DrawableImage void SetRed(u32 i, u8 r);//Sets the red value of a designated pixel on the DrawableImage void SetGreen(u32 i, u8 g);//Sets the blue value of a designated pixel on the DrawableImage void SetBlue(u32 i, u8 b);//Sets the green value of a designated pixel on the DrawableImage void SetAlpha(u32 i, u8 a);//Sets the alpha value of a designated pixel on the DrawableImage bool CheckPixel(u32 i, u8 r, u8 g, u8 b, u8 a);/*Compares the designated pixel on the DrawableImage with the values given to call the function*/ void SetPixel(u32 i, u8 r, u8 g, u8 b, u8 a);//Sets the color values of the designated pixel on the DrawableImage void MakeTransparent(u8 r, u8 g, u8 b, u8 a);//Makes all pixels that match those values in the DrawableImage transparent private: u8* _pixels; u32 _width, _height; bool _initialized; GXTexObj _texObj; }; }; #endif
#include#include "drawableimage.h" #include #include #include namespace wsp{ //Libwiisprite namespace DrawableImage::DrawableImage() : _pixels(NULL), _width(0), _height(0), _initialized(false){ } DrawableImage::~DrawableImage(){ DestroyImage(); } u8 DrawableImage::GetRed(u32 i){ u8 Red; Red = _pixels; return Red; } u8 DrawableImage::GetGreen(u32 i){ u8 Green; Green = _pixels[i+1]; return Green; } u8 DrawableImage::GetBlue(u32 i){ u8 Blue; Blue = _pixels[i+2]; return Blue; } u8 DrawableImage::GetAlpha(u32 i){ u8 Alpha; Alpha = _pixels[i+3]; return Alpha; } void DrawableImage::SetRed(u32 i, u8 r){ //_pixels = r; Crash Line } void DrawableImage::SetGreen(u32 i, u8 g){ //_pixels[i+1] = g; Crash Line } void DrawableImage::SetBlue(u32 i, u8 b){ //_pixels[i+2] = b; Crash Line } void DrawableImage::SetAlpha(u32 i, u8 a){ //_pixels[i+3] = a; Crash Line } bool DrawableImage::CheckPixel(u32 i, u8 r, u8 g, u8 b, u8 a){ if(GetRed(i) == r && GetGreen(i) == g && GetBlue(i) == b && GetAlpha(i) == a) return true; else return false; } void DrawableImage::SetPixel(u32 i, u8 r, u8 g, u8 b, u8 a){ SetRed(i, r); SetGreen(i, g); SetBlue(i, b); SetAlpha(i, a); } void DrawableImage::MakeTransparent(u8 r, u8 g, u8 b, u8 a){ u32 height = GetHeight(); u32 width = GetWidth(); u32 total = width*height; _InitializeImage(width, height); for(u32 i = 0; i <= total; i++){ if(CheckPixel(i, r, g, b, a)) SetPixel(i, r, g, b, 0); } } }
#include#include #include #include #include #include // The main libwiisprite header. using namespace wsp; // To not make us type this again and again #include "drawableimage.h" // libwiisprite uses wsp as it's namespace using namespace wsp; int main(int argc, char **argv) { int x = 320; int y = 240; int speed = 8; fatInitDefault(); // Create the game window and initalise the VIDEO subsystem GameWindow gwd; gwd.InitVideo(); // Initialise Wiimote WPAD_Init(); Image *image1 = new Image(); image1->LoadImage("data/background.png"); DrawableImage *image2 = new DrawableImage(); image2->LoadImage("data/pointer.png"); image2->MakeTransparent(255, 0, 255, 0xFF); Sprite *background = new Sprite(); background->SetImage(image1); background->Draw(); Sprite *bat = new Sprite(); bat->SetImage(image2, 48, 48); for(;;) { WPAD_ScanPads(); background->Draw(); bat->SetPosition(x, y); bat->Draw(); bat->NextFrame(); if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_UP) x -= speed; if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_DOWN) x += speed; if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_RIGHT) y -= speed; if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_LEFT) y += speed; if((WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_UP) && (WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_RIGHT)){ x -= speed/2; y -= speed/2; } if((WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_UP) && (WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_LEFT)){ x -= speed/2; y += speed/2; } if((WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_DOWN) && (WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_RIGHT)){ x += speed/2; y -= speed/2; } if((WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_DOWN) && (WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_LEFT)){ x += speed/2; y += speed/2; } if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_HOME) break; if(y < 0) y = 0; if(y > 480) y = 480; if(x < 0) x = 0; if(x > 640) x = 640; gwd.Flush(); } return 0; }
Re: Question about libwiisprite transparency August 10, 2008 12:32PM | Registered: 16 years ago Posts: 109 |
bool DrawableImage::CheckPixel(u32 i, u8 r, u8 g, u8 b){ if(GetRed(i) == r && GetGreen(i) == g && GetBlue(i) == b) return true; else return false; } void DrawableImage::SetPixel(u32 i, u8 r, u8 g, u8 b, u8 a){ SetRed(i, r); SetGreen(i, g); SetBlue(i, b); SetAlpha(i, a); } void DrawableImage::MakeTransparent(u8 r, u8 g, u8 b){ u32 height = GetHeight(); u32 width = GetWidth(); u32 total = width*height; _InitializeImage(width, height); for(u32 i = 0; i <= total; i++){ if(CheckPixel(i, r, g, b)) SetPixel(i, r, g, b, 0); } }
Re: Question about libwiisprite transparency August 10, 2008 06:08PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Question about libwiisprite transparency August 10, 2008 08:11PM | Registered: 16 years ago Posts: 265 |
struct GX_block1_pixel { u8 A,R; }; struct GX_block2_pixel { u8 G,B }; struct GX_block { GX_block1_pixel block1[4*4]; GX_block2_pixel block2[4*4]; }; GX_block *_pixels;
Re: Question about libwiisprite transparency August 10, 2008 10:26PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Question about libwiisprite transparency August 11, 2008 08:47AM | Registered: 16 years ago Posts: 109 |
Re: Question about libwiisprite transparency August 11, 2008 03:11PM | Registered: 16 years ago Posts: 265 |
Re: Question about libwiisprite transparency August 11, 2008 03:32PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Question about libwiisprite transparency August 11, 2008 04:25PM | Registered: 16 years ago Posts: 265 |
Re: Question about libwiisprite transparency August 11, 2008 06:56PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Question about libwiisprite transparency August 11, 2008 07:44PM | Registered: 16 years ago Posts: 109 |
Re: Question about libwiisprite transparency August 12, 2008 02:24AM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Question about libwiisprite transparency August 12, 2008 11:35PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Question about libwiisprite transparency August 13, 2008 04:09PM | Registered: 16 years ago Posts: 109 |
Re: Question about libwiisprite transparency August 13, 2008 07:44PM | Admin Registered: 16 years ago Posts: 5,132 |
_pixels[0+3] = 0;So since raw numbers don't work, I'm out of ideas.
Re: Question about libwiisprite transparency August 14, 2008 03:01AM | Registered: 16 years ago Posts: 211 |
Re: Question about libwiisprite transparency August 14, 2008 05:02AM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Question about libwiisprite transparency August 14, 2008 05:17AM | Registered: 16 years ago Posts: 211 |