How do i move a sprite in LWJGL?

Here is my source code, for some reason it draws the quad but it doesnt move, even though the variables are changing when keys are pressed:


package little2dworld;
import java.awt.Color;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import static org.lwjgl.opengl.GL11.*;

public class Little2DWorld {
    float x = 20, y = 20;
    final float VEL = .01f;
    int width = 400, height = 400;
    boolean up = false, right = false, down = false, left = false;
    private void updateLoop(){
        while(Keyboard.next()){
        if(Keyboard.getEventKey() == Keyboard.KEY_W)
            y = y - VEL;
        if(Keyboard.isKeyDown(Keyboard.KEY_D))
            right = true;
        if(Keyboard.isKeyDown(Keyboard.KEY_S))
            down = true;
        if(Keyboard.isKeyDown(Keyboard.KEY_A))
            left = true;
        }
        System.out.println("X coord: " + x + "\n" + "Y coord: " + y);
    }
    private void create(){
        try{
            Display.setDisplayMode(new DisplayMode(800, 600));
            Display.create();
            Display.setVSyncEnabled(true);
            initGL();
            while(!Display.isCloseRequested()){
                updateLoop();
                render();
                
                Display.update();
                Display.sync(100);
            }
            Display.destroy();
            System.exit(0);
        }catch(LWJGLException e){
            
        }
    }
    private void initGL(){
        glEnable(GL_TEXTURE_2D);
        glClearColor(0f, 0f, 0f, 0f);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glViewport(0, 0, 800, 600);
        
        
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, 800, 600, 0, -1, 1);
        glMatrixMode(GL_MODELVIEW);
        
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
    }
    private void render(){
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(240, 240, 240);
    glBegin(GL_QUADS);
        glVertex2f(x, y);
        glVertex2f(x+width, y);
        glVertex2f(x+width, y+height);
        glVertex2f(x, y+height);
    glEnd();
    }
    public static void main(String[] args) {
        new Little2DWorld().create();
    }
}


What am i doing wrong? I also feel like most of this can be simplified SO MUCH MORE :emo:

That updateLoop method is wrong. You should not put Keyboard.next() inside a while loop. Since you don’t care how many times W gets pressed, all you need is


if(Keyboard.isKeyDown(Keyboard.KEY_W))
    y -= VEL;

And you can then remove the while loop.

Yeah that was my method before. I did that and had the X and Y coords printed out at the end of the loop to see if their values change (they did) but the quad i was drawing is still sitting on the same spot, which makes no sense, I’m thinking I’m missing some kind of ‘refresh’ command i don’t know about :confused: