Kind of new to lwjgl, but I have done some basic opengl in the past. I am using slick2d, and trying to utilize opengl for manipulating the camera. This is for a simple sidescroller game. The game resolution is 800x600.
In my render method which is called every frame, I set the viewport as so:
cameraX = player.getX();
if(cameraX <= 400.0f) {
cameraX = 400.0f;
}
cameraX -= 400.0f;
if(cameraX > 0) {
cameraX *= -1;
}
GL11.glViewport((int)cameraX, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
What I wish to do is have the camera's center point to the middle of the screen, and then move left/right as needed when the player moves. I initially set it up as 400 for cameraX, 300 for the cameraY. Once I moved my character, the whole screen shifted so the bottom left corner of what I drew was now in the center of the screen (so it went 300 down, 400 to the left). I'd like to have it so the width of the camera is the same as the screen, and that it points to the center.
The first if statement is so the camera doesn't come further left then halfway across the screen. I then subtract it by 400 since the camera points to 400x when i have cameraX = 0. The second if statement is to ensure cameraX is negative. If I leave it positive the camera moves in the opposite direction of the player.
I hope this is clear enough for describing my issue.