Jump to content
  • Advertisement
Sign in to follow this  
treeway

FVF Declaration Textures

This topic is 4334 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, im revisiting some basic stuff today to see if i can still do it and ive come across something weird. Im trying to make a textured cube using a vertex buffer and rendering it to the screen. Ive defined my Vertex structure and FVF as follows:

// In my game header
// Vertex structure
struct MYVERTEX
{
	float x,y,z;	//Position
	DWORD colour;	//Diffuse
	float u,v;		//Texcoord
	float nx,ny,nz;	// Normal
};	
//FVF
const static DWORD MYFVF = (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX0 | D3DFVF_NORMAL );




then creating a vertex buffer with the data in for a cube:
// In my game initialisation

	 float height = 100.0f;
	 float width = 100.0f;
	 float depth = 100.0f;
	 MYVERTEX data[]={

	    //FRONT
		{0,0,0,0xFFFFFFFF,0,0,0,0,1},{0,height,0,0xFFFFFFFF,0,1,0,0,1},{width,0,0,0xFFFFFFFF,1,0,0,0,1},
		{0,height,0,0xFFFFFFFF,0,1,0,0,1},{width,height,0,0xFFFFFFFF,1,1,0,0,1},{width,0,0,0xFFFFFFFF,1,0,0,0,1},

		//LEFT
		{width,height,0,0xFFFFFFFF,1,0,1,0,0},{width,0,depth,0xFFFFFFFF,1,0,1,0,0},{width,0,0,0xFFFFFFFF,0,0,1,0,0},
		{width,height,0,0xFFFFFFFF,1,0,1,0,0},{width,height,depth,0xFFFFFFFF,1,1,1,0,0},{width,0,depth,0xFFFFFFFF,1,0,1,0,0},

		//BACK
		{width,0,depth,0xFFFFFFFF,0,0,-1,0,0},{width,height,depth,0xFFFFFFFF,0,1,-1,0,0},{0,0,depth,0xFFFFFFFF,1,0,-1,0,0},
		{width,height,depth,0xFFFFFFFF,0,1,-1,0,0},{0,height,depth,0xFFFFFFFF,1,1,-1,0,0},{0,0,depth,0xFFFFFFFF,1,0,-1,0,0},

		//RIGHT
		{0,height,depth,0xFFFFFFFF,0,1,-1,0,0},{0,0,0,0xFFFFFFFF,1,0,-1,0,0},{0,0,depth,0xFFFFFFFF,0,0,-1,0,0},
		{0,height,depth,0xFFFFFFFF,0,1,-1,0,0},{0,height,0,0xFFFFFFFF,1,1,-1,0,0},{0,0,0,0xFFFFFFFF,1,0,-1,0,0},
		
		//TOP
		{0,height,0,0xFFFFFFFF,0,0,0,1,0},{0,height,depth,0xFFFFFFFF,0,1,0,1,0},{width,height,0,0xFFFFFFFF,1,0,0,1,0},
		{0,height,depth,0xFFFFFFFF,0,1,0,1,0},{width,height,depth,0xFFFFFFFF,1,1,0,1,0},{width,height,0,0xFFFFFFFF,1,0,0,1,0},
			
		//Bottom
		{width,0,0,0xFFFFFFFF,1,0,0,-1,0},{width,0,depth,0xFFFFFFFF,1,1,0,-1,0},{0,0,depth,0xFFFFFFFF,0,1,0,-1,0},
		{width,0,0,0xFFFFFFFF,1,0,0,-1,0},{0,0,depth,0xFFFFFFFF,0,1,0,-1,0},{0,0,0,0xFFFFFFFF,0,0,0,-1,0},
		 
	};

		int vert_count= sizeof(data)/sizeof(MYVERTEX);
		int byte_count= vert_count*sizeof(MYVERTEX);
		g_list_count = vert_count/3;

	
		if(FAILED(CreateVertexBuffer(base->D3dDevice,byte_count,D3DUSAGE_WRITEONLY,MYFVF,D3DPOOL_MANAGED,&vb)))
		{
			base->messageBox(base->hWnd,"Error Creating vertex buffer");
		}

		if(FAILED( vb->Lock(0, //Offset
				    0, //SizeToLock
			        &vb_vertices, //Vertices
			        0)))  //Flags))
		{
			base->messageBox(base->hWnd,"Error Locking vertex buffer");
		}

		memcpy(vb_vertices,data,byte_count);

		vb->Unlock();



finally, every frame im setting the FVF to my defined FVF, setting a material and a texture on the device and drawing out my cube:
// in my frame method
	    base->D3dDevice->SetTransform(D3DTS_WORLD,&matIdent);
		base->D3dDevice->SetMaterial(material);
		base->D3dDevice->SetTexture(0,tex->texture); // this is a loaded texture 
		
		base->D3dDevice->SetFVF(MYFVF);

		//Bind our Vertex Buffer
		SetStreamSource(base->D3dDevice,0,vb,sizeof(MYVERTEX));

		//Render from our Vertex Buffer
		base->D3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, //PrimitiveType
			0,                  //StartVertex
			g_list_count);      //PrimitiveCount

		


it all seems right to me and my cube is drawn, the only problem is that it is untextured and just appears red. My material is set to green and the texture is a recognisable bitmap, and the vertex diffuse colour is white. the Lighting render state is dissabled yet it seems not to be flat shading the object but performing the standard NdotL lighting on it (some faces are dark red, others light). is there any reason anyon can think of that my cube is coming out untextured? and why red? thanks

Share this post


Link to post
Share on other sites
Advertisement
A couple problems.

TEX0 means 0 texture coords. TEX1 means 1 texture coord. The number is a count, not a mask. ie: If you want 2 texture coords, use TEX2, not TEX0|TEX1.

The order of the data is fixed, and in a different order than what you're using. The order of the flags doesn't matter, as they're just numbers being ORed together. The order in the structure matters. The order, helpfully removed from recent SDKs, is here.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!