Sign in to follow this  

DX8 vertex problem, help!!

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

Im just expiermenting with a textured square, but the result is just a jaggedy square, but alot more jaggedy than square-like. (How the heck do you put images up here...) heres the relevent code : SetupVertexBuffer()
void cGraphics::SetupVertexBuffer()
{
	unsigned char *verts = 0;

	myVertex triangle[] = 
	{
		{ 50.0f, 200.0f, 0.5f, 1.0f, 0xFFFFFF00 },
	    { 50.0f,  50.0f, 0.5f, 1.0f, 0x00FFFFFF }, // x, y, z, rhw, color
		{ 200.0f, 50.0f, 0.5f, 1.0f, 0x00FF0000 },
		{ 200.0f, 200.0f, 0.5f, 1.0f, 0xFF0000FF }
		
	};

	pD3DDevice->CreateVertexBuffer(4*sizeof(triangle),
		                           D3DUSAGE_WRITEONLY,
								   D3DFVF_XYZRHW|D3DFVF_DIFFUSE,
								   D3DPOOL_MANAGED,
								   &pTriangle);

	pTriangle->Lock(0, //offset, 0 means start at the beginning
		            0, //size, 0 means whole thing
					&verts, //points to the data in the buffer (if call is successful)
					0); //flags

	memcpy(verts, triangle, sizeof(triangle));

	pTriangle->Unlock();	


}



CreateTextures() (I believe the problem is here, but where....?)
void cGraphics::CreateTextures()
{
	ghr = D3DXCreateTextureFromFileEx(pD3DDevice,
									"playership.bmp",
									D3DX_DEFAULT, //width = default, from image
									D3DX_DEFAULT, //height too
									1, //mip lvls
									0, //usage
									D3DFMT_X8R8G8B8, //format D3DFMT_X8R8G8B8  D3DFMT_A8R8G8B8
									D3DPOOL_MANAGED, //let D3D manage the memory
									D3DX_DEFAULT, //filter, default filtering
									D3DX_DEFAULT, //mip filter
									0xFF000000, //colorkey
									NULL, //sourceinfo
									NULL, //pallette
									&pTexture); //output, out texture

	if(FAILED(ghr)) Errors(ghr, "D3DXCreateTextureFromFileEx() in cGraphics::CreateTexture() failed!");

}



and finally, maybe its in the DrawScene()
void cGraphics::DrawScene()
{
	frames++;
	
	if(pD3DDevice == NULL){MessageBox(NULL, "cGraphics::Start() - pD3DDevice == NULL", NULL, NULL); PostQuitMessage(0);}
	

    //ghr = pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);//if using a z buffer
		//if(FAILED(ghr)) Errors(ghr, "pD3DDevice->Clear() in cGraphics::DrawScene() failed!");

	ghr = pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
		if(FAILED(ghr)) Errors(ghr, "pD3DDevice->Clear() in cGraphics::DrawScene() failed!");

	ghr = pD3DDevice->BeginScene();	
		if(FAILED(ghr)) Errors(ghr, "pD3DDevice->BeginScene() in cGraphics::DrawScene() failed!");

	ghr = pD3DDevice->SetVertexShader(D3DFVF_XYZRHW|D3DFVF_DIFFUSE);
		if(FAILED(ghr)) Errors(ghr, "pD3DDevice->SetVertexShader() in cGraphics::DrawScene() failed!");

    ghr = pD3DDevice->SetStreamSource(0,pTriangle,sizeof(myVertex));
		if(FAILED(ghr)) Errors(ghr, " pD3DDevice->SetStreamSource() in cGraphics::DrawScene() failed!");

    ghr = pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		if(FAILED(ghr)) Errors(ghr, "pD3DDevice->DrawPrimitive() in cGraphics::DrawScene() failed!");

	if(ShowFrameStats) {ShowFPS();}
	if(ShowMouseStats){ShowMouse();}

	pD3DDevice->EndScene();
	pD3DDevice->Present(NULL, NULL, NULL, NULL);
}




thx in advance, -Jason O, and yes, the playership.bmp is in the correct folder.

Share this post


Link to post
Share on other sites
Quote:
4*sizeof(triangle)

It should be 4*sizeof(myVertex). The texture has nothing to do with it, you didn't apply it and your FVF doesn't even have UV coords.

Share this post


Link to post
Share on other sites
as scet said: you don't have any texture coordinates on your quad. the myVert struxt is probably like this?


struct myVert
{
float x, y, z, w;
DWORD color;
};


You want to add texture coordinates to that so that d3d knows where to paste the texture on. Texture coordinates are usually 2D


struct myVert
{
float x, y, z, w;
DWORD color;
float tu, tv;
};


Then you want to change your FVF to include texture coordinates:

myFVF = D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1

Then you want to add the texture coordinate values in your vertex data:


myVertex triangle[] =
{
{ 50.0f, 200.0f, 0.5f, 1.0f, 0xFFFFFF00, 0, 0 },
{ 50.0f, 50.0f, 0.5f, 1.0f, 0x00FFFFFF, 1, 0 },
{ 200.0f, 50.0f, 0.5f, 1.0f, 0x00FF0000, 0, 1 },
{ 200.0f, 200.0f, 0.5f, 1.0f, 0xFF0000FF, 1, 1 },

};


and then also before you draw with DrawPrimitive, you want to set the texture:

pD3DDevice->SetTexture(0, pTexture);

Share this post


Link to post
Share on other sites

This topic is 4872 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this