Levvy
Levvy

Reputation: 1150

Moved renderer in lwjgl rendering

I have made a simple application in lwjgl and created simple gui. For now I have frame and panel. But there is a problem. Because (Display 800x600) when I make panel on Panel(x,y,w,h) (0,0,64,64) everything works fine, but when I create it on other position (x,y where point 0,0 is in left upeper corner) it render moved panel. Capture of  rendering The white space is my panel which should change color when I drag mouse on it. It is created on (417,417,64,64), but it's rendered on somethink like (90,90). I have rendered fonts to show all of itss positions. The blue box I draw on this image is where it should be and it looks like there the panel is, because the white space is changing color when I drag mouse there, but this white space should be there. My code looks like that: I am adding all components to HashMap like Panels.

glColor3f(backgroundColor.getRed(), backgroundColor.getGreen(),
                backgroundColor.getBlue());
        if (hasFocus()) {
            glColor3f(1f, 0f, 0f);
        }
        glPushMatrix();
        glRecti(getX(), getY(), getWidth(), getHeight());
        glPopMatrix();

And initGL method:

glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glScalef(1.0f, 1.0f, 1.0f);
        glOrtho(0, 800, 600, 0, 1, -1);
        glFrustum(-1, 1, -1, 1, 0.0, 40.0);
        glViewport(0, 0, Display.getWidth(), Display.getHeight());
        glMatrixMode(GL_MODELVIEW);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glShadeModel(GL_SMOOTH);

Upvotes: 0

Views: 76

Answers (1)

ratchet freak
ratchet freak

Reputation: 48196

glRecti doesn't work that way it expects the coordinates of the corners

so instead you should do:

glRecti(getX(), getY(), getX()+getWidth(), getY()+getHeight());

Upvotes: 1

Related Questions