Blending hell... (changing transparency)

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Blending hell... (changing transparency)

Post by Ghoti »

Hi folks,

I have this trianglestrip which is constructed with 4 vertices. No I want to fade out that trianglestrip which has a texture on it.
I can fade in and out trianglestrips without textures on it but as soon as I use textures it does not work anymore.
Now here is the code I try to use:

Code: Select all

int GraphicsObject::Render2DImageOn3D(float left, float top, const Image* texture, int alpha) {

	vertexTCP* DisplayVertices = (vertexTCP*) sceGuGetMemory(4 * sizeof(vertexTCP));

	sceGuDisable(GU_DEPTH_TEST); 
	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
	sceGuTexMode(GU_PSM_8888, 0 ,0 ,0);
	sceGuTexImage(0, texture->textureWidth, texture->textureHeight, texture->textureWidth, (void*) texture->data);

			
	DisplayVertices[0].u = 0.0f;
	DisplayVertices[0].v = 0.0f;
	DisplayVertices[0].color = GU_RGBA(255, 255, 255, alpha);
	DisplayVertices[0].x = left;
	DisplayVertices[0].y = top;
	DisplayVertices[0].z = 0.0f;

	DisplayVertices[1].u = texture->textureWidth-1;
	DisplayVertices[1].v = 0.0f;
	DisplayVertices[1].color = GU_RGBA(255, 255, 255, alpha);
	DisplayVertices[1].x = left + texture->textureWidth;
	DisplayVertices[1].y = top;
	DisplayVertices[1].z = 0.0f;

	DisplayVertices[2].u = 0.0f;
	DisplayVertices[2].v = texture->textureHeight-1;
	DisplayVertices[2].color = GU_RGBA(255, 255, 255, alpha);
	DisplayVertices[2].x = left;
	DisplayVertices[2].y = top + texture->textureHeight;
	DisplayVertices[2].z = 0.0f;

	DisplayVertices[3].u = texture->textureWidth-1;
	DisplayVertices[3].v = texture->textureHeight-1;
	DisplayVertices[3].color = GU_RGBA(255, 255, 255, alpha);
	DisplayVertices[3].x = left + texture->textureWidth;
	DisplayVertices[3].y = top + texture->textureHeight;
	DisplayVertices[3].z = 0.0f;

	sceGuDrawArray(GU_TRIANGLE_STRIP, GU_TEXTURE_32BITF | GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_2D, 4, 0, DisplayVertices);

	sceGuEnable(GU_DEPTH_TEST); 

	return 0;
}
What I try to do is render the trianglestrip with a certain alpha value. The texture used for this however also has alpha values but they are not variable.

It always has the same alpha channel no matter what I pass for alpha as value(10 displays the same as 255)

Is there a flag I am forgetting or something? or is the blending function I use not correct? Does the color attribute of a triangle even have effect on the rendering when a texture is also applied?

I have tested with the sceGuBlendFunc() function but I can't seem to get it right, it does not seem to have that effect anyway.

Any ideas ?
yabadabo
Posts: 10
Joined: Fri Mar 30, 2007 8:49 am

Post by yabadabo »

You are missing the enable blend and texture, and setting the correct blend functions before calling the sceGuDraw.
Probably something like is what you need

Code: Select all

sceGuEnable( GU_TEXTURE_2D );
sceGuEnable( GU_BLENDING );
sceGuBlendFunc( GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 );

// Use this tex functon, or only the alpha of the texture will be used
sceGuTexFunc(GU_TFX_GU_TFX_MODULATE, GU_TCC_RGBA);

... your code here except the sceGuTexFunc 

sceGuDisable( GU_BLENDING );
sceGuDisable( GU_TEXTURE_2D );
J
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

yabadabo wrote:You are missing the enable blend and texture, and setting the correct blend functions before calling the sceGuDraw.
Probably something like is what you need

Code: Select all

sceGuEnable( GU_TEXTURE_2D );
sceGuEnable( GU_BLENDING );
sceGuBlendFunc( GU_ADD, GU_SRC_ALPHA, GU_ONE_MINUS_SRC_ALPHA, 0, 0 );

// Use this tex functon, or only the alpha of the texture will be used
sceGuTexFunc(GU_TFX_GU_TFX_MODULATE, GU_TCC_RGBA);

... your code here except the sceGuTexFunc 

sceGuDisable( GU_BLENDING );
sceGuDisable( GU_TEXTURE_2D );
J
Hi, well the blending and texture2d are already enabled, but I do that in the init graphics function I have, the same goes for the blendfunc, i have it the same as you and I tried using the modulate function also but it does not work :S it flickers between the two images that I want to fade in and out (like a transition.) using the modulate.

the images are displaying correct except that they do not fade out over time.
Post Reply