示例#1
0
  public Render(Level level) {
    this.level = level;
    try {
      Display.setFullscreen(true);
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    // Enable vsync if we can
    Display.setVSyncEnabled(true);

    try {
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    // Put the window into orthographic projection mode with 1:1 pixel
    // ratio.
    // We haven't used GLU here to do this to avoid an unnecessary
    // dependency.

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(
        0.0,
        Display.getDisplayMode().getWidth(),
        0.0,
        Display.getDisplayMode().getHeight(),
        -1.0,
        1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
  }
 private static void initControls() {
   // Automatically create mouse, keyboard and controller
   if (!getPrivilegedBoolean("org.lwjgl.opengl.Display.noinput")) {
     if (!Mouse.isCreated() && !getPrivilegedBoolean("org.lwjgl.opengl.Display.nomouse")) {
       try {
         Mouse.create();
       } catch (LWJGLException e) {
         if (LWJGLUtil.DEBUG) {
           e.printStackTrace(System.err);
         } else {
           LWJGLUtil.log("Failed to create Mouse: " + e);
         }
       }
     }
     if (!Keyboard.isCreated() && !getPrivilegedBoolean("org.lwjgl.opengl.Display.nokeyboard")) {
       try {
         Keyboard.create();
       } catch (LWJGLException e) {
         if (LWJGLUtil.DEBUG) {
           e.printStackTrace(System.err);
         } else {
           LWJGLUtil.log("Failed to create Keyboard: " + e);
         }
       }
     }
   }
 }
示例#3
0
  public void start() {
    // ウィンドウの生成
    try {
      Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
      // Display.setTitle("SimField");
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(0);
    }

    initGL();

    // メインループ
    while (!Display.isCloseRequested()) {
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
      /**
       * for(Life l : lifeSet.getArray()){ l.renderLife(); } for(Life lr: lifeRedSet.getArray()){
       * lr.renderLife(); } for(Life lb: lifeBlueSet.getArray()){ lb.renderLife(); }
       */
      for (Life l : life) {
        l.renderLife();
      }
      for (Life lr : lifeRed) {
        lr.renderLife();
      }
      for (Life lb : lifeBlue) {
        lb.renderLife();
      }
      status.updateFPS();
      Display.update(); // オンスクリーンに反映
      Display.sync(60); // FPSを60に固定
    }
  }
示例#4
0
  public void start() {
    try {
      Display.setDisplayMode(new DisplayMode(800, 600));
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(0);
    }

    initGL(); // init OpenGL
    try {
      font = new Font("assets/text.png", "assets/text.txt", 6, 13);
      font.buildFont(2); // build the textures for text
      s = new Sprite("assets/pokemon_sprites/front/643.png");
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(0);
    }
    getDelta(); // call once before loop to initialise lastFrame
    lastFPS = getTime(); // call before loop to initialise fps timer

    while (!Display.isCloseRequested() && !finished) {
      int delta = getDelta();

      update(delta);
      renderGL();

      Display.update();
      Display.sync(60); // cap fps to 60fps
    }

    Display.destroy();
  }
示例#5
0
  private void initialise() {
    DisplayMode mode = new DisplayMode(WIDTH, HEIGHT);
    Display.setTitle(TITLE);

    input = new InputHandler();
    display = new CodeDisplay(input);

    try {
      Display.setDisplayMode(mode);
      Display.setResizable(false);
      Display.create();

      if (!GLContext.getCapabilities().OpenGL33)
        System.err.printf("You must have at least OpenGL 3.3 to run this program\n");
    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(-1);
    }

    // Set clear color

    glShadeModel(GL_SMOOTH);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL); // Less than or equal
    glClearDepth(1.0);

    establishProjectionMatrix();

    // glEnable(GL_LIGHTING);
    // glEnable(GL_LIGHT0);
  }
示例#6
0
  /**
   * Start the application. The window is opened and the main loop is entered. This call does not
   * return until the window is closed or an exception was caught.
   */
  public void start() {
    try {
      Display.setDisplayMode(new DisplayMode(width, height));
      Display.setTitle(title);
      if (multisampling) Display.create(new PixelFormat().withSamples(8));
      else Display.create();

      // Sync buffer swap with vertical sync. Results in 60 fps on my Mac
      // Book.
      Display.setSwapInterval(1);
      Display.setVSyncEnabled(true);

      input = new Input();
      application.init();

      while (!Display.isCloseRequested()) {
        input.update();
        input.setWindowSize(width, height);
        application.simulate(time.elapsed(), input);
        application.display(width, height, input);
        Display.update();
      }
    } catch (LWJGLException e) {
      e.printStackTrace();
    } finally {
      Display.destroy();
    }
  }
示例#7
0
  public static void main(String[] args) {

    Main main = new Main();
    Viewer viewer;
    try {
      viewer = new Viewer();
      GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);

      Scene scene = viewer.getScene();

      // viewer.setProjection(new OrthogonalProjection(0, 800, 600, 0, 1, -1));

      // GL11.glMatrixMode(GL11.GL_MODELVIEW);
      // GL11.glRectf(100.0f, 150.0f, 150.0f, 100.0f);
      MenuButton m = new MenuButton(250.0f, 50.0f, 600.0f, 100.0f, "Bzinga", 1);

      scene.add(m);
      // scene.render();
      viewer.run();

    } catch (LWJGLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  public void start() {
    try {
      Display.setDisplayMode(new DisplayMode(800, 600));
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(0);
    }

    initGL(); // init OpenGL
    getDelta(); // call once before loop to initialise lastFrame
    lastFPS = getTime(); // call before loop to initialise fps timer

    while (!Display.isCloseRequested()) {
      int delta = getDelta();

      update(delta);
      renderGL();

      Display.update();
      Display.sync(60); // cap fps to 60fps
    }

    Display.destroy();
  }
示例#9
0
  public static void main(String[] args) throws InterruptedException {
    try {
      Display.setTitle("Simple Square");
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    // draw the square
    glBegin(GL_LINE_LOOP);
    glVertex3f(-0.5f, -0.5f, 0f);
    glVertex3f(-0.5f, 0.5f, 0f);
    glVertex3f(0.5f, 0.5f, 0f);
    glVertex3f(0.5f, -0.5f, 0f);
    glEnd();

    // flush any commands that are still hanging about.
    glFlush();
    // update window.
    Display.update();

    while (!Display.isCloseRequested()) {
      Thread.sleep(100);
    }
    Display.destroy();
  }
示例#10
0
  private void init(boolean absolutePixels, boolean testModes) {
    // find out what the current bits per pixel of the desktop is
    int currentBpp = Display.getDisplayMode().getBitsPerPixel();

    try {
      DisplayMode mode;
      if (testModes) mode = findDisplayMode(WINDOW_WIDTH, WINDOW_HEIGHT, currentBpp);
      else mode = new DisplayMode(WINDOW_WIDTH, WINDOW_HEIGHT);

      Display.setDisplayMode(mode);
      Display.setFullscreen(false);
      Display.setTitle("src");
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    double aspectRatio = (double) WINDOW_WIDTH / WINDOW_HEIGHT;

    if (absolutePixels) {
      glOrtho(0.0d, WINDOW_WIDTH, 0.0d, WINDOW_HEIGHT, 1.0d, -1.0d);
    } else {
      glOrtho(aspectRatio, -aspectRatio, -1.0d, 1.0d, 1.0d, -1.0d);
    }

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
  }
示例#11
0
 private void initGL() {
   try {
     Display.setDisplayMode(new DisplayMode(GS.FRAMEWIDTH, GS.FRAMEHEIGHT));
     Display.setFullscreen(true);
     Display.create();
     Display.setVSyncEnabled(true);
   } catch (LWJGLException e) {
     e.printStackTrace();
     Display.destroy();
     System.exit(1);
   }
   GL11.glEnable(GL11.GL_TEXTURE_2D);
   // GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   GL11.glClearDepth(1.0f);
   // GL11.glEnable(GL11.GL_DEPTH_TEST);
   // GL11.glDepthFunc(GL11.GL_ADD); //Wenn nicht auskommentiert führt es zu Exception
   GL11.glMatrixMode(GL11.GL_PROJECTION);
   GL11.glViewport(0, 0, GS.FRAMEWIDTH, GS.FRAMEHEIGHT);
   GL11.glOrtho(0, GS.FRAMEWIDTH, GS.FRAMEHEIGHT, 0, 0, 128);
   GL11.glEnable(GL11.GL_BLEND);
   GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
   // GL11.glBlendEquation( BLENDING_EQUATIONS[blendingEquationIndex]);
   GL11.glShadeModel(GL11.GL_FLAT);
   GL11.glMatrixMode(GL11.GL_MODELVIEW);
   GL11.glEnable(GL11.GL_ALPHA_TEST);
   GL11.glAlphaFunc(GL11.GL_GREATER, 0);
   GL11.glCullFace(GL11.GL_BACK);
   glEnable(GL_CULL_FACE);
   glCullFace(GL_BACK);
   GL11.glLoadIdentity();
 }
示例#12
0
  /** Tests the DisplayConfiguration */
  private void setDisplayConfigurationTest() {
    System.out.println("==== Test setDisplayConfigurationTest ====");

    System.out.println("Testing normal setting");
    changeConfig(1.0f, 0f, 1f);

    System.out.println("Testing gamma settings");
    changeConfig(5.0f, 0f, 1f);
    changeConfig(0.5f, 0f, 1f);

    System.out.println("Testing brightness settings");
    changeConfig(1.0f, -1.0f, 1f);
    changeConfig(1.0f, -0.5f, 1f);
    changeConfig(1.0f, 0.5f, 1f);
    changeConfig(1.0f, 1.0f, 1f);

    System.out.println("Testing contrast settings");
    changeConfig(1.0f, 0f, 0f);
    changeConfig(1.0f, 0f, 0.5f);
    changeConfig(1.0f, 0f, 10000.0f);

    System.out.print("resetting...");
    try {
      Display.setFullscreen(false);
    } catch (LWJGLException e) {
      e.printStackTrace();
    }
    System.out.println("done");

    System.out.println("---- Test setDisplayConfigurationTest ----");
  }
示例#13
0
 public static void setParent(Canvas canvas) {
   try {
     Display.setParent(canvas);
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
示例#14
0
 public static void toggleFullscreen() {
   Globals.fullscreen = !Globals.fullscreen;
   try {
     Display.setFullscreen(Globals.fullscreen);
     Display.update();
   } catch (LWJGLException e) {
     e.printStackTrace();
   }
 }
示例#15
0
 public static void setSize(int width, int height) {
   try {
     displayMode = new DisplayMode(width, height);
     Display.setDisplayMode(displayMode);
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
示例#16
0
 @Override
 public void setFullscreen(final boolean fullscreen) {
   try {
     Display.setFullscreen(fullscreen);
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
示例#17
0
  public static void setWindowResolution(int width, int height) {
    Globals.windowWidth = width;
    Globals.windowHeight = height;
    Globals.aspectRatio = (float) Globals.windowWidth / (float) Globals.windowHeight;
    Globals.windowMatrix.set(
        1 / Globals.aspectRatio,
        0.0f,
        0.0f,
        0.0f,
        0.0f,
        1.0f,
        0.0f,
        0.0f,
        0.0f,
        0.0f,
        1.0f,
        0.0f,
        0.0f,
        0.0f,
        0.0f,
        1.0f);

    // for(IWindowChangeListener lis : Globals.windowChangeListener)
    // {
    //	lis.onWindowResolutionChange(Globals.windowWidth, Globals.windowHeight);
    // }

    try {
      DisplayMode[] modes = Display.getAvailableDisplayModes();

      DisplayMode finalMode = new DisplayMode(Globals.getWindowWidth(), Globals.getWindowHeight());

      for (int i = 0; i < modes.length; i++) {
        DisplayMode current = modes[i];
        if (current.getWidth() == Globals.getWindowWidth()
            && current.getHeight() == Globals.getWindowHeight()
            && current.getBitsPerPixel() == 32
            && current.getFrequency() == 60) finalMode = current;
      }

      Display.setDisplayMode(finalMode);

      if (!Display.isCreated()) {
        PixelFormat pixelFormat = new PixelFormat();
        ContextAttribs contextAtrributes =
            new ContextAttribs(3, 2).withForwardCompatible(true).withProfileCore(true);
        Display.create(pixelFormat, contextAtrributes);
      }

      GL11.glViewport(0, 0, Globals.getWindowWidth(), Globals.getWindowHeight());
    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(-1);
    }
    Display.update();
  }
示例#18
0
  public void execute() {
    // Initialize OpenAL and clear the error bit.
    try {
      AL.create();
    } catch (LWJGLException le) {
      le.printStackTrace();
      return;
    }
    AL10.alGetError();

    // Load the wav data.
    if (loadALData() == AL10.AL_FALSE) {
      System.out.println("Error loading data.");
      return;
    }

    setListenerValues();

    // Loop.
    System.out.println("OpenAL Tutorial 1 - Single Static Source");
    System.out.println("[Menu]");
    System.out.println("p - Play the sample.");
    System.out.println("s - Stop the sample.");
    System.out.println("h - Pause the sample.");
    System.out.println("q - Quit the program.");
    char c = ' ';
    Scanner stdin = new Scanner(System.in);
    while (c != 'q') {
      try {
        System.out.print("Input: ");
        c = (char) stdin.nextLine().charAt(0);
      } catch (Exception ex) {
        c = 'q';
      }

      switch (c) {
          // Pressing 'p' will begin playing the sample.
        case 'p':
          AL10.alSourcePlay(source.get(0));
          break;

          // Pressing 's' will stop the sample from playing.
        case 's':
          AL10.alSourceStop(source.get(0));
          break;

          // Pressing 'h' will pause the sample.
        case 'h':
          AL10.alSourcePause(source.get(0));
          break;
      }
      ;
    }
    killALData();
    AL.destroy();
  }
示例#19
0
 private void createWindow() {
   try {
     Display.setDisplayMode(DISPLAY_MODE);
     Display.setFullscreen(fullscreen);
     Display.setTitle(WINDOW_TITLE);
     Display.create();
   } catch (LWJGLException e) {
     e.printStackTrace();
   }
 }
 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();
   }
 }
示例#21
0
 private static void setUpDisplay() {
   try {
     Display.setDisplayMode(new DisplayMode(WINDOW_DIMENSIONS[0], WINDOW_DIMENSIONS[1]));
     Display.setTitle(WINDOW_TITLE);
     Display.create();
   } catch (LWJGLException e) {
     e.printStackTrace();
     cleanUp(true);
   }
 }
示例#22
0
 public static void create() {
   try {
     Display.create();
     Mouse.create();
     Keyboard.create();
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
示例#23
0
文件: Game.java 项目: Woutwo/Project1
  public void start() {
    try {
      Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
      Display.create();
      Display.setFullscreen(true);
    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(0);
    }

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_ALPHA);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    GL11.glClearAccum(0f, 0f, 0f, 1f);
    GL11.glClear(GL11.GL_ACCUM_BUFFER_BIT);

    while (!Display.isCloseRequested() && !finished) {
      if (System.currentTimeMillis() - time > 1000) {
        System.out.println(framecount + " FPS");
        time = System.currentTimeMillis();
        framecount = 0;
      }

      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

      GL11.glColor3f(1, 1, 1);

      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glLoadIdentity();
      GL11.glOrtho(0, WIDTH, HEIGHT, 0, -10, 10);
      Manager.DrawBackground();

      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glLoadIdentity();
      GL11.glOrtho(0, WIDTH, HEIGHT, 0, -10, 10);

      GL11.glTranslatef(-Camera.x, -Camera.y, 0);
      Display.sync(60);

      Manager.Draw();
      Manager.Update();

      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glLoadIdentity();
      GL11.glOrtho(0, WIDTH, HEIGHT, 0, -10, 10);
      Manager.DrawForeground();

      Display.update();

      framecount++;
    }
  }
示例#24
0
 public MouseHelper(Component p_i174_1_) {
   field_1115_e = 10;
   field_1117_c = p_i174_1_;
   IntBuffer intbuffer = GLAllocation.func_1125_c(1);
   intbuffer.put(0);
   intbuffer.flip();
   IntBuffer intbuffer1 = GLAllocation.func_1125_c(1024);
   try {
     field_1116_d = new Cursor(32, 32, 16, 16, 1, intbuffer1, intbuffer);
   } catch (LWJGLException lwjglexception) {
     lwjglexception.printStackTrace();
   }
 }
示例#25
0
 private void initializeOpenGL() {
   // Open the program window
   try {
     PixelFormat pf = new PixelFormat(24, 8, 24, 0, 16);
     Display.setDisplayMode(new DisplayMode(boxWidth, boxHeight));
     Display.setTitle("Particles");
     Display.setVSyncEnabled(true);
     Display.create(pf);
   } catch (LWJGLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
示例#26
0
  public Main() {
    try {
      Display.setDisplayMode(new DisplayMode(800, 600));
      Display.create();

      while (!Display.isCloseRequested()) {
        Display.update();
      }

      Display.destroy();
    } catch (LWJGLException e) {
      e.printStackTrace();
    }
  }
示例#27
0
 public static void setFullscreen(boolean fullscreen) {
   try {
     if (fullscreen) {
       displayMode = Display.getDisplayMode();
       Display.setDisplayMode(Display.getDesktopDisplayMode());
     } else {
       Display.setDisplayMode(displayMode);
     }
     Display.setFullscreen(fullscreen);
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
示例#28
0
  public void initGL() {
    // Setup Display
    try {
      if (display_parent != null) {
        Display.setParent(display_parent);
      }
      Display.setDisplayMode(new DisplayMode(1000, 1000));
      Display.create(new PixelFormat(24, 8, 24, 0, 0));
      Display.setTitle("JGE3d");

      // Create a fullscreen window with 1:1 orthographic 2D projection
      // (default)
      Display.setFullscreen(false);

      // Enable vsync if we can (due to how OpenGL works, it cannot be
      // guarenteed to always work)
      // TODO: Make Configurable by User
      Display.setVSyncEnabled(true);
    } catch (LWJGLException e) {
      e.printStackTrace();
    }
    window_manager = new WindowManager();

    // camera = (Camera) objectList.getItem(Camera.CAMERA_NAME);

    setPerspective();

    // Set default openGL for drawing
    // GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    GL11.glClearDepth(1.0f);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LEQUAL);

    // Initialize default settings
    ByteBuffer temp = ByteBuffer.allocateDirect(16);
    temp.order(ByteOrder.nativeOrder());

    if (GLContext.getCapabilities().GL_ARB_vertex_buffer_object) {
      supports_vbo = true;
    } else {
      supports_vbo = false;
    }

    // Blending functions so we can have transparency
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_BLEND);
  }
示例#29
0
  public static void createDisplay() {

    ContextAttribs attribs =
        new ContextAttribs(3, 2).withForwardCompatible(true).withProfileCore(true);

    try {
      Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
      Display.create(new PixelFormat(), attribs);
      Display.setTitle(TITLE);
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    GL11.glViewport(0, 0, WIDTH, HEIGHT);
    lastFrameTime = getCurrentTime();
  }
示例#30
0
  private void execute() {
    try {
      init();
      initBroadcasting();
    } catch (LWJGLException le) {
      le.printStackTrace();
      System.out.println("Failed to initialize Gears.");
      return;
    }

    loop();

    shutdownChat();
    shutdownBroadcasting();
    destroy();
  }