When I started the program written, I have some corners in a window. The viewport is set to take the whole window . On mouse click, the distance of each corner is calculated from the position of the mouse. If any of them is within a certain threshold (let's say 5 units), the top is selected. This part is not a problem.
After changing a window size, however, I restrict the viewport of the new window to maintain the aspect ratio. It also works.
However, after resizing, clicking on vertical creates strangely behavior, as the mouse does not seem to align the position, the world now coordinates. How can I convert the position of the mouse to the coordinate system of the world, which is stored X / Y values of these verticals?
I have asked this question before, but in a 3D context It seems that ok to use gluUnproject I'm not sure that it applies to 2D programs. Any help would be appreciated!
The code in my resize function is:
// resize function; Aspect Ratio is used to resize zero (int w, int h) {screenHeight = h; Screenview = w; Integer width, height; // long if ((float) (w / h) & lt; r) {width = w; Height = w / r; } // more comprehensive {width = h * r; Height = h; WidthBound = width; Altitude = height; GlViewport (0, 0, width, height); } // Size size
I have tried to reset the projection matrix inside the code:
glMatrixMode (GL_PROJECTION); GlLoadIdentity (); GluOrtho2D (left, right, bottom, up);
Where the left, right, bottom and top are the limitations of my new viewport I have tried both of them before and after setting up a new viewport, do not fix the problem Used to be.
This is a repetition of your projection from the comments that appear on your problem. Your window size has changed.
After resizing, call glOrtho ()
(be sure to set the matrix mode in GL_ PROJECTION) and it would be nice to see you go.
Comments
Post a Comment