Jump to content
  • Advertisement
Sign in to follow this  

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
	float x,y,z;	//Position
	DWORD colour;	//Diffuse
	float u,v;		//Texcoord
	float nx,ny,nz;	// 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[]={





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

			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");



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->SetTexture(0,tex->texture); // this is a loaded texture 

		//Bind our Vertex Buffer

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