i made an lwjgl app, which isnt complete yet… but i made like a paddle and a “ball”, the ball moves around the screen and the paddle is controled with arrows. i have not yet added collision detection…
but i was wondering how to speed up the rendering process?
The ball sort of jerks around… and i am a newbie at this so any help would be cool…
heres my code if u want to c what im doing.
import org.lwjgl.*;
import org.lwjgl.opengl.*;
import org.lwjgl.input.*;
public class Test {
static GL gl;
static GLU glu;
// for paddle
static float xPos;
// for bouncing thing
static int x,xspeed = 2;
static int y,yspeed = 2;
static int width;
static int height;
public static void main(String argv[]) throws Exception {
// Choose a Display Mode
DisplayMode[] modes = Display.getAvailableDisplayModes();
for (int i=0; i<modes.length; i++) {
if (modes[i].width == 800 &&
modes[i].height == 600 &&
modes[i].bpp == 32) {
Display.create(modes[i],true);
break;
}
}
xPos = Display.getWidth()/2;
x = (Display.getWidth()-5)/2;
y = (Display.getHeight()-5)/2;
width = 10;
height = 10;
init();
render();
}
public static void init() throws Exception {
// init keyboard
Keyboard.create();
// init gl and glu
gl = new GL();
glu = new GLU(gl);
gl.create();
// set timers
Sys.setTime(0);
Sys.setProcessPriority(Sys.HIGH_PRIORITY);
// init matrices
gl.matrixMode(GL.PROJECTION);
gl.loadIdentity();
glu.ortho2D(0, Display.getWidth(), 0, Display.getHeight());
gl.matrixMode(GL.MODELVIEW);
gl.loadIdentity();
gl.viewport(0,0, Display.getWidth(),Display.getHeight());
}
public static void render() {
gl.clearColor(0,0,0,0);
for (;;) {
gl.clear(GL.COLOR_BUFFER_BIT);
gl.pushMatrix();
gl.translatef(xPos, 10.0f, 0.0f);
gl.rotatef(5.0f,0.0f,1.0f,0.0f);
gl.begin(GL.QUADS);
{
gl.color3f(1.0f,0.0f,0.0f);
gl.vertex2i(-50,5);
gl.vertex2i(-50,30);
gl.color3f(0.0f,0.0f,1.0f);
gl.vertex2i(50,30);
gl.vertex2i(50,5);
}
gl.end();
gl.popMatrix();
gl.pushMatrix();
gl.translatef(0, 0, 0);
gl.begin(GL.QUADS);
{
gl.color3f(0,149,219);
gl.vertex2i(x,y);
gl.vertex2i(x,(y+10));
gl.color3f(219,149,0);
gl.vertex2i((x+10),(y+10));
gl.vertex2i((x+10),y);
}
gl.end();
gl.popMatrix();
gl.swapBuffers();
updateBall();
checkKeys();
}
}
public static void updateBall() {
if (((x+xspeed) > Display.getWidth())) xspeed *= -1;
if (((x+xspeed) < 0)) xspeed *= -1;
if (((y+yspeed) > Display.getHeight())) yspeed *= -1;
if (((y+yspeed) < 0)) yspeed *= -1;
x += xspeed;
y += yspeed;
}
public static void checkKeys() {
Keyboard.poll();
if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
Keyboard.destroy();
gl.destroy();
Display.destroy();
System.exit(0);
}
if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
if ((xPos-50.0f) - 5.0f < 0) return;
xPos-=5.0f;
}
if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
if ((xPos+50.0f) + 5.0f > Display.getWidth()) return;
xPos+=5.0f;
}
}
}

