コード例 #1
0
  public void run() {
    if (listener == null)
      throw new IllegalStateException(
          "SystemListener is not set on context!" + "Must set with JmeContext.setSystemListner().");

    logger.log(Level.INFO, "Using LWJGL {0}", Sys.getVersion());
    if (!initInThread()) {
      logger.log(Level.SEVERE, "Display initialization failed. Cannot continue.");
      return;
    }
    while (true) {
      if (renderable.get()) {
        if (Display.isCloseRequested()) listener.requestClose(false);

        if (wasActive != Display.isActive()) {
          if (!wasActive) {
            listener.gainFocus();
            timer.reset();
            wasActive = true;
          } else {
            listener.loseFocus();
            wasActive = false;
          }
        }
      }

      runLoop();

      if (needClose.get()) break;
    }
    deinitInThread();
  }
コード例 #2
0
 public void run() {
   loadNatives();
   logger.log(Level.FINE, "Using LWJGL {0}", Sys.getVersion());
   initInThread();
   while (!needClose.get()) {
     runLoop();
   }
   deinitInThread();
 }
コード例 #3
0
ファイル: OpenGLApp.java プロジェクト: schlop/ICG-Projekt
  /**
   * Create an OpenGL application with one window. The application behavior is controlled by the
   * <code>App</code> object.
   *
   * @param title The string that is displayed in the title bar of the application window.
   * @param multisampling Multisampling is used if true. May not work on all platforms.
   * @param application The application object.
   */
  public OpenGLApp(String title, App application, boolean multisampling) {
    this.title = title;
    this.application = application;
    this.multisampling = multisampling && System.getProperty("os.name").equals("Mac OS X");

    System.out.println(
        "LWJGL version "
            + Sys.getVersion()
            + " running on "
            + System.getProperty("os.name")
            + " version "
            + System.getProperty("os.version")
            + ".");
  }
コード例 #4
0
ファイル: HelloWorld.java プロジェクト: codemonkeyrich/myGit
  public void run() {
    System.out.println("Hello LWJGL " + Sys.getVersion() + "!");

    try {
      init();
      loop();

      // Release window and window callbacks
      glfwDestroyWindow(window);
      keyCallback.release();
    } finally {
      // Terminate GLFW and release the GLFWerrorfun
      glfwTerminate();
      errorCallback.release();
    }
  }
コード例 #5
0
  private static void checkOpenGlCaps() {
    log("");
    log(getVersion());
    log("" + new Date());
    log(
        "OS: "
            + System.getProperty("os.name")
            + " ("
            + System.getProperty("os.arch")
            + ") version "
            + System.getProperty("os.version"));
    log("Java: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor"));
    log(
        "VM: "
            + System.getProperty("java.vm.name")
            + " ("
            + System.getProperty("java.vm.info")
            + "), "
            + System.getProperty("java.vm.vendor"));
    log("LWJGL: " + Sys.getVersion());
    log(
        "OpenGL: "
            + GL11.glGetString(GL11.GL_RENDERER)
            + " version "
            + GL11.glGetString(GL11.GL_VERSION)
            + ", "
            + GL11.glGetString(GL11.GL_VENDOR));
    int var0 = getOpenGlVersion();
    String var1 = "" + var0 / 10 + "." + var0 % 10;
    log("OpenGL Version: " + var1);

    if (!GLContext.getCapabilities().OpenGL12) {
      log("OpenGL Mipmap levels: Not available (GL12.GL_TEXTURE_MAX_LEVEL)");
    }

    if (!GLContext.getCapabilities().GL_NV_fog_distance) {
      log("OpenGL Fancy fog: Not available (GL_NV_fog_distance)");
    }

    if (!GLContext.getCapabilities().GL_ARB_occlusion_query) {
      log("OpenGL Occlussion culling: Not available (GL_ARB_occlusion_query)");
    }
  }
コード例 #6
0
  protected void printContextInitInfo() {
    logger.log(
        Level.INFO,
        "Lwjgl {0} context running on thread {1}",
        new Object[] {Sys.getVersion(), Thread.currentThread().getName()});

    logger.log(Level.INFO, "Adapter: {0}", Display.getAdapter());
    logger.log(Level.INFO, "Driver Version: {0}", Display.getVersion());

    String vendor = GL11.glGetString(GL11.GL_VENDOR);
    logger.log(Level.INFO, "Vendor: {0}", vendor);

    String version = GL11.glGetString(GL11.GL_VERSION);
    logger.log(Level.INFO, "OpenGL Version: {0}", version);

    String renderGl = GL11.glGetString(GL11.GL_RENDERER);
    logger.log(Level.INFO, "Renderer: {0}", renderGl);

    if (GLContext.getCapabilities().OpenGL20) {
      String shadingLang = GL11.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION);
      logger.log(Level.INFO, "GLSL Ver: {0}", shadingLang);
    }
  }
コード例 #7
0
 /**
  * Gets the LWJGL Version
  *
  * @return LWJGL Version
  */
 public static String getLWJGLVersion() {
   return Sys.getVersion();
 }
コード例 #8
0
ファイル: Gears.java プロジェクト: RELO4D3D/sdk-dist
  private void init() throws LWJGLException {
    // create Window of size 800x600
    Display.setDisplayMode(new DisplayMode(1024, 768));
    Display.setLocation(
        (Display.getDisplayMode().getWidth() - 300) / 2,
        (Display.getDisplayMode().getHeight() - 300) / 2);
    Display.setTitle("Gears");

    try {
      Display.create();
    } catch (LWJGLException e) {
      // This COULD be because of a bug! A delay followed by a new attempt is supposed to fix it.
      e.printStackTrace();
      try {
        Thread.sleep(1000);
      } catch (InterruptedException ignored) {
      }

      Display.create();
    }

    // setup ogl
    FloatBuffer pos = BufferUtils.createFloatBuffer(4).put(new float[] {5.0f, 5.0f, 10.0f, 0.0f});
    FloatBuffer red = BufferUtils.createFloatBuffer(4).put(new float[] {0.8f, 0.1f, 0.0f, 1.0f});
    FloatBuffer green = BufferUtils.createFloatBuffer(4).put(new float[] {0.0f, 0.8f, 0.2f, 1.0f});
    FloatBuffer blue = BufferUtils.createFloatBuffer(4).put(new float[] {0.2f, 0.2f, 1.0f, 1.0f});

    pos.flip();
    red.flip();
    green.flip();
    blue.flip();

    glLight(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_CULL_FACE);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_DEPTH_TEST);

    /* make the gears */
    gear1 = glGenLists(1);
    glNewList(gear1, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
    gear(1.0f, 4.0f, 1.0f, 20, 0.7f);
    glEndList();

    gear2 = glGenLists(1);
    glNewList(gear2, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
    gear(0.5f, 2.0f, 2.0f, 10, 0.7f);
    glEndList();

    gear3 = glGenLists(1);
    glNewList(gear3, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
    gear(1.3f, 2.0f, 0.5f, 10, 0.7f);
    glEndList();

    glEnable(GL_NORMALIZE);

    glMatrixMode(GL_PROJECTION);

    System.err.println("LWJGL: " + Sys.getVersion() + " / " + LWJGLUtil.getPlatformName());
    System.err.println("GL_VENDOR: " + glGetString(GL_VENDOR));
    System.err.println("GL_RENDERER: " + glGetString(GL_RENDERER));
    System.err.println("GL_VERSION: " + glGetString(GL_VERSION));
    System.err.println();
    System.err.println(
        "glLoadTransposeMatrixfARB() supported: "
            + GLContext.getCapabilities().GL_ARB_transpose_matrix);
    if (!GLContext.getCapabilities().GL_ARB_transpose_matrix) {
      // --- not using extensions
      glLoadIdentity();
    } else {
      // --- using extensions
      final FloatBuffer identityTranspose =
          BufferUtils.createFloatBuffer(16)
              .put(new float[] {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1});
      identityTranspose.flip();
      glLoadTransposeMatrixARB(identityTranspose);
    }

    float h = (float) 300 / (float) 300;
    glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -40.0f);
  }
コード例 #9
0
ファイル: SWTLWJGLDemo.java プロジェクト: asilchev/swt-lwjgl
  public static void main(String[] args) {
    logger.info("Use LWJGL version: {}", Sys.getVersion());
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    Composite comp = new Composite(shell, SWT.NONE);
    comp.setLayout(new FillLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;
    final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);

    canvas.setCurrent();
    GLContext.createFromCurrent();

    //		try {
    //			GLContext.useContext(canvas);
    //		} catch(LWJGLException e) { e.printStackTrace(); }

    canvas.addListener(
        SWT.Resize,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            Rectangle bounds = canvas.getBounds();
            float fAspect = (float) bounds.width / (float) bounds.height;
            canvas.setCurrent();
            GLContext.createFromCurrent();
            //				try {
            //					GLContext.useContext(canvas);
            //				} catch(LWJGLException e) { e.printStackTrace(); }
            GL11.glViewport(0, 0, bounds.width, bounds.height);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();

            // GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
          }
        });

    GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glColor3f(1.0f, 0.0f, 0.0f);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glClearDepth(1.0);
    GL11.glLineWidth(2);
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    shell.setText("SWT/LWJGL Example");
    shell.setSize(640, 480);
    shell.open();

    final Runnable run =
        new Runnable() {
          int rot = 0;

          @Override
          public void run() {
            if (!canvas.isDisposed()) {
              canvas.setCurrent();
              GLContext.createFromCurrent();
              //					try {
              //						GLContext.useContext(canvas);
              //					} catch(LWJGLException e) { e.printStackTrace(); }
              GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
              GL11.glClearColor(.3f, .5f, .8f, 1.0f);
              GL11.glLoadIdentity();
              GL11.glTranslatef(0.0f, 0.0f, -10.0f);
              float frot = rot;
              GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
              GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
              rot++;
              GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
              GL11.glColor3f(0.9f, 0.9f, 0.9f);
              drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
              canvas.swapBuffers();
              display.asyncExec(this);
            }
          }
        };
    canvas.addListener(
        SWT.Paint,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            run.run();
          }
        });
    display.asyncExec(run);

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }