XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

Shader to draw a simple texture

Last post 04-20-2008 6:39 AM by ArenAzul. 5 replies.
  • 04-19-2008 3:10 PM

    Shader to draw a simple texture

    Could anybody write me or reference me to a site where i can find the code for a shader to draw a texture with it's natural size in pixels and without any distortion just giving the shader the coordinates of one of its corners or the middle point or whatever. Is that posible to achieve that or there's always a mesh needed to draw something?

    I've seen some shader codes (for particle systems i guess) that are able to draw a texture (scaled) on each and every point of a cloud of points, but i haven't been able to do what i ask for.

    Thanks for any help ^^

  • 04-19-2008 3:46 PM In reply to

    Re: Shader to draw a simple texture

    See SpriteBatch

    You always need a mesh. Graphics cards draw triangles that happen to have textures mapped to them. For 2d pixel graphics APIs like spritebatch build quads out of 2 triangles and map the correct textures. You don't need to write the shader or the mesh code becuase MS has done a great job for you. This is why you don't find (m)any samples to do this.

     



    The ZBuffer News and information for XNA

    Please read the forum FAQs - Bug reporting
  • 04-19-2008 4:40 PM In reply to

    Re: Shader to draw a simple texture

    Well... I'm not using XNA, that's why i ask ^^
  • 04-19-2008 4:42 PM In reply to

    Re: Shader to draw a simple texture

    ArenAzul:
    Well... I'm not using XNA, that's why i ask ^^


    What are you using? You posted this in the XNA Framework forum. If you were looking for DirectX, there is a C++ forum for it. In DirectX I believe people use the ID3DXSprite for 2D rendering of textures.
  • 04-19-2008 5:04 PM In reply to

    Re: Shader to draw a simple texture

    Answer

    [moved thread to native forums]

    If the native sprite interface is not enough for you then you still don't need a shader. You can just build quads at runtime and apply the textures but you need to read this article. http://msdn2.microsoft.com/en-us/library/bb219690.aspx

    You can use point sprites which is where you pass in a position and the quad is expanded inside the graphics card but they are limited in functionality so it depends on your usage. See this document http://msdn2.microsoft.com/en-us/library/bb147281(VS.85).aspx

     



    The ZBuffer News and information for XNA

    Please read the forum FAQs - Bug reporting
  • 04-20-2008 6:39 AM In reply to

    Re: Shader to draw a simple texture

    Thank you very much, that was exactly what i needed ^^.

    As final thing... which option is faster?

    1. Using a quad mesh from file (2 triangles) and drawing with normal shader.

    2. Using a triangle fan buffer and drawing with normal shader.

    3. Point sprites.

Page 1 of 1 (6 items) Previous Next