'Drawing a 3D cuboid and rotating it in OpenGL

I am trying to draw a 3D cuboid by clicking on one of the corner points and then extending it based on the dimensions provided by the user, and then rotating it about any axis. However, I am not sure about how I can specify the (x, y, z) tuple after the mouse-click, since the output window is on 2D. Also, I cannot understand how to extend the point to form a cuboid.



Solution 1:[1]

What you want is called 3D Picking. Usually, this is done using Raycasting.

However, there is an easy solution (with acceptable performance) that involves rendering the scene off-screen on a framebuffer with 32-bit floats for the R/G/B values.

In the shader you use the x, y and z coordinates of that pixel as the color values.

Then, when the user clicks somewhere, you simply read out that pixels color to get its position.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 anton-tchekov