Hi all :)
i'm having a little problem with opengl and LWJGL
i try do do that if you press one time f1 it will show you your mouse cords and if you press the 2nd time the cords will disapear.
now the problem is that if i press f1 its shows the cords and suddenly it disapears.. any help??
http://pastebin.com/ZV5S6YEv
if (Keyboard.getEventKeyState())
is not the correct manner.
As you've got to know KeyEvent "events" (^^), they have several associated states (integers values). When you press a key, a key_pressed is dispatched and when you release the key a key_released is dispatched then.
switch(Keyboard.getEventKeyState()) {case KeyPressed: break; case KeyReleased: break;...etc.}
That's the way you can read KeyEvents.
:D
Actually he is using Keyboard.getEventKeyState() exactly right. From the javadoc:
QuotegetEventKeyState
public static boolean getEventKeyState()
Gets the state of the key that generated the current event
Returns:
True if key was down, or false if released
His problem is that he is only rendering the mouse coordinates inside the 'if' that handles the first F1 key down. As soon as the display updates again, the display is cleared and the rendering of the mouse coordinates is lost. Try something more like this:
while (true) {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
while(Keyboard.next())
{
if (Keyboard.getEventKeyState())
{
if(Keyboard.getEventKey() == Keyboard.KEY_F1 && count == 0)
{
count++;
}else if(Keyboard.getEventKey() == Keyboard.KEY_F1 && count == 1)
{
count = 0;
}
}
}
if (count == 1)
render();
Display.update();
if (Display.isCloseRequested()) {
Display.destroy();
System.exit(0);
}
}
thanks for the help :) it works
alright ! .)