0

I'm trying to use a pixel shader to display an image. I've searched around for information on how to do this, and I found this:

https://msdn.microsoft.com/en-us/library/windows/desktop/bb219690%28v=vs.85%29.aspx

Here is the hlsl script from there:

texture MyTexture;

sampler MySampler = 
sampler_state 
{ 
    Texture = <MyTexture>;
    MinFilter = Linear;
    MagFilter = Linear;
    AddressU = Clamp;
    AddressV = Clamp;
};

float4 TextureLookupPS( float2 vTexCoord : TEXCOORD0 ) : COLOR
{
    return tex2D( MySampler, vTexCoord );
} 

For the main function, I guess I do this:

PS_OUTPUT psmain(in VS_OUTPUT In)
{
    PS_OUTPUT Out;
    Out.Color = tex2D(mySample, In.texture);

    return Out;
};

In C++, how do I pass in the value of MyTexture? Do I load an IDirect3DTexture9* with D3DXCreateTextureFromFile? How do I get that information to the pixel shader?

NickLokarno
  • 300
  • 6
  • 20
  • 1
    Why are you using Direct3D9 (an API that is at this point 13+ years old)? If you were using DirectX 11, you can use ``SpriteBatch`` in the [DirectX Tool Kit](http://go.microsoft.com/fwlink/?LinkId=248929) – Chuck Walbourn Mar 07 '15 at 02:43
  • Because the software my company has licenses for uses Direct3D9. We don't have access to the source code itself, we can only write plugins for it. – NickLokarno Mar 08 '15 at 03:56

1 Answers1

1

I know this question is 2 months old but I'll just leave this here for reference:

Once you have created your ID3DXEffect :

D3DXHANDLE texHandle = m_pShader->GetParameterByName(0, "MyTexture")

That will give you a handle to your shader texture so you can set it inside the render function:

m_pEffect->SetTexture(texHandle, m_pTexture);

m_pEffect is your ID3DXEffect pointer.

Note: m_pTexture is a LPDIRECT3DTEXTURE9 object that you can initialize like this for example:

D3DXCreateTextureFromFileA(m_pDevice, "mytexture.bmp", &m_pTexture)

I based my answer on this one by user zdd: https://stackoverflow.com/a/18754193/2240519

Community
  • 1
  • 1
Nevak
  • 11
  • 2
  • Nice that you reference the post you borrowed from, try to also include the author's name. It's the only thing that keeps me from upvoting at the moment. – ShellFish May 29 '15 at 20:03
  • Sure thing I just added it. I'm not 100% confident with "best practices" to answer questions yet so I'll keep this one in mind for the future. – Nevak May 30 '15 at 11:36
  • You grow into that, check out the formatting page for quotes, tags, links and whatnot. One your post becomes large you can also use titles in bold. The more you read the more cool markup you can borrow from other answers! – ShellFish May 30 '15 at 12:02