I’m working on a 2D game, and having some trouble with clicking. I’m using java.awt.Polygon for the boundaries on the click areas, so they can be arbitrary shapes. However, because JOGL’s 0,0 is in the bottom left and AWT’s is top left, my click boundary and my image are on opposite sides of the screen. Is there a way to change one coordinate set or the other so that they match?
This is a pretty common issue with graphics in general.
Just transform all your screenspace Y points like this:
Y = (screenHeight - Y);
I figured that, but I anticipate there being other issues down the line, which is why I was hoping somebody had a silver bullet for me
You could also swap the Y coordinates of the top and bottom corners in your glOrtho call so your canvas Y coordinate system matches what swing uses.
That’s what I wanted to hear. Wouldn’t that make images draw upside down, though?
OK. Got it solved! I had to invert the coordinates in the gluOrtho2D call, then change around the way I was loading images (it was inverting to deal with the AWT/OpenGL coordinate discrepancy already), and then needed to display the images at x, y + height in order to have the image’s 0,0 be upper left instead of lower right. So now AWT, JOGL and my individual objects are all in the same page about it, and life is good! No longer do my objects’ bounding boxes zoom off one way and the object another! There was much rejoicing!
Hmm. Issue. Images draw right side up, but fonts probably won’t.
Any suggestions?
Invert the y coordinates in the vertexes (as opposed to the tex coords) as your subdividing your texture image?