{lwjgl} "lag" problem

EDIT:
i edit the title, just to make it look more like a problem than a discussion
Hello,
i create this topic to show you how i decompose my project classes and see if am doing it the “right” way or not .
but then it seems that i couldn’t fix the flickering issue, even when i run the examples from lwjgl wiki it doesn’t run smoothly it always have that kinda of lag

and there is my codes :

/**
 * This class is the main class 
 * 
 */

import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;

public class Game {

	// game width and height
	private final int WIDTH = 800, HEIGHT = 600;

	// variables of different classes
	Board board = new Board(); 		// the game board 
	Loop loop = new Loop(); 		// the loop class
	MyOpenGL ogl = new MyOpenGL();	// openGl initialization 

	public void start() {
		try {
			Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
			Display.create();

		} catch (LWJGLException e) {

			e.printStackTrace();
		}
		
		//initialize  open Gl
		ogl.initGL();
		
		//initialize  the game board 
		board.init();
		while (!Display.isCloseRequested()) {
			
			//calling Board main update method 
			board.myBoardLoop();

			Display.update();
			Display.sync(60);
		}
		Display.destroy();
	}

	public static void main(String[] args) {

		Game game = new Game();
		game.start();
	}

}

/**
 * This class will handle the game logic 
 * 
 */

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;

public class Board {
	// varibable of other classes
	private Drawing draw = new Drawing(); // drawing class
	private Loop loop = new Loop(); // the loop class

	private double heroX, heroY, heroW, heroH, heroSpeed;
	private Player hero;

	int delta;

	public void init() {
		// initialize the loop
		loop.init();

		initHero();
		hero = new Player(heroX, heroY, heroW, heroH);

	}

	// the main game logic "caller"
	public void myBoardLoop() {
		delta = loop.getDelta();
		painting();
		update(delta);
	}

	// the update method
	private void update(int delta) {

		heroUpdate();

		loop.updateFPS();

	}

	private void painting() {
		// clear the screen and depth buffer
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

		// using pre-build draw method
		draw.coloring("blue");
		draw.drawRect(hero.getX(), hero.getY(), hero.getWidth(),
				hero.getHeight());

	}

	// initializing the player
	private void initHero() {
		heroX = 400;
		heroY = 300;
		heroW = 30;
		heroH = 30;
		heroSpeed = 0.5;
	}

	// updateing the player
	private void heroUpdate() {
		control(delta);
		hero.setX(heroX);
		hero.setY(heroY);
		hero.setWidth(heroW);
		hero.setHeight(heroH);

	}

	// controlling the player
	private void control(int delta) {
		if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
			heroX -= heroSpeed * delta;
		}
		if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
			heroX += heroSpeed * delta;
		}
		if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
			heroY += heroSpeed * delta;

		}
		if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
			heroY -= heroSpeed * delta;
		}
	}

}

/**
 * This class will handle the game Frame rate
 * it's taken from the lwjgl wiki, "TimingExample"
 */

import org.lwjgl.Sys;
import org.lwjgl.opengl.Display;

public class Loop {

	
	public static long lastFrame;
	
	public static int fps;

	public static long lastFPS;

	public void init(){
		getDelta();

		lastFPS = getTime();
	}
	
	public int getDelta() {

		long time = getTime();
		int delta = (int) (time - lastFrame);
		lastFrame = time;

		return delta;
	}

	public long getTime() {
		return (Sys.getTime() * 1000) / Sys.getTimerResolution();
	}

	public void updateFPS() {
		if (getTime() - lastFPS > 1000) {
			Display.setTitle("FPS: " + fps);
			fps = 0;
			lastFPS += 1000;
		}
		fps++;
	}
}

/**
 * This class will handle basic OpenGl painting
 * 
 */

import java.util.Random;

import org.lwjgl.opengl.GL11;

public class Drawing {

	// fill a rectangle
	public void fillRect(double x, double y, double w, double h) {
		GL11.glBegin(GL11.GL_QUADS);
		GL11.glVertex2d(x, y); // up left corner
		GL11.glVertex2d(x + w, y);// up right corner
		GL11.glVertex2d(x + w, y + h);// down right corner
		GL11.glVertex2d(x, y + h);// down left corner
		GL11.glEnd();
	}

	// draw a rectangle
	public void drawRect(double x, double y, double w, double h) {
		GL11.glBegin(GL11.GL_LINES);

		GL11.glVertex2d(x, y);// x,y
		GL11.glVertex2d(x + w, y);// w,y

		GL11.glVertex2d(x + w, y);// w,y
		GL11.glVertex2d(x + w, y + h);// w,h

		GL11.glVertex2d(x + w, y + h);// w,h
		GL11.glVertex2d(x, y + h);// x,h

		GL11.glVertex2d(x, y + h);// x,h
		GL11.glVertex2d(x, y);// x,y
		GL11.glEnd();
	}

	// draw a line
	public void drawLine(double x1, double y1, double x2, double y2) {
		GL11.glBegin(GL11.GL_LINES);
		GL11.glVertex2d(x1, y1);
		GL11.glVertex2d(x2, y2);
		GL11.glEnd();
	}

	// set a color
	public void coloring(String color) {
		if (color == "white") {
			GL11.glColor3f(1.0f, 1.0f, 1.0f);
		} else if (color == "black") {
			GL11.glColor3f(0.0f, 0.0f, 0.0f);
		} else if (color == "red") {
			GL11.glColor3f(1.0f, 0.0f, 0.0f);
		} else if (color == "green") {
			GL11.glColor3f(0.0f, 1.0f, 0.0f);
		} else if (color == "blue") {
			GL11.glColor3f(0.0f, 0.0f, 1.0f);
		} else if (color == "random") {
			Random randomColor = new Random();
			float r = randomColor.nextFloat();
			float g = randomColor.nextFloat();
			float b = randomColor.nextFloat();
			GL11.glColor3f(r, g, b);

		}
	}

}

/**
 * This class will handle basic OpenGl initialisation
 * 
 */


import org.lwjgl.opengl.GL11;


public class MyOpenGL {

	// initializing openGl
	public void initGL() {
		
		GL11.glMatrixMode(GL11.GL_PROJECTION);
		GL11.glLoadIdentity();
		GL11.glOrtho(0, 800, 0, 600, 1, -1);
		GL11.glMatrixMode(GL11.GL_MODELVIEW);
		GL11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	}
	
}

/**
 * this class will hanle the player properties 
 */

public class Player {

	private double x, y, width, height;

	public Player(double x, double y, double width, double height) {
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
	}

	// setting values
	public void setX(double x) {
		this.x = x;
	}

	public void setY(double y) {
		this.y = y;
	}

	public void setWidth(double width) {
		this.width = width;
	}

	public void setHeight(double height) {
		this.height = height;
	}

	// getting values
	public double getX() {
		return this.x;
	}

	public double getY() {
		return this.y;
	}

	public double getWidth() {
		return this.width;
	}

	public double getHeight() {
		return this.height;
	}

}

What do you mean by ‘lagging’?

There are a few problems with the code (unused variables etc.) but I’ll leave you to find those.

when i move the player, it doesn’t really lag, but, it did that “effect”, it’s like i saw 2 squares or something like that and it hurt my eyes :stuck_out_tongue:

Something to do with your movement code?

It’s flickering?


Display.setVSyncEnabled(true);

Maybe?

[quote]It’s flickering?
[/quote]
yes, that’s the word

nope, it didn’t solve it
here is the .jar file maybe you can test it and tell me if you get the same problem

It’s working fine for me

Take note your jar isn’t working on 64-bit platform. Error:


Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\Iulian\AppDa
ta\Local\Temp\natives-656819368\lwjgl.dll: Can't load IA 32-bit .dll on a AMD 64-bit platform
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary1(Unknown Source)
        at java.lang.ClassLoader.loadLibrary0(Unknown Source)
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.loadLibrary0(Unknown Source)
        at java.lang.System.loadLibrary(Unknown Source)
        at org.lwjgl.Sys$1.run(Sys.java:73)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
        at org.lwjgl.Sys.loadLibrary(Sys.java:95)
        at org.lwjgl.Sys.<clinit>(Sys.java:112)
        at Loop.getTime(Loop.java:34)
        at Loop.getDelta(Loop.java:26)
        at Board.<init>(Board.java:14)
        at Game.<init>(Game.java:16)
        at Game.main(Game.java:47)

@NegativeZero
okay …
@marcuiulian13
yes that’s because i didn’t add the native 64bit files

I have this same flickering problem too. I believe it was you who said it was fine for you. It’s either your pc is special or you should get your eyes tested. This problem is getting annoying. I don’t see any problem in my code yet I still get this lag on my machine and on other machines.

it’s working fine for me too. You might download: http://mineforce.de/dhany.php
if it works fine, I will look up the differences :slight_smile:
(sry don’t have any uptodate projects except that)