Peršokti į turinį
  • ŽAIDIMAI
  • , ŽAIDIMAI
  • ŽAIDIMAI

C++ SDL alpha blending reikia pagalbos


L0vEe

Ši tema yra neaktyvi. Paskutinis pranešimas šioje temoje buvo prieš 747 dienas (-ų). Patariame sukurti naują temą, o ne rašyti naują pranešimą.

Už neaktyvių temų prikėlimą galite sulaukti įspėjimo ir pranešimo pašalinimo!

Recommended Posts

Sveiki as parasysiu angliskai man patogiau pasakyti apie mano problema.

So I created a function where it control RGBA colours of the image (that's what I think). However something is not right and I can't figure out myself so if you could help me to solve this problem that would be amazing.

It loads up the foreground image however, it does not blend with background image when it shows the results.

I'm not really sure how to use this function "SDL_Surface* blendImage" to use in for loop

This is what I should create: 

Mano uzdavynis

Mano code:

			SDL_Surface* convertedSurface = NULL;
			SDL_Surface* convertedSurface2 = NULL;

			SDL_Surface* blendImage(SDL_Surface* img1, SDL_Surface* img2);


			printf("Width/height of image: %i %i\n", foreground->w, foreground->h);
			printf("Image format: %s\n", SDL_GetPixelFormatName(foreground->format->format));

			printf("Width/height of image: %i %i\n", background->w, background->h);
			printf("Image format: %s\n", SDL_GetPixelFormatName(background->format->format));

			SDL_PixelFormat* format = SDL_AllocFormat(SDL_PIXELFORMAT_RGBA32);
			convertedSurface = SDL_ConvertSurface(foreground, format, 0);
			printf("Image format after conversion: %s\n", SDL_GetPixelFormatName(convertedSurface->format->format));

			convertedSurface2 = SDL_ConvertSurface(background, format, 0);
			printf("Image format after conversion: %s\n", SDL_GetPixelFormatName(convertedSurface2->format->format));

			Uint8* frontPtr = (Uint8*)convertedSurface->pixels;
			Uint8* backPtr = (Uint8*)convertedSurface2->pixels;

			for (int i = 0; i < foreground->w * foreground->h * 4; i += 4)
			{
				Uint8 frontR = *(frontPtr + i + 0);
				Uint8 frontG = *(frontPtr + i + 1);
				Uint8 frontB = *(frontPtr + i + 2);
				Uint8 frontA = *(frontPtr + i + 3);
				Uint8 backR = *(backPtr + i + 0);
				Uint8 backG = *(backPtr + i + 1);
				Uint8 backB = *(backPtr + i + 2);
				Uint8 backA = *(backPtr + i + 3);

				*(frontPtr + i + 0) = (frontR * frontA + backR * backA * (255 - frontA) / 255) / *(frontPtr);
				*(frontPtr + i + 1) = (frontG * frontA + backG * backA * (255 - frontA) / 255) / *(frontPtr);
				*(frontPtr + i + 2) = (frontB * frontA + backB * backA * (255 - frontA) / 255) / *(frontPtr);
				*(frontPtr + i + 3) = frontA + (backA * (255 - frontR) / 255);

			}

 

Okey jau daugiau padariau bet mano vistiek images nera right turiu buti kad viena image butu transparent and you can see the background. I think it's just RGB formula isn't right. 

	*(frontPtr + i + 0) = (frontR * frontA / 255) + (backR * backA * (255 - frontA) / (255 * 255));
		*(frontPtr + i + 1) = (frontG * frontA / 255) + (frontG * backA * (255 - frontA) / (255 * 255));
		*(frontPtr + i + 2) = (frontB * frontA / 255) + (frontB * backA * (255 - frontA) / (255 * 255));
		*(frontPtr + i + 3) = frontA + (backA * (255 - frontA) / 255);

Ar zinot kaip sutvarkyti?

Naudojau is sito pavyzdzio:

https://stackoverflow.com/questions/1944095/how-to-mix-two-argb-pixels

Pats isprendziau problema galit uzdaryti tema aciu!

Redaguota , nario L0vEe
Nuoroda į komentarą
Dalintis per kitą puslapį

Ši tema yra neaktyvi. Paskutinis pranešimas šioje temoje buvo prieš 747 dienas (-ų). Patariame sukurti naują temą, o ne rašyti naują pranešimą.

Už neaktyvių temų prikėlimą galite sulaukti įspėjimo ir pranešimo pašalinimo!

Prisijungti prie diskusijos

Palikti atsakymą galite iš karto, o užsiregistruoti vėliau. Jeigu jau turite paskyrą mūsų forume, Prisijunkite.

Svečias
Atsakyti šioje temoje...

×   Įklijuotas tekstas turi teksto formatavimą.   Pašalinti teksto formatavimą

  Galimi tik 75 veidukai.

×   Nuoroda buvo automatiškai įterpta.   Įterpti nuorodą paprastai

×   Jūsų ankstesnis pranešimas buvo atkurtas.   Išvalyti redaktorių

×   Jūs negalite įkelti nuotraukas tiesiogiai.Įkelkite arba įdėkite nuotraukas iš URL.

Skelbimai


×
×
  • Sukurti naują...