Example #1
0
/** Created by cout970 on 10/02/2016. */
public class GuiHandler implements InputHandler.IKeyboardCallback {

  private ConfigurationFile config = ConfigurationFile.INSTANCE;
  private Vect2i size = Display.getFrameBufferSize().copy();
  private Vect2i center = Display.getFrameBufferSize().copy().division(2);
  private Gui gui;

  public void init() {
    gui = new Gui();
    TopBar topBar;
    gui.addComponent(topBar = new TopBar());
    topBar.init(gui);
    InputHandler.registerKeyboardCallback(this);
    gui.addComponent(topBar.getCubeEditor());
    //        gui.addComponent(topBar.getModelTree());
    gui.addComponent(topBar.getTextureEditor());
    //        gui.addComponent(topBar.getGroupEditor());
  }

  public void update() {
    Display.setGuiProjection();
    TextureStorage.EMPTY.bind();
    if (InputHandler.isMouseButtonPress(InputHandler.MouseButton.MIDDLE)
        || InputHandler.isMouseButtonPress(InputHandler.MouseButton.RIGHT)) {
      drawCenter();
    }
    size = Display.getFrameBufferSize().copy();
    center = Display.getFrameBufferSize().copy().division(2);
    gui.render();
  }

  private void drawCenter() {
    float size = 50;
    TextureStorage.CENTER.bind();
    glBegin(GL_QUADS);
    glColor4f(1, 1, 1, 1);
    glTexCoord2d(0, 0);
    glVertex3d(center.getX() - size / 2, center.getY() - size / 2, 0);
    glTexCoord2d(0, 1);
    glVertex3d(center.getX() - size / 2, center.getY() + size / 2, 0);
    glTexCoord2d(1, 1);
    glVertex3d(center.getX() + size / 2, center.getY() + size / 2, 0);
    glTexCoord2d(1, 0);
    glVertex3d(center.getX() + size / 2, center.getY() - size / 2, 0);
    glEnd();
  }

  @Override
  public void onKeyPress(int key, int code, int action) {}

  public Vect2i getScreenSize() {
    return size.copy();
  }

  public Gui getGui() {
    return gui;
  }
}
 private void setUpDisplay() {
   try {
     Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
     Display.setTitle("Pong");
     Display.create();
   } catch (LWJGLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Example #3
0
 public void update() {
   Display.setGuiProjection();
   TextureStorage.EMPTY.bind();
   if (InputHandler.isMouseButtonPress(InputHandler.MouseButton.MIDDLE)
       || InputHandler.isMouseButtonPress(InputHandler.MouseButton.RIGHT)) {
     drawCenter();
   }
   size = Display.getFrameBufferSize().copy();
   center = Display.getFrameBufferSize().copy().division(2);
   gui.render();
 }
 public PongGame() {
   setUpDisplay();
   setUpOpengGL();
   setUpEntities();
   setUpTimer();
   while (isRunning) {
     render();
     logic(getDelta());
     input();
     Display.update();
     Display.sync(60);
     if (Display.isCloseRequested()) {
       isRunning = false;
     }
   }
   Display.destroy();
 }
  public SimpleRenderer(int x, int y) {
    this.width = x;
    this.height = y;
    try {
      Display.setDisplayMode(new DisplayMode(x, y));
      Display.setTitle("Crowd Simulation");
      Display.create();
      Display.setVSyncEnabled(true);
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    Random r = new Random();

    System s = new System(this.width, this.height - 2, 0.0f, 1.0f);
    for (int i = 0; i < 1200; i++) {

      int xX = r.nextInt(this.width);
      int yY = r.nextInt(this.height);
      int oldX = xX; // + r.nextInt(1) ;
      int oldY = yY; // + r.nextInt(2) + 1;

      double size = r.nextGaussian() * 1.2 + 16;
      addPoint(
          s,
          xX,
          yY,
          oldX,
          oldY,
          (float) size, // r.nextFloat() * 20 + 10,
          1,
          i > 600 ? 0 : 1,
          1,
          i > 600 ? -0.9 : 0.9); // r.nextFloat(), r.nextFloat(), r.nextFloat());

      // addPoint(s, xX, yY, oldX, oldY, (float)size,//r.nextFloat() * 20 + 10,
      //		r.nextFloat(), r.nextFloat(), r.nextFloat(),i>400 ?-r.nextFloat():r.nextFloat());

    }

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, x, y, 0, 1, -1);
    glMatrixMode(GL_MODELVIEW);

    boolean isPressed = false;
    while (!Display.isCloseRequested()) // rendering
    {

      glClear(GL_COLOR_BUFFER_BIT);
      // glClearColor(1.0f,1.0f,1.0f,1.0f);
      if (Mouse.isButtonDown(0)) {

        // isPressed = true;
        /*int xX = Mouse.getX();
        int yY = this.height - Mouse.getY();

        int oldX = xX;// + r.nextInt(4) - 2;
        int oldY = yY;
        double size = r.nextGaussian()*1.2 +14;
        addPoint(s, xX, yY, oldX, oldY,(float)size,// r.nextFloat() * 20 + 10,
        		r.nextFloat(), r.nextFloat(), r.nextFloat(),30);
        */
        s.setDestroying(true);
      }

      if (Mouse.isButtonDown(1)) {

        for (int i = -150; i < 150; i += 10) {

          int xX = Mouse.getX();
          int yY = this.height - Mouse.getY();
          s.applyDirerction(s.searchPoint(xX, yY + i), 10);
        }
      }

      // java.lang.System.out.println("Number of objects: " +s.getListOfPoints().size() +"
      // Destroying? "+ s.isDestroying());
      s.step(3);

      int xX = Mouse.getX();
      int yY = this.height - Mouse.getY();

      for (int i = -150; i < 150; i += 10) {
        Point k = s.searchPoint(xX, yY + i);
        if (k != null) {
          glColor3f(0.0f, 0.0f, 0.0f);
          Point.DrawCircle(k.getX(), k.getY(), k.getRadius() - 2, 20);
        }
      }

      Display.update();
      Display.sync(30);
    }

    Display.destroy();
  }