2d strange problem d3d9

Started by
6 comments, last by gamedevtmp 20 years, 4 months ago
i have a strange problem... i'm making a 2D game with Direct3D 9, i'm using Textured Quads. On ATI this work perfecly but on GeForce 4 or TNT2 M64 the pixels seems to be perturbed....does anyone know what's this problem and how to solve it ? Look the screenshots: http://chemzys.free.fr/So6/ [edited by - gamedevtmp on November 28, 2003 8:34:14 PM]
Advertisement
Weird... are you using a filter?
And the rockets' red glare, the bombs bursting in air,gave proof through the fight that our flag was still there.Oh say, does that star-spangled banner yet waveover the land of the free and the home of the brave?
how that ?? i have that.
i don''t use filter i think

d3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
d3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
d3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
d3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
d3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );

d3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_NONE );
d3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_NONE );
I mean... when you render, do you use a filter, like a linear filter?
And the rockets' red glare, the bombs bursting in air,gave proof through the fight that our flag was still there.Oh say, does that star-spangled banner yet waveover the land of the free and the home of the brave?
i donno how to use a liner filter so i don''t user linear filter.
It''s the code of my blitter, at the end there is the fillVertice methode of the sprite

#include "C3DBlitter.h"C3DBlitter::C3DBlitter( long resWidth, long resHeight, D3DFORMAT resFormat, HWND hWnd, BOOL bWindowedMode ){	HRESULT hr;	GetCurrentDirectory( MAX_PATH, directory );    //Make Direct3D object    d3d = Direct3DCreate9( D3D_SDK_VERSION );    //Make sure NULL pointer was not returned    if( !d3d )        return;    //Get device capabilities    ZeroMemory( &d3dCaps, sizeof( d3dCaps ) );    if( FAILED( d3d->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps ) ) )        return;    //Setup present parameters    ZeroMemory( &d3dPresent, sizeof( d3dPresent ) );    d3dPresent.SwapEffect = D3DSWAPEFFECT_FLIP;    d3dPresent.hDeviceWindow = hWnd;    d3dPresent.BackBufferCount = 1;	d3dPresent.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;    //Check if windowed    if( bWindowedMode )    {        D3DDISPLAYMODE d3ddm;        RECT rWindow;        //Get display mode        d3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );        //Get window bounds        GetClientRect( hWnd, &rWindow );		//Setup screen dimensions        this->resWidth = rWindow.right - rWindow.left;        this->resHeight = rWindow.bottom - rWindow.top;        //Setup backbuffer        d3dPresent.Windowed = true;        d3dPresent.BackBufferFormat = d3ddm.Format;        d3dPresent.BackBufferWidth = rWindow.right - rWindow.left;        d3dPresent.BackBufferHeight = rWindow.bottom - rWindow.top;    }    else    {   		this->resWidth = resWidth;		this->resHeight = resHeight;        d3dPresent.Windowed = false;        d3dPresent.BackBufferWidth = resWidth;        d3dPresent.BackBufferHeight = resHeight;        d3dPresent.BackBufferFormat = resFormat;    }    //Check if hardware vertex processing is available    if( d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )    {            //Create device with hardware vertex processing        hr = d3d->CreateDevice( D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL, hWnd,            D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dPresent, &d3dDevice );            }    else    {        //Create device with software vertex processing        hr = d3d->CreateDevice( D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL, hWnd,            D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dPresent, &d3dDevice );    }    //Make sure device was created    if( FAILED( hr ) )        return;		/*for( long i = 0; i < NB_TEXTURES; i++ )	{		char fileName[MAX_PATH];		sprintf( fileName, "%s/Textures/Tex_%d.png", directory, i );		tTextures = loadTexture( fileName );<br>	}*/</font><br><br>	<font color=gray>// faire un undef si on veux changer !<br></font><br>	<font color=gray>//#define IDR_DATA1                       105<br></font><br><br>	tTextures[<font color=purple>0</font>] = loadTextureFromResource( IDR_DATA1 );<br>	tTextures[<font color=purple>1</font>] = loadTextureFromResource( IDR_DATA2 );<br>	tTextures[<font color=purple>2</font>] = loadTextureFromResource( IDR_DATA3 );<br>	tTextures[<font color=purple>3</font>] = loadTextureFromResource( IDR_DATA4 );<br><br>	<br>	<font color=gray>//<font color=gray>//Create vertex buffer and set as stream source<br></font></font><br>    d3dDevice-&gt;CreateVertexBuffer( <font color=blue>sizeof</font>( TLVERTEX ) * 4, 0, D3DFVF_TLVERTEX, D3DPOOL_MANAGED, &vertexBufferStandard, NULL );<br>	<font color=gray>//d3dDevice-&gt;CreateVertexBuffer( sizeof( TLVERTEX ) * 4, 0, D3DFVF_TLVERTEX, D3DPOOL_DEFAULT, &vertexBufferStandard, NULL );<br></font><br><br>	<font color=gray>//Create vertex buffer and set as stream source<br></font><br>    d3dDevice-&gt;CreateVertexBuffer( <font color=blue>sizeof</font>( TLVERTEX ) * NB_GAME_VERTICES, 0, D3DFVF_TLVERTEX, D3DPOOL_MANAGED, &vertexBufferGame, NULL );<br>	<font color=gray>//d3dDevice-&gt;CreateVertexBuffer( sizeof( TLVERTEX ) * NB_GAME_VERTICES, 0, D3DFVF_TLVERTEX, D3DPOOL_DEFAULT, &vertexBufferGame, NULL );<br></font><br><br>	restoreAll();<br><br>	limitFPS = FALSE;<br>	showFPS  = FALSE;<br>	sFps = <font color=blue>new</font> CGString( 0, 0, "<font color=darkred>", FONT_TYPE_0, MAX_3DBLITTER_STR_FPS, VERTEX_BUFFER_STANDARD );<br>	<br>	<font color=gray>//Successfully initalized Direct3D<br></font><br>}<br><br>C3DBlitter::~C3DBlitter( void )<br>{<br>	if( sFps )<br>	{<br>		delete sFps;<br>		sFps = NULL;<br>	}<br><br>	for( long i = 0; i &lt; NB_TEXTURES; i++ )<br>	{<br>		if( tTextures )<br>		{<br>			tTextures-&gt;Release();<br>			tTextures = NULL;<br>		}<br>	}<br><br>	if( vertexBufferStandard )<br>	{<br>        vertexBufferStandard-&gt;Release();<br>		vertexBufferStandard = NULL;<br>	}<br><br>	if( vertexBufferGame )<br>	{<br>		vertexBufferGame-&gt;Release();<br>		vertexBufferGame = NULL;<br>	}<br><br>    <font color=gray>//Release device<br></font><br>    if( d3dDevice )<br>        d3dDevice-&gt;Release();<br><br>    <font color=gray>//Release d3d object<br></font><br>    if( d3d )<br>        d3d-&gt;Release();<br><br>    <font color=gray>//Successfully closed Direct3D<br></font><br>}<br><br>void C3DBlitter::restoreAll( void )<br>{<br>	<font color=gray>//Set vertex shader<br></font><br>    d3dDevice-&gt;SetVertexShader( NULL );<br>    d3dDevice-&gt;SetFVF( D3DFVF_TLVERTEX );<br><br>    <font color=gray>//Setup rendering states<br></font><br>    d3dDevice-&gt;SetRenderState( D3DRS_LIGHTING, FALSE );<br>    d3dDevice-&gt;SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );<br>    d3dDevice-&gt;SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );<br>    d3dDevice-&gt;SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );<br>    d3dDevice-&gt;SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );<br><br>	d3dDevice-&gt;SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_NONE );<br>	d3dDevice-&gt;SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_NONE );<br>}<br><br>IDirect3DTexture9 *C3DBlitter::getTexture( long idxTextures )<br>{<br>	return tTextures[idxTextures];<br>}<br><br><br>IDirect3DTexture9 *C3DBlitter::loadTextureFromResource( long rId )<br>{<br>    IDirect3DTexture9 *d3dTexture;<br>    D3DXIMAGE_INFO SrcInfo;			<font color=gray>//Optional<br></font><br><br>    <font color=gray>//Use a black colourkey<br></font><br>    D3DCOLOR colorkey = D3DCOLOR_ARGB( 255, 0, 0, 0 );<br><br>	<font color=gray>// Load image from file<br></font><br>    if( FAILED( D3DXCreateTextureFromResourceEx( d3dDevice, GetModuleHandle( NULL ), MAKEINTRESOURCE( rId ), 0, 0, 1, 0, <br>          D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_NONE, D3DX_DEFAULT, <br>          colorkey, &SrcInfo, NULL, &d3dTexture ) ) )<br><br>	{<br>        return NULL;<br>    }<br><br>	<font color=gray>//Return the newly made texture<br></font><br>    return d3dTexture;<br>}<br><br>void C3DBlitter::clear( void )<br>{<br>	<font color=gray>//d3dDevice-&gt;Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_COLORVALUE( 0.35f, 0.53f, 0.7, 1.0f ), 0.0f, 0 );<br></font><br>	d3dDevice-&gt;Clear( 0, NULL, D3DCLEAR_TARGET, 0xFF000000, 0.0f, 0 );<br>}<br><br>void C3DBlitter::startBlt( void )<br>{<br>	d3dDevice-&gt;BeginScene();<br>}<br><br>void C3DBlitter::setShowFPS( BOOL showFPS )<br>{<br>	this-&gt;showFPS = showFPS;<br>}<br><br>void C3DBlitter::setLimitFPS( BOOL limitFPS )<br>{<br>	this-&gt;limitFPS = limitFPS;<br>}<br><br>BOOL C3DBlitter::getLimitFPS( void )<br>{<br>	return limitFPS;<br>}<br><br>void C3DBlitter::endBlt( void )<br>{<br>	static long lastT = 0;<br>	static long fpsCounter = 0;<br>	static long fps = 0;<br><br>	long now = timeGetTime();<br><br>	if( now - lastT &gt;= 1000 )<br>	{<br>		lastT = now;<br>		fps = fpsCounter;<br>		fpsCounter = 0;<br><br>		char str[MAX_3DBLITTER_STR_FPS + 1];<br>		sprintf( str, "</font>FPS: %d", fps );<br>		sFps-&gt;setText( str );<br>	}<br><br>	<font color=blue>if</font>( showFPS )<br>	{<br>		sFps-&gt;prepareBlit();<br>		sFps-&gt;blit( 0 );<br>	}<br><br>	fpsCounter++;<br>	<br>	d3dDevice-&gt;EndScene();<br>}<br><br><font color=blue>void</font> C3DBlitter::present( <font color=blue>void</font> )<br>{<br>	<font color=blue>static</font> BOOL readyToPresent = TRUE;<br>	<font color=blue>static</font> <font color=blue>long</font> lastTimeFrame = 0;	<br><br>	<font color=blue>switch</font>( d3dDevice-&gt;TestCooperativeLevel() )<br>	{<br>		<font color=blue>case</font> D3DERR_DEVICELOST:<br>			readyToPresent = FALSE;<br>			<font color=blue>return</font>;<br><br>		<font color=blue>case</font> D3DERR_DEVICENOTRESET:<br>			d3dDevice-&gt;Reset( &d3dPresent );<br>			restoreAll();<br>			readyToPresent = TRUE;<br>			<font color=blue>return</font>;<br>	}<br><br>	<font color=blue>if</font>( readyToPresent )<br>	{<br>		<font color=blue>if</font>( limitFPS )<br>		{<br>			<font color=blue>while</font>( timeGetTime() - lastTimeFrame &lt; 15 )<br>				;<br>		}<br><br>		lastTimeFrame = timeGetTime();<br><br><br>		d3dDevice-&gt;Present( NULL, NULL, NULL, NULL );<br>	}<br>}<br><br><font color=blue>void</font> C3DBlitter::lockVertexBufferGame( TLVERTEX **vertices )<br>{<br>	<font color=gray><font color=gray>//Lock the vertex buffer<br></font></font><br>	vertexBufferGame-&gt;Lock( 0, 0, ( <font color=blue>void</font> ** )vertices, NULL );<br>}<br><br><font color=blue>void</font> C3DBlitter::unlockVertexBufferGame( <font color=blue>void</font> )<br>{<br>	<font color=gray><font color=gray>//Unlock the vertex buffer<br></font></font><br>	vertexBufferGame-&gt;Unlock();<br>}<br><br><font color=blue>void</font> C3DBlitter::blit( C3DSprite *s, DWORD vIdx, <font color=blue>long</font> addX, <font color=blue>long</font> addY )<br>{<br>	<font color=blue>long</font> startVertice = vIdx;<br><br>	<font color=blue>if</font>( s-&gt;getHaveClip() )<br>	{<br>		RECT rClip;<br>		<br>		s-&gt;getRClip( &rClip );<br><br>		D3DVIEWPORT9 vp;<br>		memset( &vp, 0, <font color=blue>sizeof</font>( D3DVIEWPORT9 ) );<br>		vp.X      = rClip.left + addX;<br>		vp.Y      = rClip.top  + addY;<br>		vp.Width  = rClip.right  - rClip.left;<br>		vp.Height = rClip.bottom - rClip.top;<br><br>		d3dDevice-&gt;SetViewport( &vp );<br>	}<br>	<br>	<font color=gray>//Set texture<br></font><br>	d3dDevice-&gt;SetTexture( 0, tTextures[<font color=purple>s-&gt;getIdxTexture()</font>] );<br>	<br>	<font color=blue>switch</font>( s-&gt;getVbt() )<br>	{<br>		<font color=blue>case</font> VERTEX_BUFFER_GAME:<br>			d3dDevice-&gt;SetStreamSource( 0, vertexBufferGame, 0, <font color=blue>sizeof</font>( TLVERTEX ) );<br>			<font color=blue>break</font>;<br><br>		<font color=blue>case</font> VERTEX_BUFFER_STANDARD:<br>		{		<br>			TLVERTEX *vertices;<br><br>			startVertice = 0;<br><br>			<font color=gray><font color=gray>//Lock the vertex buffer<br></font></font><br>			vertexBufferStandard-&gt;Lock( 0, 0, ( <font color=blue>void</font> ** )&vertices, NULL );<br>			s-&gt;fillVertices( vertices, addX, addY );<br>			<font color=gray><font color=gray>//Unlock the vertex buffer<br></font></font><br>			vertexBufferStandard-&gt;Unlock();<br><br>			d3dDevice-&gt;SetStreamSource( 0, vertexBufferStandard, 0, <font color=blue>sizeof</font>( TLVERTEX ) );<br><br>			<font color=blue>break</font>;<br>		}<br>	}<br><br>	d3dDevice-&gt;DrawPrimitive( D3DPT_TRIANGLEFAN, startVertice, 2 );<br><br>	<font color=blue>if</font>( s-&gt;getHaveClip() )<br>	{<br>		D3DVIEWPORT9 rvp;<br>		memset( &rvp, 0, <font color=blue>sizeof</font>( D3DVIEWPORT9 ) );<br>		rvp.X      = 0;<br>		rvp.Y      = 0;<br>		rvp.Width  = resWidth;<br>		rvp.Height = resHeight;<br><br>		d3dDevice-&gt;SetViewport( &rvp );<br>	}<br>}<br><br><br><br><br><br><br><br><br><br><br><font color=blue>void</font> C3DSprite::fillVertices( TLVERTEX *vertices, <font color=blue>long</font> addX, <font color=blue>long</font> addY )<br>{<br>	<font color=blue>if</font>( visible )<br>	{<br>		<font color=gray>//Setup vertices<br></font><br>		RECT rcDest;<br>		RECT rcSrc;<br><br>		memcpy( &rcDest, &rDest, <font color=blue>sizeof</font>( RECT ) );<br>		rcDest.left   += addX;<br>		rcDest.top    += addY;<br>		rcDest.right  += addX;<br>		rcDest.bottom += addY;<br><br>		getCurrentRSrc( &rcSrc );<br><br>		vertices[<font color=purple>0</font>].colour = verticesColors[<font color=purple>0</font>];<br>		vertices[<font color=purple>0</font>].x = ( <font color=blue>float</font> ) rcDest.left;<br>		vertices[<font color=purple>0</font>].y = ( <font color=blue>float</font> ) rcDest.top;<br>		vertices[<font color=purple>0</font>].z = 0.0f;<br>		vertices[<font color=purple>0</font>].rhw = 1.0f;	<br>		vertices[<font color=purple>0</font>].u = ( bltFlag & BLIT_FLAG_MIRROR ) ? ( <font color=blue>float</font> )( rcSrc.right  ) / texWidth : ( <font color=blue>float</font> )( rcSrc.left ) / texWidth;<br>		vertices[<font color=purple>0</font>].v = ( bltFlag & BLIT_FLAG_FLIP   ) ? ( <font color=blue>float</font> )( rcSrc.bottom ) / texWidth : ( <font color=blue>float</font> )( rcSrc.top  ) / texWidth;<br><br>		vertices[<font color=purple>1</font>].colour = verticesColors[<font color=purple>1</font>];<br>		vertices[<font color=purple>1</font>].x = ( <font color=blue>float</font> ) rcDest.right;<br>		vertices[<font color=purple>1</font>].y = ( <font color=blue>float</font> ) rcDest.top;<br>		vertices[<font color=purple>1</font>].z = 0.0f;<br>		vertices[<font color=purple>1</font>].rhw = 1.0f;<br>		vertices[<font color=purple>1</font>].u = ( bltFlag & BLIT_FLAG_MIRROR ) ? ( <font color=blue>float</font> )( rcSrc.left   ) / texWidth : ( <font color=blue>float</font> )( rcSrc.right ) / texWidth;<br>		vertices[<font color=purple>1</font>].v = ( bltFlag & BLIT_FLAG_FLIP   ) ? ( <font color=blue>float</font> )( rcSrc.bottom ) / texWidth : ( <font color=blue>float</font> )( rcSrc.top   ) / texWidth;<br><br>		vertices[<font color=purple>2</font>].colour = verticesColors[<font color=purple>2</font>];<br>		vertices[<font color=purple>2</font>].x = ( <font color=blue>float</font> ) rcDest.right;<br>		vertices[<font color=purple>2</font>].y = ( <font color=blue>float</font> ) rcDest.bottom;<br>		vertices[<font color=purple>2</font>].z = 0.0f;<br>		vertices[<font color=purple>2</font>].rhw = 1.0f;<br>		vertices[<font color=purple>2</font>].u = ( bltFlag & BLIT_FLAG_MIRROR ) ? ( <font color=blue>float</font> )( rcSrc.left ) / texWidth : ( <font color=blue>float</font> )( rcSrc.right  ) / texWidth;<br>		vertices[<font color=purple>2</font>].v = ( bltFlag & BLIT_FLAG_FLIP   ) ? ( <font color=blue>float</font> )( rcSrc.top  ) / texWidth : ( <font color=blue>float</font> )( rcSrc.bottom ) / texWidth;<br><br>		vertices[<font color=purple>3</font>].colour = verticesColors[<font color=purple>3</font>];<br>		vertices[<font color=purple>3</font>].x = ( <font color=blue>float</font> ) rcDest.left;<br>		vertices[<font color=purple>3</font>].y = ( <font color=blue>float</font> ) rcDest.bottom;<br>		vertices[<font color=purple>3</font>].z = 0.0f;<br>		vertices[<font color=purple>3</font>].rhw = 1.0f;<br>		vertices[<font color=purple>3</font>].u = ( bltFlag & BLIT_FLAG_MIRROR ) ? ( <font color=blue>float</font> )( rcSrc.right ) / texWidth : ( <font color=blue>float</font> )( rcSrc.left   ) / texWidth;<br>		vertices[<font color=purple>3</font>].v = ( bltFlag & BLIT_FLAG_FLIP   ) ? ( <font color=blue>float</font> )( rcSrc.top   ) / texWidth : ( <font color=blue>float</font> )( rcSrc.bottom ) / texWidth;<br>	}<br>}<br><br></pre><!–ENDSCRIPT–>    
This has to do with the problem of pixel center not being well defined in Direct3D texturing. They were supposed to fix that in Direct3D 9, but it could be either that the spec is still broken, or that one of the vendors doesn''t follow it.

The typical work-around for bad texture pixel centers is to add 0.375/texture_width to all "u" texture coordinates, and 0.375/texture_height to all "v" texture coordinates.

Another possibility is that it''s the framebuffer pixel center which isn''t lining up, and you should add 0.375 to all your x and y coordinates.
enum Bool { True, False, FileNotFound };
yes that''s work perfecly thx

This topic is closed to new replies.

Advertisement