0

I am new to LWJGL but am slowly learning. I was wanting to make a square that rotated when you pressed the key. Like d rotates it 90 degrees as you can tell below, but when I use glRotatef(); it gives me an error and I don't know why. There error tells me I need to create a method for it, I know I don't need to though. Anything helps!

public class MainPlayer {

private Draw draw;
private int rotation;

private float WIDTH = (float) (Display.getWidth() * 0.1);
private float HEIGHT = (float) (WIDTH / 2);
private float x = Display.getWidth() / 2 - WIDTH / 2;
private float y = Display.getHeight() / 2 - HEIGHT / 2;

public MainPlayer(){
    draw = new Draw(1.0f, 1.0f, 1.0f, WIDTH, HEIGHT);
}

public void update(){

}

public void render(){

        glTranslatef(x, y, 0);
        glRotatef(rotation,0,0,1);
        draw.render();

}

public void getInput(){
    if(Keyboard.isKeyDown(Keyboard.KEY_W)){
        rotation = 0;
    }
    if(Keyboard.isKeyDown(Keyboard.KEY_S)){
        rotation = 180;
    }
    if(Keyboard.isKeyDown(Keyboard.KEY_A)){
        rotation = 270;
    }
    if(Keyboard.isKeyDown(Keyboard.KEY_D)){
        rotation = 90;
    }
}
}
user2892875
  • 99
  • 1
  • 1
  • 9

3 Answers3

0

You create an int rotation and I assume your render() loops the whole time, and you only set rotation in getInput().

So I am assuming that you should declare it as int rotation = 0.

skiwi
  • 66,971
  • 31
  • 131
  • 216
0

That probably means that you haven't statically imported glRotatef

Either use

GL11.glRotatef(rotation, 0, 0, 1);

or import it at the beginning of your program with

import static org.lwjgl.opengl.GL11.glRotatef
Ryxuma
  • 672
  • 5
  • 18
0

glRotatef() is a OpenGL call to rotate objects, just like glTranslatef() moves them. glRotatef() does it in the same way.

glRotatef(AngleOfRotationf, 0, 1, 0) would rotate it horisontally, like in this video i just made: http://www.youtube.com/watch?v=SHsssrj9qr8& uses that line to rotate a ship.

Also in that video i demonstrated moving it with glTranslatef().

To use it you must use GL11.glRotatef(), or import static org.lwjgl.opengl.GL11.*;

Joehot200
  • 1,070
  • 15
  • 44