Welcome! Log In Create A New Profile

Advanced

Question about libwiisprite transparency

Posted by Arikado 
Re: Question about libwiisprite transparency
August 15, 2008 12:21PM
For the 3rd time, _pixels is not just ARGB! It is this complicated block format. pixels[3] is the R for (1,0), not the B for (0,0).



Edited 1 time(s). Last edit at 08/15/2008 12:22PM by henke37.
Re: Question about libwiisprite transparency
August 15, 2008 11:47PM
_pixels = 0; doesn't work either. I'll probably have to use GX to write a color blending function (or is that alpha blending). Too bad I don't know GX!
Re: Question about libwiisprite transparency
August 16, 2008 01:20AM
uhm, read the existing posts and learn the texture format for real, it should be a piece of cake to set the alpha channel manually.
Re: Question about libwiisprite transparency
August 16, 2008 01:51AM
You would think that but nothing's ever as easy as it seems. Lol
Re: Question about libwiisprite transparency
August 16, 2008 05:28AM
Generally setting the alpha value for an entire surface or just a pixel is very easy, just a single function call, don't know what that function is though sorry, I don't have a lot of knowledge in GX.
Re: Question about libwiisprite transparency
August 16, 2008 04:36PM
I'll ask chaosteil.
Re: Question about libwiisprite transparency
August 19, 2008 02:03AM
Alrighty, so here's the latest on the transparency; I haven't been able to program the last two days because of something that came up. I finally got around to it today. Turns out that setting all the values of a member in _pixels does not make that pixel transparent. Surprising, eh? So I played around with GX a little and couldn't find anything to do the trick. I'm working realy hard now and I hope I'll stumble onto something that will finish the job quick. I would appreciate any ideas.
Re: Question about libwiisprite transparency
August 19, 2008 02:43PM
Do the color change?
Re: Question about libwiisprite transparency
August 19, 2008 04:35PM
I can't get rid of or change a color.
Re: Question about libwiisprite transparency
August 19, 2008 04:42PM
Quote
Arikado
I can't get rid of or change a color.
? Don't get it... can't get rid of what?
Re: Question about libwiisprite transparency
August 19, 2008 08:19PM
@Dykam
Let me rewrite that: I can't seem to rid of a pixel (delete doesn't compile) or change the pixel's color. Changing it's RGBA (ARGB?) values don't do anything.

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
So chaosteil doesn't know how its own stuff works.... Strange.
Re: Question about libwiisprite transparency
August 20, 2008 12:32AM
It's not entirely his own stuff, alot of it is just functions that have a lot of default parameters or something to make it easier, mainly just a layer of top of GX
Re: Question about libwiisprite transparency
August 20, 2008 01:01AM
@WiiPhlex
GX is only used in the Image class and DrawSprite(), so why not just rewrite it? I'm not talented enough to do it unfortunately. But as henke37 pointed out, the GX texture format is pretty warped, which may be why I'm having so much trouble with it.

I see chaosteil as an all knowing code god (he wrote the library after all). So I'm disappointed when I see some of these problems or when what I try doesn't work. I personally really appreciate how far he's come with the library and I hope to improve it. Unfortunately, this is taking way to long. I'm just really stuck in a rut right now. I'll get it working though, I've never given up on a program because it was to hard (...yet).
Re: Question about libwiisprite transparency
August 21, 2008 12:54AM
Here's the latest code everyone:

drawableimage.h
#ifndef LIBWIISPRITE_DRAWABLEIMAGE
#define LIBWIISPRITE_DRAWABLEIMAGE
 
#include

 namespace 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

drawableimage.cpp
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);

      }
     
    }

testprogram.cpp
#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
Uhm, you are not paying attention to me are you?
The pixels are not stored like that, stop using them like this!



Edited 1 time(s). Last edit at 08/21/2008 08:11AM by henke37.
Re: Question about libwiisprite transparency
August 21, 2008 09:33AM
Quote
henke37
Uhm, you are not paying attention to me are you?
The pixels are not stored like that, stop using them like this!

Yeah dude, thought you would have got that, it's like 4th time he's said it...

Oh and maybe it's a little extreme to say "I see chaosteil as an all knowing code god".



Edited 1 time(s). Last edit at 08/21/2008 10:54AM by WiiPhlex.
Re: Question about libwiisprite transparency
August 21, 2008 12:09PM
The here is my calc...
Alpha = _pixels[i%16 * 64 + i]
Red = _pixels[i%16 * 64 + 16 + i]
Green = _pixels[i%16 * 64 + 32 + i]
Blue = _pixels[i%16 * 64 + 48 + i]



Edited 1 time(s). Last edit at 08/21/2008 12:10PM by Dykam.
Re: Question about libwiisprite transparency
August 21, 2008 10:07PM
@henke37
Sorry, I'm just an idiot sometimes. How do you propose I write the Get() and Set() functions which use _pixels?

@Dykam
Sorry, but I couldn't get your calculations to work with either the RGBA or ARGB format.

@WiiPhlex
Extreme? Probably, but I respect what he's accomplished. Yeah, all right "code god" is extreme.
Re: Question about libwiisprite transparency
August 22, 2008 07:48AM
Personally I just plain avoid the pixels array and make my own bitmap array that's easy to address in. And when I am done, I call the now overloaded _Flush method to copy the changes to the _pixels array (and to flush the memory too).
Sorry, only registered users may post in this forum.

Click here to login