コード例 #1
0
ファイル: Codenav.java プロジェクト: Haynesy/Codenav
  private void run() {

    int frames = 0;
    double nsPerFrame = 1000000000.0 / 60.0;
    double unProcessed = 0;
    long lastFrameTime = System.nanoTime();
    long currentFrameTime = System.currentTimeMillis();

    while (running) {
      long now = System.nanoTime();
      unProcessed += (now - lastFrameTime) / nsPerFrame;
      lastFrameTime = now;

      if (Display.isCloseRequested()) running = false;

      while (unProcessed > 1) {
        unProcessed -= 1;
        tick();
        display.render();
      }

      frames++;

      if (System.currentTimeMillis() - currentFrameTime > 1000) {
        currentFrameTime += 1000;
        // Print.line(frames + " fps");
        Display.setTitle(frames + " fps");
        frames = 0;
      }
      Display.sync(60);
      Display.update();
    }

    Display.destroy();
  }
コード例 #2
0
ファイル: Codenav.java プロジェクト: Haynesy/Codenav
  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);
  }
コード例 #3
0
ファイル: Gears.java プロジェクト: RELO4D3D/sdk-dist
  private void submitFrame() {
    if (!broadcastController.getIsBroadcasting() || broadcastController.getIsPaused()) {
      return;
    }

    long curTime = System.nanoTime();
    long nanoPerFrame = 1000000000 / broadcastFramesPerSecond;

    // If you send frames too quickly to the SDK (based on the broadcast FPS you configured) it will
    // not be able
    // to make use of them all.  In that case, it will simply release buffers without using them
    // which means the
    // game wasted time doing the capture.  To mitigate this, the app should pace the captures to
    // the broadcast FPS.
    long captureDelta = curTime - lastCaptureTime;
    boolean isTimeForNextCapture = captureDelta >= nanoPerFrame;

    if (!isTimeForNextCapture) {
      return;
    }

    FrameBuffer buffer = broadcastController.getNextFreeBuffer();
    broadcastController.captureFrameBuffer_ReadPixels(buffer);
    broadcastController.submitFrame(buffer);

    lastCaptureTime = curTime;
  }
コード例 #4
0
ファイル: OSSpecifics.java プロジェクト: Osoldier/HeS
 static {
   String system = System.getProperty("os.name").toLowerCase();
   OSX = system.indexOf("mac") >= 0;
   WIN = system.indexOf("win") >= 0;
   LINUX = system.indexOf("nux") >= 0 | system.indexOf("nix") >= 0 | system.indexOf("aix") >= 0;
   assert ((WIN && !OSX && !LINUX) || (!WIN && OSX && !LINUX) || (!WIN && !OSX && LINUX));
 }
コード例 #5
0
  protected boolean insertCharacter(char charTyped) {

    if (isAllowedCharacter(charTyped)) {

      if (selectionStart != selectionEnd) {
        if (caret == selectionStart) {
          ++caret;
        }
        text[selectionStart++] = charTyped;
        return true;
      }

      if ((caretInsert && caret == text.length) || textLength == text.length) {
        return false;
      }

      if (!caretInsert) {
        if (caret < textLength) {
          System.arraycopy(text, caret, text, caret + 1, textLength - caret);
        }
        ++textLength;
      }
      text[caret++] = charTyped;
      return true;
    } else {
      return true;
    }
  }
コード例 #6
0
  @Override
  protected void init() {
    initializeProgram();

    try {
      cylinderMesh = new Mesh("UnitCylinder.xml");
      planeMesh = new Mesh("LargePlane.xml");
    } catch (Exception exception) {
      exception.printStackTrace();
      System.exit(-1);
    }

    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);
    glFrontFace(GL_CW);

    glEnable(GL_DEPTH_TEST);
    glDepthMask(true);
    glDepthFunc(GL_LEQUAL);
    glDepthRange(0.0f, 1.0f);
    glEnable(GL_DEPTH_CLAMP);

    projectionUniformBuffer = glGenBuffers();
    glBindBuffer(GL_UNIFORM_BUFFER, projectionUniformBuffer);
    glBufferData(GL_UNIFORM_BUFFER, ProjectionBlock.SIZE, GL_DYNAMIC_DRAW);

    // Bind the static buffers.
    glBindBufferRange(
        GL_UNIFORM_BUFFER, projectionBlockIndex, projectionUniformBuffer, 0, ProjectionBlock.SIZE);

    glBindBuffer(GL_UNIFORM_BUFFER, 0);
  }
コード例 #7
0
ファイル: Window.java プロジェクト: TeamField3/jTTD
 public static void setParent(Canvas canvas) {
   try {
     Display.setParent(canvas);
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
コード例 #8
0
ファイル: Window.java プロジェクト: TeamField3/jTTD
 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);
   }
 }
コード例 #9
0
ファイル: Gears.java プロジェクト: RELO4D3D/sdk-dist
  private void loop() {
    long lastFrameTime = 0;

    while (!Display.isCloseRequested()) {
      long now = System.nanoTime();
      long renderFps = 30;
      long nanoPerFrame = 1000000000 / renderFps;

      // update the animation
      if (now - lastFrameTime >= nanoPerFrame) {
        lastFrameTime = now;

        angle += 2.0f;

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glPushMatrix();
        glRotatef(view_rotx, 1.0f, 0.0f, 0.0f);
        glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
        glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);

        glPushMatrix();
        glTranslatef(-3.0f, -2.0f, 0.0f);
        glRotatef(angle, 0.0f, 0.0f, 1.0f);
        glCallList(gear1);
        glPopMatrix();

        glPushMatrix();
        glTranslatef(3.1f, -2.0f, 0.0f);
        glRotatef(-2.0f * angle - 9.0f, 0.0f, 0.0f, 1.0f);
        glCallList(gear2);
        glPopMatrix();

        glPushMatrix();
        glTranslatef(-3.1f, 4.2f, 0.0f);
        glRotatef(-2.0f * angle - 25.0f, 0.0f, 0.0f, 1.0f);
        glCallList(gear3);
        glPopMatrix();

        glPopMatrix();

        Display.update();
      }

      handleInput();

      if (broadcastController != null) {
        submitFrame();
        broadcastController.update();
      }

      if (chatController != null) {
        chatController.update();
      }
    }
  }
コード例 #10
0
 public ElementTextField setMaxLength(short limit) {
   char[] oldText = text;
   text = new char[limit];
   textLength = Math.min(limit, textLength);
   if (oldText != null) {
     System.arraycopy(oldText, 0, text, 0, textLength);
   }
   findRenderStart();
   return this;
 }
コード例 #11
0
ファイル: Window.java プロジェクト: TeamField3/jTTD
 public static void create() {
   try {
     Display.create();
     Mouse.create();
     Keyboard.create();
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
コード例 #12
0
ファイル: Sprite.java プロジェクト: mewGit/alp5_game
 public Sprite(TextureLoader loader, String ref, int x, int y, int w, int h) {
   try {
     texture = loader.getTexture(ref, GL_TEXTURE_2D, GL_RGBA, GL_LINEAR, GL_LINEAR, x, y, w, h);
     width = texture.getImageWidth();
     height = texture.getImageHeight();
   } catch (IOException ioe) {
     ioe.printStackTrace();
     System.exit(-1);
   }
 }
コード例 #13
0
  @Override
  public void handleOutput(List<Entity> collection) {
    if (getInputCloseSignal()) // read input
    System.exit(0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    for (Entity e : collection) render(e);
    Display.sync(FPS); // sync to fps
    Display.update(); // update the view/screen
  }
コード例 #14
0
  private static void killAll() {
    // Kill any waiting threads
    for (Thread t : Thread.getAllStackTraces().keySet()) {
      if (t.getState() == Thread.State.WAITING && !t.getName().contains("Disposer")) {
        t.interrupt();
      }
    }

    System.exit(0); // Exit
  }
コード例 #15
0
ファイル: Sprite.java プロジェクト: mewGit/alp5_game
 /**
  * Create a new sprite from a specified image.
  *
  * @param loader the texture loader to use
  * @param ref A reference to the image on which this sprite should be based
  */
 public Sprite(TextureLoader loader, String ref) {
   try {
     texture = loader.getTexture(ref);
     width = texture.getImageWidth();
     height = texture.getImageHeight();
   } catch (IOException ioe) {
     ioe.printStackTrace();
     System.exit(-1);
   }
 }
コード例 #16
0
  public static void main(String[] args) {
    try {
      Display.setDisplayMode(new DisplayMode(640, 480));
      Display.setTitle("Timer Demo");
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
      Display.destroy();
      System.exit(1);
    }

    int x = 100;
    int y = 100;
    int dx = 1;
    int dy = 1;

    // Initialization code OpenGL
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 640, 480, 0, 1, -1);
    glMatrixMode(GL_MODELVIEW);

    lastFrame = getTime();

    while (!Display.isCloseRequested()) {
      // Render

      glClear(GL_COLOR_BUFFER_BIT);

      double delta = getDelta();
      x += delta * dx * 0.1;
      y += delta * dy * 0.1;

      glRecti(x, y, x + 30, y + 30);

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

    Display.destroy();
    System.exit(0);
  }
コード例 #17
0
ファイル: TrueTypeFont.java プロジェクト: tyty5949/SwingGL
  /**
   * The constructor that creates the font from the given file at the given height.
   *
   * @param filePath - The path to file including the file type
   * @param fontHeight - The height (size) of the font
   */
  public TrueTypeFont(String filePath, int fontHeight) {
    this.fontHeight = fontHeight;

    long startTime = 0L;
    if (Debug.enabled) startTime = System.nanoTime();

    textureID = glGenTextures();
    cdata = STBTTBakedChar.mallocBuffer(96);

    try {
      ByteBuffer ttf = IOUtil.ioResourceToByteBuffer(filePath, 160 * 1024);

      ByteBuffer bitmap = BufferUtils.createByteBuffer(BITMAP_W * BITMAP_H);
      STBTruetype.stbtt_BakeFontBitmap(ttf, fontHeight, bitmap, BITMAP_W, BITMAP_H, 32, cdata);

      glBindTexture(GL_TEXTURE_2D, textureID);
      glTexImage2D(
          GL_TEXTURE_2D, 0, GL_ALPHA, BITMAP_W, BITMAP_H, 0, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    xbuf = BufferUtils.createFloatBuffer(1);
    ybuf = BufferUtils.createFloatBuffer(1);
    quad = STBTTAlignedQuad.malloc();

    if (Debug.enabled) {
      long endTime = System.nanoTime();
      Debug.println(
          " Loaded font: "
              + filePath
              + "\n\tFont height: "
              + fontHeight
              + "px"
              + "\n\tLoad time: "
              + Debug.noNotation.format((endTime - startTime) / 1000000000.0)
              + "s",
          Debug.ANSI_CYAN);
    }
  }
コード例 #18
0
ファイル: OBJLoader.java プロジェクト: AlexandreRio/JGame
 /**
  * @param path Path of the .obj file
  * @param index GLUint
  */
 public static void name(String path, int index) {
   int list = glGenLists(index);
   glNewList(list, GL_COMPILE);
   {
     Model m = null;
     try {
       m = OBJLoader.loadModel(new File(path));
     } catch (FileNotFoundException e) {
       e.printStackTrace();
       Display.destroy();
       System.exit(1);
     } catch (IOException e) {
       e.printStackTrace();
       Display.destroy();
       System.exit(1);
     }
     float b;
     //			glColor3f(0.3f, 0.20f, 0.13f);
     b = (float) Math.random();
     glColor3f(b, 0, 0);
     int count = 0;
     glBegin(GL_TRIANGLES);
     for (Face face : m.faces) {
       count++;
       Vector3f n1 = m.normals.get((int) face.normal.x - 1);
       glNormal3f(n1.x, n1.y, n1.z);
       Vector3f v1 = m.vertices.get((int) face.vertex.x - 1);
       glVertex3f(v1.x, v1.y, v1.z);
       Vector3f n2 = m.normals.get((int) face.normal.y - 1);
       glNormal3f(n2.x, n2.y, n2.z);
       Vector3f v2 = m.vertices.get((int) face.vertex.y - 1);
       glVertex3f(v2.x, v2.y, v2.z);
       Vector3f n3 = m.normals.get((int) face.normal.z - 1);
       glNormal3f(n3.x, n3.y, n3.z);
       Vector3f v3 = m.vertices.get((int) face.vertex.z - 1);
       glVertex3f(v3.x, v3.y, v3.z);
     }
     glEnd();
     System.out.println(count);
   }
   glEndList();
 }
コード例 #19
0
ファイル: Texture.java プロジェクト: Kiwuser/3DGameEngine
  private static TextureResource loadTexture(String fileName) {
    String[] splitArray = fileName.split("\\.");
    String ext = splitArray[splitArray.length - 1];

    try {
      BufferedImage image = ImageIO.read(new File("./res/textures/" + fileName));
      int[] pixels =
          image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth());

      ByteBuffer buffer = Util.createByteBuffer(image.getHeight() * image.getWidth() * 4);
      boolean hasAlpha = image.getColorModel().hasAlpha();

      for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
          int pixel = pixels[y * image.getWidth() + x];

          buffer.put((byte) ((pixel >> 16) & 0xFF));
          buffer.put((byte) ((pixel >> 8) & 0xFF));
          buffer.put((byte) ((pixel) & 0xFF));
          if (hasAlpha) buffer.put((byte) ((pixel >> 24) & 0xFF));
          else buffer.put((byte) (0xFF));
        }
      }

      buffer.flip();

      TextureResource resource = new TextureResource();
      glBindTexture(GL_TEXTURE_2D, resource.getId());

      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

      glTexImage2D(
          GL_TEXTURE_2D,
          0,
          GL_RGBA8,
          image.getWidth(),
          image.getHeight(),
          0,
          GL_RGBA,
          GL_UNSIGNED_BYTE,
          buffer);

      return resource;
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }

    return null;
  }
コード例 #20
0
 private static void setUpDisplay() {
   try {
     Display.setDisplayMode(new DisplayMode(640, 480));
     Display.setVSyncEnabled(true);
     Display.setTitle("Core Lighting Demo");
     Display.create();
   } catch (LWJGLException e) {
     System.err.println("The display wasn't initialized correctly. :(");
     Display.destroy();
     System.exit(1);
   }
 }
コード例 #21
0
  protected void clearSelection() {

    if (selectionStart != selectionEnd) {
      if (selectionEnd < textLength) {
        System.arraycopy(text, selectionEnd, text, selectionStart, textLength - selectionEnd);
      }
      textLength -= selectionEnd - selectionStart;

      selectionEnd = caret = selectionStart;
      findRenderStart();
    }
  }
コード例 #22
0
  @Override
  protected void init() {
    initializePrograms();

    try {
      realHallway = new Mesh("RealHallway.xml");
      fauxHallway = new Mesh("FauxHallway.xml");
    } catch (Exception exception) {
      exception.printStackTrace();
      System.exit(-1);
    }
  }
コード例 #23
0
ファイル: ClothSim.java プロジェクト: dshen36/GATECH
 /**
  * Application init
  *
  * @param args Commandline args
  */
 public static void main(String[] args) {
   try {
     init(false);
     run();
   } catch (Exception e) {
     e.printStackTrace(System.err);
     Sys.alert(GAME_TITLE, "An error occured and the game will exit.");
   } finally {
     cleanup();
   }
   System.exit(0);
 }
コード例 #24
0
ファイル: Main.java プロジェクト: Osoldier/Vox
  public void run() {
    init();
    engine = new Engine();

    long lastTime = System.nanoTime();
    double delta = 0.0;
    // Amout of nanoseconds in 1/60th of a second
    double ns = 1000000000.0 / 60.0;
    long timer = System.currentTimeMillis();
    int updates = 0;
    int frames = 0;
    while (running) {
      long now = System.nanoTime();
      delta += (now - lastTime) / ns;
      lastTime = now;
      // if delta >= than one then the amount of time >= 1/60th of a second
      if (delta >= 1.0) {
        update();
        updates++;
        delta--;
      }
      render();
      frames++;
      // If a second has passed, we print the stats
      if (System.currentTimeMillis() - timer > 1000) {
        timer += 1000;
        System.out.println(updates + " ups, " + frames + " fps");
        updates = 0;
        frames = 0;
      }
      if (glfwWindowShouldClose(window) == GL_TRUE) running = false;
    }
    engine.CleanUp();
    keyCallback.release();
    sizeCallback.release();
    mouseCallback.release();
    focusCallback.release();
    glfwDestroyWindow(window);
    glfwTerminate();
  }
コード例 #25
0
  public static void main(String[] args) {
    try {
      Display.setDisplayMode(new DisplayMode(640, 480));
      Display.setTitle("Immediate Mode Demo");
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
      Display.destroy();
      System.exit(1);
    }

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(1, 1, 1, 1, 1, -1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    while (!Display.isCloseRequested()) {
      glClear(GL_COLOR_BUFFER_BIT);

      glBegin(GL_TRIANGLES);
      {
        glColor3f(1, 0, 0);
        glVertex2f(-0.5f, -0.5f);
        glColor3f(0, 1, 0);
        glVertex2f(0.5f, -0.5f);
        glColor3f(0, 0, 1);
        glVertex2f(0.5f, 0.5f);
      }
      glEnd();

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

    Display.destroy();
    System.exit(0);
  }
コード例 #26
0
 public static void main(String[] args) {
   setUpDisplay();
   setUpDisplayLists();
   setUpCamera();
   setUpLighting();
   while (!Display.isCloseRequested()) {
     render();
     checkInput();
     Display.update();
     Display.sync(60);
   }
   cleanUp();
   System.exit(0);
 }
コード例 #27
0
ファイル: Window.java プロジェクト: TeamField3/jTTD
 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
 private static void setUpVBOs() {
   int[] vbos;
   try {
     model = OBJLoader.loadModel(new File(MODEL_LOCATION));
     vbos = OBJLoader.createVBO(model);
     vboVertexHandle = vbos[0];
     vboNormalHandle = vbos[1];
   } catch (FileNotFoundException e) {
     e.printStackTrace();
     cleanUp();
     System.exit(1);
   } catch (IOException e) {
     e.printStackTrace();
     cleanUp();
     System.exit(1);
   }
   glEnableClientState(GL_VERTEX_ARRAY);
   glEnableClientState(GL_NORMAL_ARRAY);
   glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
   glVertexPointer(3, GL_FLOAT, 0, 0L);
   glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
   glNormalPointer(GL_FLOAT, 0, 0L);
 }
コード例 #29
0
 public void addPoint(
     System s,
     int x,
     int y,
     int oX,
     int oY,
     float r,
     float red,
     float green,
     float blue,
     double force) {
   Point p = new Point(x, y, oX, oY, r, red, green, blue, force);
   s.addPoint(p);
 }
コード例 #30
0
ファイル: TextEditor.java プロジェクト: brainshave/OpenGLOL
  @Override
  protected void init() {
    glClearColor(0, 0, 0, 0);
    glPixelZoom(1, -1);

    try {
      for (int i = 0; i < fonts.length; ++i) {
        fonts[i] = new Font(new File(FONT_NAMES[i]), FONT_MAPS[i], width, height);
      }
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }