panel->target_map plus draw_obj issue

Posted By: txesmi

panel->target_map plus draw_obj issue - 07/25/15 11:17

Hi,
I recently wrote a function that uses a panel target map to render my game buttons.

Code:
void fncPanRendererCreate ()
{
	bmpRendererBack = bmap_createblack ( 1024, 1024, 32 );
	bmpRendererWindow = bmap_create ( "mask.tga" );
	panRenderer = pan_create ( "", 1 );
	panRenderer->bmap = bmpRendererBack;
	panRenderer->size_x = bmap_width ( bmpRendererBack );
	panRenderer->size_y = bmap_height ( bmpRendererBack );
	panRenderer->flags = CENTER_X | OUTLINE;
	pan_setwindow ( panRenderer, 0, 0, 0, panRenderer->size_x, panRenderer->size_y, bmpRendererWindow, NULL, NULL );
	pan_setstring ( panRenderer, 0, 0, 0, fntButton, strTemp );
}

void fncButtonDraw ( BMAP *bmp, FRAME *frm, FONT *fnt, STRING *str )
{
	panRenderer->target_map = bmp;
	panRenderer->size_x = bmap_width ( bmp );
	panRenderer->size_y = bmap_height ( bmp );
	bmap_process ( bmpRendererBack, NULL, mtlClear );
	bmap_frame_quad ( bmpRendererBack, frm, nullvector, vector(panRenderer->size_x,panRenderer->size_y,0) ); // the function that draws the panel background image
	pan_setstring ( panRenderer, 1, panRenderer->size_x/2, (panRenderer->size_y-fnt->dy)/2, fnt, str );
	draw_obj ( panRenderer );
}





These three rectangles are drawn from the same panel. The panel has a background image (the rounded rectangle) that is neutral grey, a semitransparent yellow window covering the whole panel (added for this test) and a digit string. The panel has the OUTLINE flag set and tex_outline is set to 50.

The first rectangle is the renderer panel (panRenderer) after fncButtonDraw is called in order to draw the other two buttons images. It is correctly drawn on the screen.

The second rectangle is an image rendered by fncButtonDraw. It has a wrong alpha channel.

The third rectangle is an image rendered by fncButtonDraw and converted to a 888 format image after that in order to clearly see the RGB values. The panel background image color is correctly mixed by the alpha values of both panel members and their own colors.

Here is the process:
Code:
fncButtonDraw ( bmp, frmButton, fntButton, str );
fncButtonDraw ( bmp2, frmButton, fntButton, str );
bmap_to_format ( bmp2, 888 );
panRenderer->target_map = NULL;
panRenderer->flags |= SHOW;



I guess the problem is clear enough.

I found same behavior in other bmap rendering functions in the past: bmap_rendertarget plus semitransparent draw_quad, draw_obj and others. That is why I tryed this method in order to render my buttons.

I wish this problem is solved soon however ingenuous it may seem xP

Salud!
Posted By: Kartoffel

Re: panel->target_map plus draw_obj issue - 07/25/15 15:26

Err, I think I had the very same problem just a while ago...
However, my interface system didn't use panels, but a view and some entities.
The problem was the alpha blending that messed up the outlines of my text.

After setting the blending in the interface-shader manually to

AlphaBlendEnable = True;
DestBlend = InvSrcAlpha;
SrcBlend = One;


the problem was fixed.
Posted By: txesmi

Re: panel->target_map plus draw_obj issue - 07/25/15 19:23

Thanks for the info!

Unfortunatelly the use of views for buttons rendering would be a pain for this project. It has near a thousand buttons of different shapes. I thought on rendering the visible ones over a common template so it would have just a little part on memory at a time. A good save of memory.

I am thinking on building my own layered renderer using bmap_process and material skins. I hope it fast.
Posted By: jcl

Re: panel->target_map plus draw_obj issue - 07/27/15 07:32

From what I understood, the rendered panel had a wrong 50% alpha transparency? What happens when you set panRenderer->alpha = 100?
Posted By: txesmi

Re: panel->target_map plus draw_obj issue - 07/27/15 08:30

Hi jcl,
it has not the transparent flag set. The panel is opaque but the window covering the whole panel has a 30% transparency. The panel background is a 32bits image but the colored zone is opaque.

The first rectangle on the image is the panel drawn by the engine on its way. The other two are this first panel renderer over two images setting them as the render_map member of the panel. The panel is not shown on rendering time and the render_map is drawn with draw_obj instruction.

I will see what happens when setting transparent flag.

Thank you for your time,
txes

EDITED____________
No difference when setting TRANSLUCENT flag.
Posted By: jcl

Re: panel->target_map plus draw_obj issue - 07/27/15 08:46

Hmm, my test script displays panel render targets ok. Can you upload your example, or contact Support and send it to them? They'll look into it. The next update is just in the works and it would be good if this issue could be solved for 8.46.
Posted By: txesmi

Re: panel->target_map plus draw_obj issue - 07/27/15 10:04

Here you go!

dowload

I've taken the liberty of including two scripts: draw_obj.c and bmap_rendertarget.c

I venture to say that both behaviors are related.

Salud!
Posted By: jcl

Re: panel->target_map plus draw_obj issue - 07/27/15 11:23

Thanks for the script. From what I see, you're putting a half transparent window over your panel - that seems to be the reason of the transparency. A window is a hole in the panel background, it makes your panel transparent at that place and you can see through. Remove that window and all is fine.


Posted By: txesmi

Re: panel->target_map plus draw_obj issue - 07/27/15 11:52

Yes, the problems on translucent objects rendering over a bitmap is the main stream of the thread.

Originally Posted By: jcl
Remove that window and all is fine.

Is it fine to not be able to render any translucent bitmap, text outline, engine object, draw_..., etc, over an alpha channeled opaque bitmap with no alpha troubles? No, it is not fine.
Posted By: jcl

Re: panel->target_map plus draw_obj issue - 07/27/15 14:45

You're not rendering a bitmap over another bitmap. You're simply copying a bitmap into a target bitmap. If the source bitmap has alpha transparency, the target bitmap will naturally get that alpha transparency too.

This might be not intuitive, but it is just logical. In a 3D level, transparent objects are sorted and blended over each other. This won't happen with panel elements. They are just drawn, one after the other, regardless of their transparency.

I don't think that it's very difficult to nevertheless produce a non transparent panel of any sort, even on a target bitmap. If you have problems, just ask and I'll help.
Posted By: txesmi

Re: panel->target_map plus draw_obj issue - 07/27/15 15:37

Ok, I understand. Excuse my ignorance. It is really counterintuitive that a straight copy mixes the color channels.

I solved it already. Thank you for your offer.
© 2024 lite-C Forums