Gamestudio Links
Zorro Links
Newest Posts
Votes for future features
by DdlV
Yesterday at 23:46
Project Aum - Winter Contest 2017 - Update
by George
Yesterday at 22:37
hold key code returns very high value instead of 0 or 1
by 3run
Yesterday at 16:08
oldschool fps project
by 3run
Yesterday at 15:46
Sam Foster Sound | Experienced Indie Game Composer for Hire
by titanicpiano14
Yesterday at 15:02
[ALL STYLES] 2D Videogame Artist (pixel, vector, painted)
by DesixStudios
12/15/17 14:45
Easy question
by jcl
12/15/17 13:47
AUM Magazine
Latest Screens
RPG PARTY
Triton Wing now available on Steam
AckCon'17: Lotter vs The World
Triton Wing
Who's Online
12 registered (ChrstphFr, Ch40zzC0d3r, Dico, 3run, boatman, AndrewAMD, alibaba, easyX, 3 invisible), 453 Guests and 4 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
Meisterbene, Amocfx, cme, pataba, byano
17835 Registered Users
Topic Options
Rate This Topic
#455240 - 10/14/15 19:00 draw_... on big render targets
txesmi Offline
Serious User

Registered: 06/13/07
Posts: 1054
Loc: 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.



Attachments
bitmap_zoom.zip (116 downloads)


Top
#455400 - 10/19/15 11:30 Re: draw_... on big render targets [Re: txesmi]
jcl Offline

Chief Engineer

Registered: 07/22/00
Posts: 26002
Loc: 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.

Top
#455413 - 10/19/15 14:38 Re: draw_... on big render targets [Re: jcl]
txesmi Offline
Serious User

Registered: 06/13/07
Posts: 1054
Loc: 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

Top
#455414 - 10/19/15 15:14 Re: draw_... on big render targets [Re: txesmi]
jcl Offline

Chief Engineer

Registered: 07/22/00
Posts: 26002
Loc: 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.

Top
#455900 - 11/02/15 18:58 Re: draw_... on big render targets [Re: jcl]
Malice
Unregistered


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

Top
#455989 - 11/05/15 11:56 Re: draw_... on big render targets [Re: ]
jcl Offline

Chief Engineer

Registered: 07/22/00
Posts: 26002
Loc: 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.

Top
#469591 - 11/23/17 17:49 Re: draw_... on big render targets [Re: jcl]
Superku Offline
Senior Expert

Registered: 09/13/03
Posts: 6614
Loc: 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

Superku side-scroller: ~98.5% (??????!??)

Steam® Store Page ("Coming Soon"): http://store.steampowered.com/app/407570 Wowowowow!

Top
#469593 - 11/23/17 18:41 Re: draw_... on big render targets [Re: Superku]
Kartoffel Offline
Expert

Registered: 06/11/09
Posts: 2124
Loc: 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

Top
#469595 - 11/23/17 20:35 Re: draw_... on big render targets [Re: Kartoffel]
Superku Offline
Senior Expert

Registered: 09/13/03
Posts: 6614
Loc: 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

Superku side-scroller: ~98.5% (??????!??)

Steam® Store Page ("Coming Soon"): http://store.steampowered.com/app/407570 Wowowowow!

Top
#469596 - 11/23/17 20:39 Re: draw_... on big render targets [Re: Superku]
Kartoffel Offline
Expert

Registered: 06/11/09
Posts: 2124
Loc: 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

Top


Moderator:  jcl, Nems, Spirit, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | resources | magazine | manual | support faq | bugs

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) 3dgamestudio.net