Results 1 to 3 of 3

Thread: Shader Help

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2008

    Default Shader Help

    Hey guys,
    I've been plugging away with clanlib 8.1 shaders and am having some difficulties. First of all, if there is any support examples for this version (found a 9.0 one) I'd for sure check them out. Google hasn't really offered any...

    I've written a number of HLSL shaders in the past, but am far from an expert and this is my first attempt at GLSL, so I've been using this site, which provides a good basic run down on OGLSL.

    Anyway, I am able to get a few of the very basic examples working, but am not able to use a basic texture applying shader with CL_Sprites... do they even play nicely together? Should I give up and use some sort of quad and lose all the sprite and resource support of clanlib? I'm hoping I am just doing something wrong.

    My code base is quite extensive, so I've had to cut snippets out. Please be assured that my shaders are compiling correctly, running, and the sprites are rendering correctly when I don't try to apply my shader.

    // vertex.glsl:
    void main(void)
     gl_TexCoord[0] = gl_MultiTexCoord0;
     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 
    // fragment.glsl:
    uniform sampler2D myTexture;
    void main (void)
      gl_FragColor  = texture2D(myTexture, vec2(gl_TexCoord[0]));         
    //...shader loading
      m_shaderResources = CL_ResourceManager("../shaders.xml");
       m_vertex = new CL_ShaderObject("vertexShader", &m_shaderResources);
       m_fragment = new CL_ShaderObject("fragmentShader", &m_shaderResources);
       m_program = new CL_ProgramObject();
    m_bottomSprite and m_topSprite are two sprites with some alphas which stack atop of each other... (again, they work correctly when I take out the m_program stuff)

          m_bottomSprite->draw(x, y, context);
          m_topSprite->draw(x, y, context);
    I run this last code block one time for the each of my in game actors. The end result is showing these sprites as solid color which I think is a pixel of the actual texture.

    Thanks for your assistance.
    Last edited by jerkald; 09-07-2008 at 02:46 AM.

  2. #2
    ClanLib Developer
    Join Date
    Sep 2006
    Bergen, Norway


    I'm afraid 0.8 was never designed to use shaders in the provided ClanLib functionality. If it works, good for you, if not, we have no idea why

    In 0.9 branch we're pretty much basing the entire display on the new programmable pipeline, and you'll see a much better integration. We haven't worked on the sprite part much in 0.9 yet, but we will provide some basic shader functionality they will use by default (instead of using the fixed pipeline).

    A tip - there exists converter utilities out there between GLSL and HLSL if you need some help how to convert your old stuff I used one previously and it really worked well.

  3. #3
    Join Date
    Sep 2008


    Thanks for the reply, I was beginning to think that there was no one able to suggest anything.

    It won't be a huge deal to switch over to 9, so I'll go ahead and try that. If the shader support isn't implemented for sprites though.. i'm basically in the same boat. I suppose if I have to, i'll have to write a basic sprite class that the works with shaders.

    Yes I did get a few simple shaders working, or at least they appeared to be working.

    I hadn't even thought about a converter, so thanks for the tip.. i'll look into that as well.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts