Beginner - Cursor & Render locations doesn't match

Started by KliK, August 04, 2013, 22:59:17

Previous topic - Next topic

KliK



As you can see, the rect is drawn at X=774, while the cursor is around X~955
Why is it happening?


Cornix

I doubt anybody can give you a good answer without some more information.
For example it would be alot easier if we could see the important parts of the code since there can be many reasons as to why this is happening.

KliK

This is the main class:

http://pastebin.com/5s0mRmgw

This is the code to draw a rectangle:

public static void drawCircle(final Point location, final double radius) {
        GL11.glBegin(GL11.GL_QUADS);

        GL11.glVertex2i((int)(location.getX() - radius), (int)(location.getY() - radius));
        GL11.glVertex2i((int)(location.getX() + radius), (int)(location.getY() - radius));
        GL11.glVertex2i((int)(location.getX() + radius), (int)(location.getY() + radius));
        GL11.glVertex2i((int)(location.getX() - radius), (int)(location.getY() + radius));

        GL11.glEnd();
    }


Ignore the "drawCircle"

I have followed the tutorial on the wiki

Fool Running

Best guess is the call to GL11.glOrtho(0, 800, 0, 600, 1, -1). It should be your width and height constants you are using to create your display mode. What you are doing is stretching the 800x600 to the size of your window - no matter what that size is.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

KliK

Quote from: Fool Running on August 05, 2013, 16:55:21
Best guess is the call to GL11.glOrtho(0, 800, 0, 600, 1, -1). It should be your width and height constants you are using to create your display mode. What you are doing is stretching the 800x600 to the size of your window - no matter what that size is.
Thank you, it works
Why should the window be at the size of 800x600?

Fool Running

The call to glOrtho just has to have the same dimensions as the size of your window. So if you created a window that was 1600x1200 and used your glOrtho call with 800x600, then for every unit of movement on an axis in OpenGL, it would move 2 pixels on the screen. To get a 1:1 mapping of OpenGl units to pixels, they need to be the same.

Hope that helps. ;D
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D