Texture renders gray when rendering

I am currently working my way through β€œGetting Started in C #” and run into a problem in Chapter 7 when drawing textures.

I used the same code as on the demo CD, and although I had to change the texture path to be absolute, it appears gray when rendering.

I debugged the program for writing the loaded texture to the file, and this is normal - there are no problems. So something after this happens wrong.

Here are some code snippets:

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(); ... } 

I can not understand what is happening here. Obviously, if I load the texture into the windows, it displays normally - so there is something wrong with the code examples in the book. This really doesn't work, and there must be something wrong with my environment presumably.

+4
source share
1 answer

You are using TRUSTED old technology ... I assume that you are trying to create a game (as we all did when we started!), Try using XNA. My best guess is your graphics driver. I know this sounds like a cop, but seriously, I saw it before, and once I changed my old graphics card to a new one, it will work! I am not saying that it is broken, or that it is impossible to make it work. But my top two sentences would be as follows:

1) Start using XNA and use the tutorials http://www.xnadevelopment.com/tutorials.shtml 2) Replace your graphics card (if you want to continue what you are doing now).

+1
source

Source: https://habr.com/ru/post/1413302/


All Articles