Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

evilgenius

texture problem

This topic is 5475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i wonder if it''s possible to render a texture using the following FVF #define D3DFVF_CUSTOMVERTEX(D3DFVF_XYZRHW|D3DFVF_SPECULAR|D3DFVF_DIFFUSE|D3DFVF_TEX1) rendering works fine for D3DFVF_XYZ but using D3DFVF_XYZRHW it doesn''t work at all. am i missing something? any help would be welcome

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
sure it''s possible. did you add an additional float into your vertex struct to account for the new w component? if so, did you make sure to set each vert''s w component value to something meaningful?

Share this post


Link to post
Share on other sites
Remember that use of D3DFVF_XYZRHW is basically telling D3D that your vertices have already been transformed. That means that they are in screen space. Your w component will usually be 1.0f

neneboricua

Share this post


Link to post
Share on other sites
here ist the code i use:
//the customvertex struct
struct CUSTOMVERTEX
{
D3DXVECTOR3 position; // vertex position
float rhw;
D3DXVECTOR3 color; // vertex color
float tu,tv;
};

#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1)

//vertex setup
float x=512.0f, y=512.0f;

CUSTOMVERTEX vertices[4];
vertices[0].position=D3DXVECTOR3(-x, y, 0.0f);
vertices[0].rhw=1.0f;
vertices[0].color=D3DXVECTOR3(255.0, 255.0, 255.0);
vertices[0].tu=0.0f;
vertices[0].tv=0.0f;

vertices[1].position=D3DXVECTOR3(x, y, 0.0f);
vertices[1].rhw=1.0f;
vertices[1].color=D3DXVECTOR3(255.0, 255.0, 255.0);
vertices[1].tu=1.0f;
vertices[1].tv=0.0f;

vertices[2].position=D3DXVECTOR3(-x, -y, 0.0f);
vertices[2].rhw=1.0f;
vertices[2].color=D3DXVECTOR3(255.0, 255.0, 255.0);
vertices[2].tu=0.0f;
vertices[2].tv=1.0f;

vertices[3].position=D3DXVECTOR3(x, -y, 0.0f);
vertices[3].rhw=1.0f;
vertices[3].color=D3DXVECTOR3(255.0, 255.0, 255.0);
vertices[3].tu=1.0f;
vertices[3].tv=1.0f;

//loading and setting the texture
if( FAILED( D3DXCreateTextureFromFile(g_pd3dDevice, "wallpaper.bmp",&g_pTexture)))
{
return E_FAIL;
}
g_pd3dDevice->SetTexture(0,g_pTexture);

------------------
and the renderstates
------------------
g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE); // Lighting off.
g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);// Culling off.

g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_PASSTHRU );


// Set miscellaneous render states
g_pd3dDevice->SetRenderState( D3DRS_DITHERENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_SPECULARENABLE, FALSE );
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x000F0F0F );



i cant figure out why there isn't any texture on my rect.
please help!

[edited by - evilgenius on September 24, 2003 8:58:24 AM]

Share this post


Link to post
Share on other sites
I think the colour is wrong. I''m pretty sure you can''t use a vector like that. It should be a DWORD or one of D3DX''s own ones, which is basically the same. I have the same vertex structure in my own program I am currently working on and it works fine. Just correct the colour and you should be fine.

Share this post


Link to post
Share on other sites
i changed the color using a DWORD now, but still it doesn''t render anything.
BTW: AFAIK is the D3DXCOLOR struct quite similar to the D3DXVECTOR3 i used. its only 4 floats not 3, but this shouldn''t be a prob, because acc. to microsoft the alpha will be set to 1 by default.

Share this post


Link to post
Share on other sites
D3DFVF_DIFFUSE or whatever color component you specify expect a DWORD as higherspeed mentioned.

Well, D3D's equivalent for DWORD is D3DCOLOR(when specifying colors) and you have several macros to specify color components such as D3DCOLOR_XRGB, D3DCOLOR_ARGB, D3DCOLOR_RGBA ...



[edited by - UdayK on September 24, 2003 9:55:01 AM]

Share this post


Link to post
Share on other sites
I think the reason nothing shows up is that the range for your vertices is too large. Your vertices seem to be in the range of [-512..512] on both x and y axis. The problem is that D3DFVF_XYZRHW uses screen space coordinates (i.e. [0..screenWidth] and [0..screenHeight]).

The second tutorial from the SDK has an example of rendering a colored screen spaced triangle. Take a look at it if you need to refresh your memory.

neneboricua

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!