Results 1 to 2 of 2

Thread: Hiding a part of the component with a shader.

  1. #1
    Member Contributor
    Join Date
    Oct 2015
    Posts
    60

    Hiding a part of the component with a shader.

    Hi!
    I would like to hide the part of the component which is outside its parent by it doesn't work.
    Here is my fragment shader code :
    Code :
    "#version 130 \n"
                    "uniform vec2 winSize;"
                    "uniform vec2 componentSize;"
                    "uniform vec2 componentPos;"
                    "void main() {"
                    "   vec4 colors[2];"
                    "   colors[0] = vec4(0, 0, 0, 0);"
                    "   colors[1] = gl_Color;"
                    "   bool b = gl_FragCoord.x >= componentPos.x"
                                "&& winSize.y - gl_FragCoord.y >= winSize.y - componentPos.y"
                                "&& gl_FragCoord.x <= componentPos.x + componentSize.x"
                                "&& winSize.y - gl_FragCoord.y <= winSize.y - (componentPos.y + componentSize.y);"
                    "   gl_FragColor = colors[int(b)];"
                    "}"

    The pixels outside the parent component are still visible.
    Code cpp:
    shadScissor->setParameter("winSize",getWindow().getSize().x, getWindow().getSize().y);
                    shadScissor->setParameter("componentPos", getPosition().x, getPosition().y);
                    shadScissor->setParameter("componentSize",getSize().x,getSize().y);
                    states.shader = shadScissor.get();
                    onDraw(target, states);
                    std::multimap<int, LightComponent*, std::greater<int>> sortedChildren;
                    for (unsigned int i = 0; i < children.size(); i++) {
                        sortedChildren.insert(std::make_pair(children[i]->getPriority(), children[i].get()));
                    }
                    std::multimap<int, LightComponent*, std::greater<int>>::iterator it;
                    for (it = sortedChildren.begin(); it != sortedChildren.end(); it++) {
                        if (it->second->isVisible()
                            && it->second->getPosition().x + it->second->getSize().x >= getPosition().x
                            && it->second->getPosition().y + it->second->getSize().y >= getPosition().y
                            && it->second->getPosition().x <= getPosition().x + getSize().x
                            && it->second->getPosition().y <= getPosition().y + getSize().y) {
                            it->second->draw(target, states);
                        }
                    }
                    drawOn(target, states);

  2. #2
    Member Contributor
    Join Date
    Oct 2015
    Posts
    60
    It's ok I used glScissor instead!

Similar Threads

  1. Replies: 1
    Last Post: 08-18-2008, 02:37 PM
  2. hiding surface behind
    By jyoung77 in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 03-21-2002, 12:45 PM
  3. 3D image hiding
    By Reaper4774 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 10-23-2001, 10:25 AM
  4. Custom projection matrix: part ortho, part frustum
    By joelsk in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 11-30-2000, 07:01 AM
  5. Replies: 1
    Last Post: 12-31-1969, 07:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean