Jump to content
  • Advertisement
Sign in to follow this  
DeviceLost

[Textured Quads]sorry but i just dont get it

This topic is 4897 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

hi gamedev community! relating on the articles on gamedev.net and some other sources i tried to render a bitmap on the screen using textured quads. it seems that the image is loaded successfully but the screen output is a totally wrong image! due to lack of webspace here s a short description of the problem: IMAGE: BB****PP ******** ******** YY****GG B = blue P = purple Y = yellow G = green * = red OUTPUT: BB****YY BB****YY BB****YY BB****YY so its kinda twisted and streched. and i really dont know why! i ve been changing the valuesof the texture and vertex coordinates for days! so you are my last hope! here is teh code: setting up the device and the image

D3DDISPLAYMODE X_mode;

		X_d3d9->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&X_mode);



		ZeroMemory(&X_presParams, sizeof(X_presParams));

		X_presParams.BackBufferWidth = n_screenWidth;
		X_presParams.BackBufferHeight = n_screenHeight;
		X_presParams.BackBufferFormat =X_devFormat;// X_mode.Format;
		X_presParams.BackBufferCount = 1;
		X_presParams.MultiSampleType = D3DMULTISAMPLE_NONE;
		X_presParams.MultiSampleQuality = 0;
		X_presParams.SwapEffect = D3DSWAPEFFECT_FLIP;
		X_presParams.hDeviceWindow = W_window;
		X_presParams.Windowed = false;
		X_presParams.EnableAutoDepthStencil = true;
		X_presParams.AutoDepthStencilFormat = D3DFMT_D16;//X_devFormat;
		X_presParams.FullScreen_RefreshRateInHz = X_mode.RefreshRate;// D3DPRESENT_RATE_DEFAULT;
		X_presParams.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
		
		if(X_devCaps.PresentationIntervals & D3DPRESENT_INTERVAL_IMMEDIATE)
		X_presParams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

		if(X_devCaps.PresentationIntervals & D3DPRESENT_INTERVAL_ONE)
		X_presParams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;


		if(X_devCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
		{
		W_rval = X_d3d9->CreateDevice(D3DADAPTER_DEFAULT,X_devType,W_window, D3DCREATE_HARDWARE_VERTEXPROCESSING, &X_presParams, &X_d3dDevice);

		if(W_rval == D3D_OK)
		{
		X_d3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &X_backBufferSurface);
		
		


		X_d3dDevice->SetRenderState(D3DRS_LIGHTING,false);
		X_d3dDevice->SetVertexShader(NULL);
		X_d3dDevice->SetFVF(D3DFVF_XYZRHW| D3DFVF_TEX1);


		}//D3D_OK


W_rval =X_d3dDevice->CreateVertexBuffer(sizeof(XXX_VERTEX) * 4, D3DUSAGE_WRITEONLY,D3DFVF_XYZRHW | D3DFVF_TEX1,D3DPOOL_DEFAULT,&X_vertexBuffer,NULL);

  if(W_rval != D3D_OK){...}


if(FAILED(D3DXCreateTextureFromFileEx(X_d3dDevice,"test.bmp",0,0,1,0,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_FILTER_NONE,D3DX_DEFAULT,NULL,NULL,&X_textur)))
 {
 MessageBox(NULL,"Error","CreateTextureFromFileEx()",0);
 return ERROR;
 }






Drawing
D3DXIMAGE_INFO X_info;

 
 D3DXGetImageInfoFromFile("test.bmp",&X_info);

 
 XXX_VERTEX V[4];
 XXX_VERTEX* ver = NULL;

X_vertexBuffer->Lock(0,sizeof(XXX_VERTEX)*4,(void**)&ver,NULL);

 

 V[0].rhw= 1.0f;
 V[0].x = 10 -0.5f;
 V[0].y = 10-0.5f;
 V[0].X_color = D3DCOLOR_XRGB(255,255,255);
 V[0].z = 0.0f;
 V[0].u = 0.0f;
 V[0].v = 0.0f;

V[1].rhw = 1.0f;
 V[1].x = 10 + X_info.Width-0.5f;
 V[1].y = 10-0.5f;
 V[1].X_color = V[0].X_color;
 V[1].z = 0.0f;
 V[1].u = 1.0f;
 V[1].v = 0.0f;

 V[2].rhw = 1.0f;
 V[2].x = 10 + X_info.Width-0.5f;
 V[2].y = 10 + X_info.Height-0.5f;
 V[2].X_color = V[0].X_color;
 V[2].z = 0.0f;
 V[2].u = 1.0f;
 V[2].v = 1.0f;

 V[3].rhw = 1.0f;
 V[3].x = 10-0.5f;
 V[3].y = 10 + X_info.Height-0.5f;
 V[3].X_color = V[0].X_color;
 V[3].z = 0.0f;
 V[3].u = 0.0f;
 V[3].v = 1.0f;

 
 memcpy(ver,V,sizeof(XXX_VERTEX)*4);

 X_vertexBuffer->Unlock();

 X_d3dDevice->SetRenderState(D3DRS_AMBIENT,D3DCOLOR_XRGB(255,255,255));
 X_d3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
 X_d3dDevice->SetRenderState(D3DRS_LIGHTING, false);
 X_d3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE  ,true);
 X_d3dDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
 X_d3dDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA);
 X_d3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
// X_d3dDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_MODULATE);


 X_d3dDevice->SetStreamSource(0,X_vertexBuffer,0,sizeof(XXX_VERTEX));
 X_d3dDevice->SetFVF(D3DFVF_XYZRHW|D3DFVF_TEX1);

 X_d3dDevice->SetTexture(0,X_textur);
 X_d3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,0,2);

 return OK;


i hope that you can help me otherwise i have to set my computer on fire! ;) thx alot! DeviceLost

Share this post


Link to post
Share on other sites
Advertisement
See what happens if in the call to D3DXCreateTextureFromFileEx you replace D3DFMT_A8R8G8B8 with D3DFMT_X8R8G8B8 since bmp files don't store an alpha channel.

Share this post


Link to post
Share on other sites
Quote:
Original post by AndyGeers
See what happens if in the call to D3DXCreateTextureFromFileEx you replace D3DFMT_A8R8G8B8 with D3DFMT_X8R8G8B8 since bmp files don't store an alpha channel.


hey! thx for your reply.
i testet it with X8R8G8B8 but its still the same output. maybe the texture coordinates are wrong? but i cant imagine why / which. i ll try to rewrite the whole thing in a new empty project! grrrrr...or maybe some genius helps me outta this!


greets

deviceLost

Share this post


Link to post
Share on other sites
Your FVF is incomplete. Your vertex structure includes the vertex color but your FVF definition does not include it.

Share this post


Link to post
Share on other sites
Ah, well that's your problem then:

in place of "D3DFVF_XYZRHW | D3DFVF_TEX1" at every point where it occurs, you need "D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1"

or take the X_color out of XXX_VERTEX

Share this post


Link to post
Share on other sites
AndyGeers,













I LOVE YOU!

i cut out the color component of the XXX_VERTEX and..w00t w00t it worxx!
i tried to remove D3DFVF_DIFFUSE before but then the screen stayed just black, nothing was shown. but so far..big thx!! you saved my day!


greets deviceLost

Share this post


Link to post
Share on other sites
I have a simple question on your coding technique (not D3D, because I know almost nohting about it yet):
You two vertex buffers, like this:
XXX_VERTEX V[4];
XXX_VERTEX *ver;

X_vertexBuffer->Lock(0,sizeof(XXX_VERTEX)*4,(void**)&ver,NULL);
//This is the part I am questioning...
V[0]=...
V[1]=...
V[2]=...
V[3]=...
memcpy(ver,&V,sizeof(XXX_VERTEX)*4);

Instead of using this method, with two buffers, and copying memory, why don't you simply eliminate the middle man?
XXX_VERTEX *V=new XXX_VERTEX[4]; //Dynamic memory allocation
V[0]=...
V[1]=...
V[2]=...
V[3]=...
X_vertexBuffer->Lock(0,sizeof(XXX_VERTEX)*4,(void**)&V,NULL);


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!