Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (monk12, Quad), 830 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
draw_... on big render targets #455240
10/14/15 17:00
10/14/15 17:00
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline OP
Serious User
txesmi  Offline OP
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
draw_... intructions (but draw_line) do not take effect out of the engine window meassures when a custom render target bigger than the engine window is set.

Could it be fixed?
Thank you in advance.


Attached Files
bitmap_zoom.zip (230 downloads)
Re: draw_... on big render targets [Re: txesmi] #455400
10/19/15 09:30
10/19/15 09:30
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
I certainly trust that you're able to fix it. A render target can be as big as a barn door if your hardware permits.

First check out the render target examples, especially the pssm script, and compare them with your code. If you can not draw into all of the target area, check if you have correctly set up the viewport size with view.pos x/y and view.size x/y. Next thing to check is if you've correctly created a z buffer for your render target, and if it has the right size.

If you tried anything and can still not fix it, please post here again and I'll look through your code.

Re: draw_... on big render targets [Re: jcl] #455413
10/19/15 12:38
10/19/15 12:38
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline OP
Serious User
txesmi  Offline OP
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
Yes, I encreased the zbuffer already.

Code:
bmap_zbuffer ( bmap_createblack ( 2048, 2048, 32 ) );



and encreased the size of the camera render target too.

Code:
level_load ( "" );
camera->bmap = bmap_createblack ( 2048, 2048, 32 );
camera->size_x = 2048;
camera->size_y = 2048;



wrote a function that fills a bitmap with with all draw_... instructions.

Code:
#define CHECKER_SIZE 128
void draw_map ( BMAP *bmpMap )
{
	bmap_rendertarget ( bmpMap, 0, 0 );
		draw_quad ( NULL, vector(0,0,0), NULL, vector(bmap_width(bmpMap),bmap_height(bmpMap),0), NULL, COLOR_WHITE, 100, 0 );
		int posX = 0;
		for ( ; posX<bmap_width(bmpMap); posX+=CHECKER_SIZE )
		{
			int posY = 0;
			for ( ; posY<bmap_height(bmpMap); posY+=CHECKER_SIZE )
			{
				if ( ( ( posX + posY ) / CHECKER_SIZE ) % 2 )
				{
					draw_quad ( NULL, vector(posX,posY,0), NULL, vector(CHECKER_SIZE,CHECKER_SIZE,0), NULL, COLOR_BLUE, 100, 0 );
					txtObj->pos_x = posX + 15 + CHECKER_SIZE * 0.5;
					txtObj->pos_y = posY;
					draw_obj ( txtObj );
				}
				else
				{
					draw_text ( "0", posX+15, posY+CHECKER_SIZE*0.5, COLOR_RED );
					panObj->pos_x = posX + CHECKER_SIZE * 0.5;
					panObj->pos_y = posY;
					draw_obj ( panObj );
				}
				
				draw_line ( vector(posX,posY,0), COLOR_BLACK, 0 );
				draw_line ( vector(posX,posY,0), COLOR_BLACK, 100 );
				draw_line ( vector(posX+CHECKER_SIZE,posY+CHECKER_SIZE,0), COLOR_BLACK, 100 );
				draw_line ( vector(posX+CHECKER_SIZE,posY+CHECKER_SIZE,0), COLOR_BLACK, 0 );
			}
		}
	bmap_rendertarget ( NULL, 0, 0 );
}



The result over a 2048x2048 bitmap in a 1024x768 window. The bitmap is shown at 1:4 scale.



The result over a 2048x2048 bitmap in a 1440x900 window.



In both cases the drawn area fits the window size instead of fullfill the bitmap. The only draw_... instruction that takes effect out of the window meassures is draw_line.

Never had troubles with level rendering on oversized render targets. I have got a NvidiaGTX660, so no hardware problem at all, I guess.

Thanks for your answer,
txes

Re: draw_... on big render targets [Re: txesmi] #455414
10/19/15 13:14
10/19/15 13:14
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
Thanks, we'll look into that. Your code snippets look fine to me. Maybe it's indeed something draw_quad specific. If so, then it will be fixed for the next update.

Re: draw_... on big render targets [Re: jcl] #455900
11/02/15 17:58
11/02/15 17:58

M
Malice
Unregistered
Malice
Unregistered
M



jcl Was there any confirmation on this issue? Just a yes/no on is a issue.

Re: draw_... on big render targets [Re: ] #455989
11/05/15 10:56
11/05/15 10:56
Joined: Jul 2000
Posts: 27,977
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,977
Frankfurt
As to my information it was an issue with 2d drawing commands. 2D drawing indeed is limited to the screen size. This is not a hard limit, so it can be worked around in the next update. 3D drawing should not be affected by this issue. So you could use for instance 3D sprite drawing commands for large offscreen buffers.

Re: draw_... on big render targets [Re: jcl] #469591
11/23/17 16:49
11/23/17 16:49
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
If I'm not mistaken this issue has not been fixed yet, has it?
Can this be fixed (in the sense of will it be fixed) in the next update?
Thanks.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: draw_... on big render targets [Re: Superku] #469593
11/23/17 17:41
11/23/17 17:41
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
one workaround is to draw things yourself, for example using dx9's DrawPrimitiveUp. DrawPrimitiveUp is an old feature that has legacy support in directx 9 but it gets the job done. also it doesn't require you to create mesh data on your graphics card. instead it directly sends the vertex data to it (has pros and cons).

this is what I'm using for my 2D renderer and it works pretty well. here's a basic example using the fixed function pipeline (using shaders would work, too). I didn't include culling, partial clipping of images and some other stuff that I had in there, (you might want to split setting the sampler states and the FVF into another function as this only needs to be done once every frame).

Code:
#define PRAGMA_POINTER
#include <acknex.h>
#include <d3d9.h>

// some datatypes

typedef byte bool;

typedef struct int_x
{
	int x, y;
} int_xy;

typedef struct int_xyzw
{
	int x, y, z, w;
} int_xyzw;

typedef struct int_rect
{
	int left, top, right, bottom;
} int_rect;

typedef struct float_rect
{
	float left, top, right, bottom;
} float_rect;

//

typedef struct BMAP_DRAW_VERTEX
{ 
	float x, y, z;
	float rhw;
	D3DCOLOR color; 
	float u, v;
} BMAP_DRAW_VERTEX;

#define D3DFVF_BMAP_DRAW_VERTEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1) // vertex's content ("Flexible" Vertex Format)

BMAP_DRAW_VERTEX _bmap_draw_vertices[4]; // vertices used for _bmap_draw, defining them locally inside the function was slower when I tested it, I think?

//

void bmap_draw(BMAP * Bmap, int_rect * iRect, float_rect * fUV, bool AlphaBlendEnable, D3DCOLOR Color)
{
	/// vertices-setup ///
	
	_bmap_draw_vertices[0].x = _bmap_draw_vertices[2].x = iRect->left;
	_bmap_draw_vertices[0].y = _bmap_draw_vertices[1].y = iRect->top;
	_bmap_draw_vertices[1].x = _bmap_draw_vertices[3].x = iRect->right;
	_bmap_draw_vertices[2].y = _bmap_draw_vertices[3].y = iRect->bottom;
	
	_bmap_draw_vertices[0].u = _bmap_draw_vertices[2].u = fUV->left;
	_bmap_draw_vertices[0].v = _bmap_draw_vertices[1].v = fUV->top;
	_bmap_draw_vertices[1].u = _bmap_draw_vertices[3].u = fUV->right;
	_bmap_draw_vertices[2].v = _bmap_draw_vertices[3].v = fUV->bottom;
	
	_bmap_draw_vertices[0].color = _bmap_draw_vertices[1].color = _bmap_draw_vertices[2].color = _bmap_draw_vertices[3].color = Color;
	
	/// drawing ///
	
	// get the active D3D device
	LPDIRECT3DDEVICE9 pd3dDev = (LPDIRECT3DDEVICE9)draw_begin();
	
	if(!AlphaBlendEnable) // alphablending?
	{
		pd3dDev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
		
		pd3dDev->SetTextureStageState(0, D3DRS_SRCBLEND, 2); // ONE
		pd3dDev->SetTextureStageState(0, D3DRS_DESTBLEND, 1); // ZERO
	}
	else
	{
		pd3dDev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
		
		pd3dDev->SetTextureStageState(0, D3DRS_SRCBLEND, 5); // SRCALPHA
		pd3dDev->SetTextureStageState(0, D3DRS_DESTBLEND, 6); // INCSRCALPHA
	}
	
	// set texture
	pd3dDev->SetTexture(0, Bmap->d3dtex); // NOTE: BMAP* needs to have a valid format! (8888 works, for example)
	
	pd3dDev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); // texture sampling and color-op
	pd3dDev->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
	pd3dDev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); // multiply texture with color
	
	// draw triangles
	pd3dDev->SetFVF(D3DFVF_BMAP_DRAW_VERTEX);
	pd3dDev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, (LPVOID)_bmap_draw_vertices, sizeof(BMAP_DRAW_VERTEX));
}

int get_next_pow2(int x) // get next power of two
{
	int xp2;
	for(xp2 = 1; xp2 < x; xp2 <<= 1);
	return xp2;
}

void bmap_UV_to_fUV(int_xy * BmapDimensions, int_rect * UV, float_rect * Dest_fUV) // convert uv in pixels (UV) to uv in [0,1] range (Dest_fUV)
{
	if(UV != NULL)
	{
		Dest_fUV->left   = UV->left;
		Dest_fUV->top    = UV->top;
		Dest_fUV->right  = UV->right;
		Dest_fUV->bottom = UV->bottom;
	}
	else
	{
		Dest_fUV->left   = 0.0;
		Dest_fUV->top    = 0.0;
		Dest_fUV->right  = BmapDimensions->x;
		Dest_fUV->bottom = BmapDimensions->y;
	}
	
	int xpow2 = get_next_pow2(BmapDimensions->x);
	int ypow2 = get_next_pow2(BmapDimensions->y);
	
	// apply half pixel offset and compensate strechting (due to non power of two dimensions)
	Dest_fUV->left   = (Dest_fUV->left   + 0.5) / (float)xpow2;
	Dest_fUV->top    = (Dest_fUV->top    + 0.5) / (float)ypow2;
	Dest_fUV->right  = (Dest_fUV->right  + 0.5) / (float)xpow2;
	Dest_fUV->bottom = (Dest_fUV->bottom + 0.5) / (float)ypow2;
}

void main()
{
	fps_max = 60;
	
	wait(1);
	
	// only needed to set once (since vertex array is global)
	
	_bmap_draw_vertices[0].z = _bmap_draw_vertices[1].z = _bmap_draw_vertices[2].z = _bmap_draw_vertices[3].z = 0.0; // no depth needed
	_bmap_draw_vertices[0].rhw = _bmap_draw_vertices[1].rhw = _bmap_draw_vertices[2].rhw = _bmap_draw_vertices[3].rhw = 1.0; // no perspective
	
	//
	
	BMAP * bmap = bmap_create(ImageFileNameHere);
	bmap_to_format(bmap, 8888); // depending on the bmap's format, this is sometimes necessary to force the engine to create a valid d3dtexture for the bmap
	
	int_rect DrawRect; // target position for drawing
	DrawRect.left = 50;
	DrawRect.top = 30;
	DrawRect.right = DrawRect.left + bmap_width(bmap);
	DrawRect.bottom = DrawRect.top + bmap_height(bmap);
	
	int_xyzw BmapDimensions; // size of the bmap in pixels
	BmapDimensions.x = bmap_width(bmap);
	BmapDimensions.y = bmap_height(bmap);
	
	int_rect UV; // min/max UVs in PIXELS
	UV.left = UV.top = 0.0;
	UV.right = BmapDimensions.x;
	UV.bottom = BmapDimensions.y;
	
	float_rect fUV; // float UVs in [0,1] range
	bmap_UV_to_fUV(&BmapDimensions, &UV, &fUV); // also possible: use NULL as input UV to use the whole image
	
	while(1)
	{
		bmap_draw(bmap, &DrawRect, &fUV, true, 0xFFFFFFFF);
		
		wait(1);
	}
}


Also keep in mind that setting those samplers might cause other 2d stuff to render incorrectly (like DEBUG_BMAP maybe), just in case some things render strangely. It works for me, though.

Edit: I forgot: this also works together with bmap_rendertarget()


POTATO-MAN saves the day! - Random
Re: draw_... on big render targets [Re: Kartoffel] #469595
11/23/17 19:35
11/23/17 19:35
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Oh that's very interesting... thanks for sharing.
I'd need to be able to draw (Unicode) text as well. Hard to judge from a first glance if that's possible that way but I may dig deeper next week.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: draw_... on big render targets [Re: Superku] #469596
11/23/17 19:39
11/23/17 19:39
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Unicode might be tricky, I never did any text rendering except the default 8bit ascii stuff (using textures as fonts).


POTATO-MAN saves the day! - Random

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