2009-07-11 3 views
3

here에있는 예제를 사용하여 텍스쳐 쿼드를 렌더링하려고합니다.XNA를 사용하여 텍스쳐 화 된 쿼드 그리기

쿼드를 성공적으로 렌더링 할 수 있지만 텍스처 정보가 손실 된 것처럼 보입니다. 하지만 쿼드는 기본 텍스처의 색상을 사용합니다.

명백한 문제 ("쿼드를 렌더링하는 BasicEffect는 TextureEnabled 속성이 true로 설정되어 있습니까?")를 확인 했으므로 즉시 문제를 볼 수 없습니다. 아래

코드 :

public class Quad 
{ 
    public VertexPositionNormalTexture[] Vertices; 
    public Vector3 Origin; 
    public Vector3 Up; 
    public Vector3 Normal; 
    public Vector3 Left; 
    public Vector3 UpperLeft; 
    public Vector3 UpperRight; 
    public Vector3 LowerLeft; 
    public Vector3 LowerRight; 
    public int[] Indexes; 


    public Quad(Vector3 origin, Vector3 normal, Vector3 up, 
     float width, float height) 
    { 
     this.Vertices = new VertexPositionNormalTexture[4]; 
     this.Indexes = new int[6]; 
     this.Origin = origin; 
     this.Normal = normal; 
     this.Up = up; 

     // Calculate the quad corners 
     this.Left = Vector3.Cross(normal, this.Up); 
     Vector3 uppercenter = (this.Up * height/2) + origin; 
     this.UpperLeft = uppercenter + (this.Left * width/2); 
     this.UpperRight = uppercenter - (this.Left * width/2); 
     this.LowerLeft = this.UpperLeft - (this.Up * height); 
     this.LowerRight = this.UpperRight - (this.Up * height); 

     this.FillVertices(); 
    } 

    private void FillVertices() 
    { 
     Vector2 textureUpperLeft = new Vector2(0.0f, 0.0f); 
     Vector2 textureUpperRight = new Vector2(1.0f, 0.0f); 
     Vector2 textureLowerLeft = new Vector2(0.0f, 1.0f); 
     Vector2 textureLowerRight = new Vector2(1.0f, 1.0f); 

     for (int i = 0; i < this.Vertices.Length; i++) 
     { 
      this.Vertices[i].Normal = this.Normal; 
     } 

     this.Vertices[0].Position = this.LowerLeft; 
     this.Vertices[0].TextureCoordinate = textureLowerLeft; 
     this.Vertices[1].Position = this.UpperLeft; 
     this.Vertices[1].TextureCoordinate = textureUpperLeft; 
     this.Vertices[2].Position = this.LowerRight; 
     this.Vertices[2].TextureCoordinate = textureLowerRight; 
     this.Vertices[3].Position = this.UpperRight; 
     this.Vertices[3].TextureCoordinate = textureUpperRight; 

     this.Indexes[0] = 0; 
     this.Indexes[1] = 1; 
     this.Indexes[2] = 2; 
     this.Indexes[3] = 2; 
     this.Indexes[4] = 1; 
     this.Indexes[5] = 3; 
    } 
} 

this.quadEffect = new BasicEffect(this.GraphicsDevice, null); 
this.quadEffect.AmbientLightColor = new Vector3(0.8f, 0.8f, 0.8f); 
this.quadEffect.LightingEnabled = true; 
this.quadEffect.World = Matrix.Identity; 
this.quadEffect.View = this.View; 
this.quadEffect.Projection = this.Projection; 
this.quadEffect.TextureEnabled = true; 
this.quadEffect.Texture = someTexture; 

this.quad = new Quad(Vector3.Zero, Vector3.UnitZ, Vector3.Up, 2, 2); 

this.quadVertexDecl = new VertexDeclaration(this.GraphicsDevice, VertexPositionNormalTexture.VertexElements); 

내가 무엇을 볼 수에서
public override void Draw(GameTime gameTime) 
{ 
    this.GraphicsDevice.Textures[0] = this.SpriteDictionary["B1S1I800"]; 
    this.GraphicsDevice.VertexDeclaration = quadVertexDecl; 
    quadEffect.Begin(); 

    foreach (EffectPass pass in quadEffect.CurrentTechnique.Passes) 
    { 
     pass.Begin(); 
     GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(
      PrimitiveType.TriangleList, 
      beamQuad.Vertices, 0, 4, 
      beamQuad.Indexes, 0, 2); 

     pass.End(); 
    } 

    quadEffect.End(); 
} 

답변

1

이 작동합니다. 내가 상상할 수있는 유일한 것은이 코드에 없지만 텍스처의 로딩이 어딘가에서 잘못되었다는 것입니다. 쿼드가 텍스처의 기본 색상을 가지고 있음을 의미하는 것을 시각화 할 수도 없습니다. 우리를위한 스크린 샷이 있습니까?

또한 무언가가 나타나면 질감이 매우 왜곡되어 나타날 수 있습니다. 예를 들어 의 렌더링이 쿼드 렌더링에 영향을 미칠 수 있습니다. 예를 들어 그래픽 장치에 또 다른 정점 선언이있는 동안 쿼드를 그릴 경우 또는 이전에 렌더링 한 것이 이국적인 렌더링 상태를 설정했거나 다른 드로잉 코드 내에서 쿼드를 드로잉하는 경우입니다. 이 코드를 새 프로젝트 나 다른 것으로 분리하거나 다른 모든 렌더링을 사용하지 않도록 설정하십시오.

+0

이전의 일은 참으로 이국적인 렌더링 상태를 설정했습니다. 위의 코드는 다소 정확하지만, 렌더링 상태를 변경하는 SpriteBatch와 함께 BasicEffect를 사용하고 있음을 언급하지 않았습니다. 나는 SpriteBatch가 부작용이 없다고 잘못 가정했다. –

관련 문제