纹理没有出现

时间:2012-05-19 15:38:40

标签: c# directx textures

enter image description here早些时候发布这个,有一个人回复了任何建议,所以我会再发帖一次。我意识到这是我们在这里徘徊的旧技术,但仍然 - 我被卡住了。所以任何想法 - 任何事情 - 都会受到赞赏。

我目前正在通过“开始C#编程”工作,并且在绘制纹理时在第7章遇到了问题。

我使用了与演示CD上相同的代码,虽然我不得不将纹理的路径更改为绝对路径,但渲染时它显示为灰色。

我已经调试了程序来写入加载纹理的文件,这很好 - 没有问题。所以在那之后发生了一些错误。

以下是一些代码片段:

public void InitializeGraphics()
{
    // set up the parameters
    Direct3D.PresentParameters p = new Direct3D.PresentParameters();
    p.SwapEffect = Direct3D.SwapEffect.Discard;
    ...
    graphics = new Direct3D.Device( 0, Direct3D.DeviceType.Hardware, this,
    Direct3D.CreateFlags.SoftwareVertexProcessing, p );
    ...
    // set up various drawing options
    graphics.RenderState.CullMode = Direct3D.Cull.None;
    graphics.RenderState.AlphaBlendEnable = true;
    graphics.RenderState.AlphaBlendOperation = Direct3D.BlendOperation.Add;
    graphics.RenderState.DestinationBlend = Direct3D.Blend.InvSourceAlpha;
    graphics.RenderState.SourceBlend = Direct3D.Blend.SourceAlpha;
    ...
}

public void InitializeGeometry()
{
    ...
    texture = Direct3D.TextureLoader.FromFile( 
            graphics, "E:\\Programming\\SharpDevelop_Projects\\AdvancedFrameworkv2\\texture.jpg", 0, 0, 0, 0, Direct3D.Format.Unknown,
            Direct3D.Pool.Managed, Direct3D.Filter.Linear, 
            Direct3D.Filter.Linear, 0 );
...
}

protected virtual void Render()
{
    graphics.Clear( Direct3D.ClearFlags.Target, Color.White , 1.0f, 0 );
    graphics.BeginScene();

    // set the texture
    graphics.SetTexture( 0, texture );

    // set the vertex format
    graphics.VertexFormat = Direct3D.CustomVertex.TransformedTextured.Format;

    // draw the triangles
    graphics.DrawUserPrimitives( Direct3D.PrimitiveType.TriangleStrip, 2, vertexes );

    graphics.EndScene();
    graphics.Present();
    ...
}

我无法弄清楚这里出了什么问题。显然,如果我在Windows中加载纹理它显示正常 - 所以在书中给出的代码示例中有一些不正确的东西。它实际上并不起作用,并且我的环境肯定会出现问题。

0 个答案:

没有答案