I currently have a jpeg texture stored as a Color array in XNA as RGBA. I also have the vertices of a cube in OBJ format mapped to VertexPositionColor vertex buffer using the VertexBuffer and Indices of the GraphicsDevice class. The OBJ has my jpeg mapped as a UV texture. I think I have all the Texture Coordinates as well(not sure, the array has 24 Vector3D values). I'm not sure where to go from here. I'm not using the Content Pipeline for my cube model or its texture though I'm wiling to add a custom .fx file if i need to. I realize I will have to add info about texture coords and color to my VertexDeclaration but do i need to write a custom effects file in HLSL to display my textured cube model or is there another way?

  • \$\begingroup\$ Your title is somewhat misleading. The source of your texture isn't relevant to drawing textured geometry. \$\endgroup\$ – Seth Battin May 11 '14 at 7:11

A custom shader is not required; you can accomplish this with BasicEffect. You will need to set the Textures and TexturesEnabled properties. Those properties will tell the shader:

  1. Expect and enforce texture coordinates in your vertex data
  2. Which texture data to sample.

This relevant article discusses drawing a textured quad with BasicEffect, and it's a short step from that to drawing a textured cube.

  • \$\begingroup\$ Thanks, I'll check it out. I notice the article defines Normals in its VertexDeclaration but doesn't seem to fill it in anywhere. Does this mean I can skip setting normal values? I may need them since I am working with 3d models but dont have them right now. \$\endgroup\$ – user1278255 May 11 '14 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.