Hello Guest

Display.sync() don't work

  • 3 Replies
  • 7672 Views
Display.sync() don't work
« on: April 16, 2010, 16:38:01 »
Hello all,
I wont to change de FPS in my program with Display(), but it don't work, I don't know why, this my code:

Code: [Select]
public class DisplayTest extends JFrame
{
static Vector3f camPos = new Vector3f();
    static Vector3f target = new Vector3f();
    static Vector3f target2 = new Vector3f();
static float distance = 4.0f;
static float angleY = 0.0f;
static float angleX = 0.0f;
public static void main(String[] args) throws LWJGLException {
DisplayTest test = new DisplayTest();

test.setVisible(true);
Display.setParent(test.c);
DisplayMode displayMode = null;
camPos.x = 0f;
                camPos.y = 0f;
                camPos.z = 1f;
       
      Display.setFullscreen(false);
      DisplayMode[] d = Display.getAvailableDisplayModes();
      for (int i = 0; i < d.length; i++) {
        if (d[i].getWidth() == 640 && d[i].getHeight() == 480 && d[i].getBitsPerPixel() == 32) {
          displayMode = d[i];
          break;
        }
      }
      Display.setDisplayMode(displayMode);
      Display.create();
      Mouse.setGrabbed(true);
      GL11.glShadeModel(GL11.GL_SMOOTH);
      GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      GL11.glClearDepth(1.0f);
      GL11.glEnable(GL11.GL_DEPTH_TEST);
      GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glDepthFunc(GL11.GL_LEQUAL);

      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();

      GLU.gluPerspective(45.0f, (float) displayMode.getWidth() / (float) displayMode.getWidth(),0.1f,100.0f);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
Keyboard.create();
Mouse.create();

cam();

while (!Display.isCloseRequested()) {
dessine();
glFlush();

   Display.update();
}
Display.sync(60);// Here I put 60 FPS
   mouse();
   key();
   
}

[...]

public static void floor(int x, int y, String texture){
glBindTexture(GL_TEXTURE_2D, loadTexture(texture+".jpg"));
    GL11.glPushMatrix();
    {
    glBegin(GL_QUADS);
    glTexCoord2d(0,0);
        glVertex3d(0.60+1.2*x,-0.60+1.2*y,0.8);
        glTexCoord2d(10,0);
        glVertex3d(-0.60+1.2*x,-0.60+1.2*y,0.8);
        glTexCoord2d(10,10);
        glVertex3d(-0.60+1.2*x,0.60+1.2*y,0.8);
        glTexCoord2d(0,10);
        glVertex3d(0.60+1.2*x,0.60+1.2*y,0.8);
       
        glEnd();
       
    }
    GL11.glPopMatrix();
}

Canvas c;

public DisplayTest() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c = new Canvas();
c.setBackground(Color.blue);
c.setSize(new Dimension(640,480));
this.add(c);
this.pack();

}
[...]
   
public static void draw(){
     Parseur("test.xml");
     NodeList listeparcours = nroot.getElementsByTagName("floor");
     nbparcours=listeparcours.getLength();
     for(int i=0; i<nbparcours; i++){
     Element e = (Element)listeparcours.item(i);

     floor(Integer.parseInt(e.getAttribute("x"))/10, Integer.parseInt(e.getAttribute("y"))/10, "iron");
     }
    }
}


Can you help me ?

*

Offline kappa

  • *****
  • 1319
Re: Display.sync() don't work
« Reply #1 on: April 16, 2010, 16:40:17 »
yes, simple problem. Display.sync(fps) must be inside your game loop and must be called every frame.

Re: Display.sync() don't work
« Reply #2 on: April 16, 2010, 16:53:03 »
It not work, I try:
Code: [Select]
while (!Display.isCloseRequested()) {
dessine();
   glFlush();
   Display.update();
   Display.sync(6);
}
and I try:
Code: [Select]
while (!Display.isCloseRequested()) {
dessine();
   glFlush();
                   Display.sync(6);
   Display.update();
   
}

and it not work, what is my error please ? (sorry, I'm a very noob beginner)

Re: Display.sync() don't work
« Reply #3 on: April 16, 2010, 18:53:23 »
Ok, I have found the error, it's from texture.