Results 1 to 3 of 3

Thread: Shader Help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Peasant
    Join Date
    Sep 2008
    Posts
    5

    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.
    http://www.clockworkcoders.com/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.

    Code:
    // vertex.glsl:
    
    void main(void)
    {
     gl_TexCoord[0] = gl_MultiTexCoord0;
     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; 
    }
    Code:
    // fragment.glsl:
    
    uniform sampler2D myTexture;
    
    void main (void)
    {
      gl_FragColor  = texture2D(myTexture, vec2(gl_TexCoord[0]));         
    }
    Code:
    //...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_program->attach(*m_vertex);
       m_program->attach(*m_fragment);
       m_program->link();
    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)

    Code:
          m_program->set_uniform("myTexture",0);
          m_program->use();
    
          m_bottomSprite->draw(x, y, context);
          m_topSprite->draw(x, y, context);
    
          m_program->disable();
    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.

Bookmarks

Bookmarks

Posting Permissions

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