 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Sun Nov 25, 2007 3:58 am Post subject: Blending hell... (changing transparency) |
|
|
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: |
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 ? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
yabadabo
Joined: 30 Mar 2007 Posts: 10
|
Posted: Sun Nov 25, 2007 5:25 am Post subject: |
|
|
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: | 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 |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Sun Nov 25, 2007 5:33 am Post subject: |
|
|
| 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: | 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. _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|