Re: Question about libwiisprite transparency August 15, 2008 12:21PM | Registered: 16 years ago Posts: 265 |
Re: Question about libwiisprite transparency August 15, 2008 11:47PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Question about libwiisprite transparency August 16, 2008 01:20AM | Registered: 16 years ago Posts: 265 |
Re: Question about libwiisprite transparency August 16, 2008 01:51AM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Question about libwiisprite transparency August 16, 2008 05:28AM | Registered: 16 years ago Posts: 211 |
Re: Question about libwiisprite transparency August 16, 2008 04:36PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Question about libwiisprite transparency August 19, 2008 02:03AM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Question about libwiisprite transparency August 19, 2008 02:43PM | Registered: 16 years ago Posts: 109 |
Re: Question about libwiisprite transparency August 19, 2008 04:35PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Question about libwiisprite transparency August 19, 2008 04:42PM | Registered: 16 years ago Posts: 109 |
Re: Question about libwiisprite transparency August 19, 2008 08:19PM | Admin Registered: 16 years ago Posts: 5,132 |
Quote
chaosteil
Well, there may be one additional way you can achieve what you were looking for. Try to load the image, but into your own buffer. Use the libpng functions then to change the image data and then push the buffer to the Image class. This may work or may not work so much. I guess you should just try.
Re: Question about libwiisprite transparency August 19, 2008 09:05PM | Registered: 16 years ago Posts: 109 |
Re: Question about libwiisprite transparency August 20, 2008 12:32AM | Registered: 16 years ago Posts: 211 |
Re: Question about libwiisprite transparency August 20, 2008 01:01AM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Question about libwiisprite transparency August 21, 2008 12:54AM | 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 using namespace wsp; //Libwiisprite namespace DrawableImage::DrawableImage(){ } 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; } void DrawableImage::SetGreen(u32 i, u8 g){ _pixels[i+1] = g; } void DrawableImage::SetBlue(u32 i, u8 b){ _pixels[i+2] = b; } void DrawableImage::SetAlpha(u32 i, u8 a){ _pixels[i+3] = a; } 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, 0, 0, 0, 0); } }
#include#include #include #include #include #include // The main libwiisprite header. #include "drawableimage.h" using namespace wsp; //Libwiisprites namespace int main(int argc, char **argv){ int x = 320; int y = 240; int speed = 8; fatInitDefault();//Initialize the SanDisk // Create the game window and initalise the VIDEO subsystem GameWindow gwd; gwd.InitVideo(); WPAD_Init(); //Initialize the Wiimote Image *image1 = new Image(); image1->LoadImage("data/background.png"); DrawableImage *image2 = new DrawableImage(); image2->LoadImage("data/pointer.png"); image2->MakeTransparent(0xFF, 255, 0, 255);//Check with ARGB 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_A)//Leaving this in for additional trial image2->MakeTransparent(255, 0, 255, 0xFF);//Check with RGBA 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 21, 2008 08:09AM | Registered: 16 years ago Posts: 265 |
Re: Question about libwiisprite transparency August 21, 2008 09:33AM | Registered: 16 years ago Posts: 211 |
Quote
henke37
Uhm, you are not paying attention to me are you?
The pixels are not stored like that, stop using them like this!
Re: Question about libwiisprite transparency August 21, 2008 12:09PM | Registered: 16 years ago Posts: 109 |
Re: Question about libwiisprite transparency August 21, 2008 10:07PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Question about libwiisprite transparency August 22, 2008 07:48AM | Registered: 16 years ago Posts: 265 |