Search code examples
opengltextureslwjglprojection

OpenGL selection area


enter image description here

I'm currently using LWJGL but if you have a solution for OpenGL I can use that too.

Now, I'm trying to apply a selection area to a plane that I can move around with my mouse (like my terrible drawing above). I'm trying to make it flat to the plane, so it can move over any obstacles. I've considered projection texture but I dont know how to implement it. Is this a good way of solving the problem or is there any better alternative?

  1. What would be the best way to implement a selection area?
  2. Alternative options, pros and cons.

Edit: This will be moving over another texture if that makes a difference.


Solution

  • When you already know the intersection point in world space, there is a relative simple solution that doesn't require projected textures:

    In the fragment shader calculate the world-space distance between the intersection point and the current fragment. When the distance between the two is smaller than the desired radius of the circle, then the selection color should be drawn. Otherwise just the normal plane is drawn.

    float dist = length(current_ws - intersection_ws);
    
    if (dist < circle_radius)
        //Draw overlay
    else
        //Draw plane normal