Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (TipmyPip, AndrewAMD), 911 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
draw_quad and bmap_rendertarget issue #456843
12/12/15 13:11
12/12/15 13:11
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Just ran into this problem, pretty sure it's related to this one, posted by txesmi:

when rendering into a bmap using bmap_rendertarget and draw_quad the quad does not get drawn if it's outside of the window's dimensions.

what I mean by this is that draw_quad can draw on sections of a rendertarget that are outside of the screen's resolution - but only if some part of the quad is inside the rendertarget's dimensions.

Looks like there's some culling going on that uses the dimensions of the engine window instead of the rendertarget's dimensions.

Here's an example to test:
Code:
#include <acknex.h>

void main()
{
	fps_max = 60;
	
	wait(1);
	
	video_set(256, 256, 0, 2);
	
	wait(1);
	
	//
	
	BMAP * RenderTarget = bmap_createblack(512, 512, 8888); // create 512x512 bmap used as rendertarget -> bigger than the video resolution (256x256)
	bmap_fill(RenderTarget, vector(40, 32, 30), 100); // fill it with some dark color
	
	BMAP * SomeQuad = bmap_createblack(100, 75, 8888); // create a bmap to draw
	bmap_fill(SomeQuad, vector(255, 255, 255), 100); // fill with white, this one is colored using draw_quad()'s color-parameter
	
	//
	
	bmap_rendertarget(RenderTarget, 0, 1); // render folowing stuff into bmap, keep the bmap's content
	
	draw_quad(SomeQuad, vector(  0,   0, 0), NULL, NULL, NULL, vector(120, 240,  40), 100, 0); // GREEN: draw at position: 0, 0
	draw_quad(SomeQuad, vector(150,  50, 0), NULL, NULL, NULL, vector( 30, 300, 240), 100, 0); // RED:   draw at position: 300, 100 
	draw_quad(SomeQuad, vector(250, 250, 0), NULL, NULL, NULL, vector(240, 140,  40), 100, 0); // BLUE:  partially outside, can draw outside
	draw_quad(SomeQuad, vector(290, 325, 0), NULL, NULL, NULL, vector(240, 240, 240), 100, 0); // [ISSUE #1]: WHITE: fully outside, this one gets culled
	
	bmap_rendertarget(NULL, 0, 0); // stop rendering into bmap
	
	//
	
	// [ISSUE #2]: without this the BMAP*'s content is lost when changing the video resolution or minimizing the game when running acknex in fullscreen
	bmap_to_format(RenderTarget, bmap_format(RenderTarget)); // force bmap rewrite
	
	video_set(512, 512, 0, 2); // set video resolution to the rendertarget's size
	
	//
	
	PANEL * test_pan = pan_create("flags = SHOW;", 0); // create panel to show the rendertarget's content
	test_pan.bmap = RenderTarget;
}


It starts up with a resolution of 256x256 and creates a 512x512 BMAP*.
Then it renders 4 rectangles into this BMAP* using draw_quad, a green one, a red one, a blue one and a white one.
After this the resolution changes from 256x256 to 512x512 and the rendered image is being displayed using a panel.
In the screenshot I also marked a purple and a white area:



The purple area shows the application's initial dimensions.
The green and red rectangle which are fully inside the window are rendered correctly as expected.
The blue one which only intersects the window's resolution partially is also rendered completely.
However, the white one - which is not inside the window - is not being rendered at all, it should appear where the white area is marked in the screenshot.

The code example also addresses another issue (marked with '[ISSUE #2]' in the above code example):
after using bmap_rendertarget on a BMAP*, it will lose it's content when changing the video resolution or minimizing the game when running acknex in fullscreen.
You can test this by commenting out the line with bmap_to_format();
I suspect that the bmap somehow stays a rendertarget, but I'm not too sure about this.

I sincerely hope that at least the first issue (the one related to draw_quad) can be solved somwhere in the near future since this is a crucial feature I need for my current project.

kind regards, Alex


POTATO-MAN saves the day! - Random
Re: draw_quad and bmap_rendertarget issue [Re: Kartoffel] #456910
12/15/15 16:58
12/15/15 16:58
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Some feedback on whether or not this has been acknowledged would be nice...


POTATO-MAN saves the day! - Random
Re: draw_quad and bmap_rendertarget issue [Re: Kartoffel] #456939
12/16/15 11:01
12/16/15 11:01
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Yes, it's the same reason as with draw_quad. While 3D drawing uses the defined target size, 2D drawing is restricted to the screen size.

For preserving the content of a rendertarget, copy it into a normal, non-target bitmap. The rendertarget behavior can be device dependent.

Re: draw_quad and bmap_rendertarget issue [Re: jcl] #456949
12/16/15 14:06
12/16/15 14:06
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Thanks for the answer, but does this mean that there's no way to fix this behaviour of draw_xxx functions and enable rendering into big rendertargets using draw_quad?
Like I've said, being able to do so is quite important for what I'm planning to do and it would make things very complicated in that case. frown

Edit: I'm sorry but shouldn't fixing this require just a really small change in the engine's code?

Last edited by Kartoffel; 12/17/15 10:50.

POTATO-MAN saves the day! - Random
Re: draw_quad and bmap_rendertarget issue [Re: Kartoffel] #457046
12/21/15 11:49
12/21/15 11:49
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The only way at the moment for drawing into extended render targets is using a 3D drawing function. I have 2D extended rendering on the planned features list, but it's not yet clear if it's possible in a simple way.

Re: draw_quad and bmap_rendertarget issue [Re: jcl] #457048
12/21/15 16:18
12/21/15 16:18
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Thanks again, I'd really appreciate it if this could make it into an upcoming update.


POTATO-MAN saves the day! - Random
Re: draw_quad and bmap_rendertarget issue [Re: Kartoffel] #457137
12/29/15 10:07
12/29/15 10:07
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
I just ran into another problem using draw_quad and bmap_rendertarget.
It seems like draw_quad performs incorrect alphablending:



In this screenshot I'm drawing a title bar with a soft shadow onto an orange (100% opaque) bmap.
It should look like the top image but the bottom one is the result.

As you can see, the background (in this case a blue-green checker pattern) is clearly visible which means that draw_quad has lowered the alpha values of these pixels.

Sadly, this behaviour renders alphablending useless and causes me a lot of trouble.


POTATO-MAN saves the day! - Random
Re: draw_quad and bmap_rendertarget issue [Re: Kartoffel] #457138
12/29/15 10:29
12/29/15 10:29
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Panels and 2D elements are just written on the screen by standard blit operations. There is no "alphablending". Alpha and RGB just overwrite the alpha and RGB of the previous elements.

Re: draw_quad and bmap_rendertarget issue [Re: jcl] #457139
12/29/15 11:02
12/29/15 11:02
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline OP
Expert
Kartoffel  Offline OP
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Well, bmap_blit/_blitpart is a function that overwrites the bmap's pixels (I guess it uses something like memcpy to copy the pixel's color values).
draw_quad, however, seems to use some kind of blending. It has to, since it supports an 'alpha'-parameter as blending opacity and does produce correct results when rendering directly onto the screen.

In my example above, the rgb-channels are blended correctly but the alpha channel is not.

I'm not sure if draw_quad uses something similar to a shader, but I know that you get the same, incorrect blending when using the wrong values for DestBlend and SrcBlend in a shader's pass.

The problem is really just related to draw_quad in combination with bmap_rendertarget.
When using panels with different layers, this problem does not occur.
Neither does it when draw_quad is being used to draw an image directly onto the screen (without bmap_rendertarget).

Edit: Thinking about it, the reason why it works when rendering onto the screen is most likely because the screen's buffer doesn't use an alpha channel, so there's nothing to mess up.
...which means that bmap_rendertarget is probably not the culprit here, it's the blending-op that 2D-drawing-functions use.


POTATO-MAN saves the day! - Random
Re: draw_quad and bmap_rendertarget issue [Re: Kartoffel] #457142
12/29/15 13:09
12/29/15 13:09
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Yes. 2D operations just write content on the background. When the target has no alpha channel, as is the case for the screen, if can not become transparent by blitting content onto it. But if the target has an alpha channel, your operation writes into it and then the target becomes transparent at the same places where the blitted content was transparent. At least that's how I would interpret the problem you're describing.

Page 1 of 2 1 2

Moderated by  jcl, Nems, Spirit, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1