Beispiel #1
0
  public static void initPerspective(int width, int height, float zClose, float zFar) {
    fov = 55.0f;

    glEnable(GL_TEXTURE_2D);

    //		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    //		glEnable(GL_TEXTURE_2D);

    //		glEnable(GL_CULL_FACE);

    //		glShadeModel(GL_SMOOTH); // Enable Smooth Shading
    glClearDepth(1.0); // Depth Buffer Setup
    glEnable(GL_DEPTH_TEST); // Enables Depth Testing
    glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do

    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
    glLoadIdentity(); // Reset The Projection Matrix

    // Calculate The Aspect Ratio Of The Window
    gluPerspective(fov, (float) width / height, zClose, zFar);
    //		glOrtho(1, 1, 1, 1, -1, 1);
    glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix

    // Really Nice Perspective Calculations
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // GL_DECAL);
  }
  /** Initialise the GL context */
  protected void initGL() {
    Log.info("Starting display " + width + "x" + height);
    String extensions = GL11.glGetString(GL11.GL_EXTENSIONS);

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);

    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    GL11.glClearDepth(1);

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    GL11.glViewport(0, 0, width, height);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    if (input == null) {
      input = new Input(height);
    }
    input.init(height);
    input.removeListener(lastGame);
    input.addListener(game);
    lastGame = game;
  }
 /* (non-Javadoc)
  * @see chu.engine.Game#loop()
  */
 @Override
 public void loop() {
   while (!Display.isCloseRequested()) {
     final long time = System.nanoTime();
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
     glClearDepth(1.0f);
     getInput();
     final ArrayList<Message> messages = new ArrayList<>();
     if (client != null) {
       synchronized (client.messagesLock) {
         messages.addAll(client.messages);
         for (Message m : messages) client.messages.remove(m);
       }
     }
     SoundStore.get().poll(0);
     glPushMatrix();
     // Global resolution scale
     //			Renderer.scale(scaleX, scaleY);
     currentStage.beginStep(messages);
     currentStage.onStep();
     currentStage.processAddStack();
     currentStage.processRemoveStack();
     currentStage.render();
     //				FEResources.getBitmapFont("stat_numbers").render(
     //						(int)(1.0f/getDeltaSeconds())+"", 440f, 0f, 0f);
     currentStage.endStep();
     glPopMatrix();
     Display.update();
     timeDelta = System.nanoTime() - time;
   }
   AL.destroy();
   Display.destroy();
   if (client != null && client.isOpen()) client.quit();
 }
 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();
 }
Beispiel #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);
  }
  /**
   * *************************************************************************************************************************************************************************************************
   * Initialization stuff comes in here...
   * ************************************************************************************************************************************************************************************************
   */
  private void init() {

    try {
      Display.setDisplayMode(new DisplayMode(640, 480));
      Display.setVSyncEnabled(true);
      Display.setTitle("MS3D Loader [G36C]");
      Display.create();

      Keyboard.create();

    } catch (LWJGLException e) {
      Sys.alert("Error", "Initialization failed!\n\n" + e.getMessage());
      System.exit(0);
    }

    /* OpenGL */
    int width = Display.getDisplayMode().getWidth();
    int height = Display.getDisplayMode().getHeight();

    GL11.glViewport(0, 0, width, height); // Reset The Current Viewport
    GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
    GL11.glLoadIdentity(); // Reset The Projection Matrix
    GLU.gluPerspective(
        45.0f,
        ((float) width / (float) height),
        0.1f,
        1000.0f); // Calculate The Aspect Ratio Of The Window
    GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix
    GL11.glLoadIdentity(); // Reset The Modelview Matrix

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Background color
    GL11.glClearDepth(1.0f);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);

    // Load model
    //		g36c = new
    // MS3DModel(resourceLoader.loadResourceAsStream("models/gsg9.ms3d"),this.getClass().getResource("./data/textures").getPath());
    g36c =
        new MS3DModel(
            resourceLoader.loadResourceAsStream("models/assassin.ms3d"),
            this.getClass().getResource("./data/textures").getPath());

    //		tdsLoader=new TDSLoader();
    //		try {
    //			tdsLoader.load(resourceLoader.loadResourceAsStream("models/face.3ds"));
    //			System.out.println(tdsLoader.getObjectSize());
    //		} catch (IOException e) {
    //			e.printStackTrace();
    //		}

    // Load font
    font = new Font(resourceLoader.loadResourceAsStream("textures/font.bmp"), 12, width, height);

    // Init timer
    timer = new Timer();
  }
  private void initGL() {
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // sets background to grey
    glClearDepth(1.0f); // clear depth buffer
    glEnable(GL_DEPTH_TEST); // Enables depth testing
    glDepthFunc(GL_LEQUAL); // sets the type of test to use for depth testing
    glMatrixMode(GL_PROJECTION); // sets the matrix mode to project

    // GLU.gluOrtho2D(-10, 10, -10, 10);
    // GLU.gluOrtho2D(0 - COORD_WIDTH / 2, 0 + COORD_WIDTH / 2, 0 - COORD_HEIGHT / 2, 0 +
    // COORD_HEIGHT / 2);
    float fovy = 90.0f;
    float aspect = DISPLAY_MODE.getWidth() / (float) DISPLAY_MODE.getHeight();
    float zNear = 0.1f;
    float zFar = 20000.0f;
    GLU.gluPerspective(fovy, aspect, zNear, zFar);

    glViewport(0, 0, DISPLAY_MODE.getWidth(), DISPLAY_MODE.getHeight());
    // GLU.gluOrtho2D(-10, 10, -10, 10);
    // GLU.gluOrtho2D(-1, 1, -1, 1);

    glOrtho(
        0 - COORD_WIDTH / 2,
        0 + COORD_WIDTH / 2,
        0 - COORD_HEIGHT / 2,
        0 + COORD_HEIGHT / 2,
        zNear,
        zFar);

    System.out.println(COORD_WIDTH + ", " + COORD_HEIGHT);

    glMatrixMode(GL_MODELVIEW);

    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    // ----------- Variables & method calls added for Lighting Test -----------//
    initLightArrays();
    glShadeModel(GL_SMOOTH);
    glMaterial(GL_FRONT, GL_SPECULAR, matSpecular); // sets specular material color
    glMaterialf(GL_FRONT, GL_SHININESS, 50.0f); // sets shininess

    glLight(GL_LIGHT0, GL_POSITION, lightPosition); // sets light position
    glLight(GL_LIGHT0, GL_SPECULAR, whiteLight); // sets specular light to white
    glLight(GL_LIGHT0, GL_DIFFUSE, whiteLight); // sets diffuse light to white
    glLightModel(GL_LIGHT_MODEL_AMBIENT, lModelAmbient); // global ambient light

    glEnable(GL_LIGHTING); // enables lighting
    glEnable(GL_LIGHT0); // enables light0

    glEnable(GL_COLOR_MATERIAL); // enables opengl to use glColor3f to define material color
    glColorMaterial(
        GL_FRONT,
        GL_AMBIENT_AND_DIFFUSE); // tell opengl glColor3f effects the ambient and diffuse properties
                                 // of material
    // ----------- END: Variables & method calls added for Lighting Test -----------//

  }
Beispiel #8
0
  private void doRenderLoop() {
    try {
      while (!isDisplayable()) {
        Thread.sleep(50);
      }
      Display.setParent(this);
      Display.setVSyncEnabled(true);
      Display.create();
      mMouseState = new boolean[Mouse.getButtonCount()];
      for (int i = 0; i < mMouseState.length; i++) {
        mMouseState[i] = Mouse.isButtonDown(i);
      }

      // GL11.glsetSwapInterval(1);
      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);
      if (mScene.getAmbientLight() != null) {
        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glLightModel(
            GL11.GL_LIGHT_MODEL_AMBIENT, Color4fLogic.toFloatBuffer(mScene.getAmbientLight()));
      }
      if (mScene.getColorMaterialFace() != JGLColorMaterialFace.UNSET) {
        initMaterial();
      }
      if (mScene.getFogMode() != JGLFogMode.UNSET) {
        initFog();
      }

      Dimension newDim;

      while (!Display.isCloseRequested() && !mCloseRequested) {
        newDim = mNewCanvasSize.getAndSet(null);
        if (newDim != null) {
          GL11.glViewport(0, 0, newDim.width, newDim.height);
          syncViewportSize();
        }
        doRender();
        doMouse();
        doKeys();
        doEye();
        Display.update();
      }

      Display.destroy();
    } catch (InterruptedException | LWJGLException e) {
      e.printStackTrace();
    }
  }
Beispiel #9
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);
  }
Beispiel #10
0
 public static void initOpenGL() {
   GLPrep.resizedRefresh();
   GL11.glEnable(GL11.GL_ALPHA_TEST); // allows alpha channels or
   // transperancy
   GL11.glAlphaFunc(GL11.GL_GREATER, 0.1f); // set alpha aceptance
   GL11.glEnable(GL11.GL_COLOR_MATERIAL);
   GL11.glDisable(GL11.GL_DITHER);
   GL11.glShadeModel(GL11.GL_SMOOTH); // smooth shading
   GL11.glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
   GL11.glDepthMask(true); // turn on depth mask
   GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
   GL11.glDepthFunc(GL11.GL_ALWAYS); // The Type Of Depth Test To Do
   GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
   GL11.glEnable(GL11.GL_TEXTURE_2D); // enable 2d textures
   RenderManager.registerRenders();
 }
  @Override
  public void draw(GameTime gameTime) {
    GL11.glClearColor(0, 0, 0, 0);
    GL11.glClearDepth(1.0);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    RasterizerState.CULL_CLOCKWISE.set();
    BlendState.OPAQUE.set();
    DepthState.DEFAULT.set();

    program.use();
    texture.use(TextureUnit.Texture0, program.getUniform("Texture"));
    vb.useAsAttrib(fxsi);
    ib.bind();
    GL11.glDrawElements(PrimitiveType.Triangles, 6, GLType.UnsignedInt, 0);
    ib.unbind();
    texture.unuse();
    GLProgram.unuse();

    if (!savedImage) {
      int sw = game.getWidth();
      int sh = game.getHeight();
      ByteBuffer pb = NativeMem.createByteBuffer(sw * sh * 4);
      GL11.glReadPixels(0, 0, sw, sh, PixelFormat.Rgba, GLType.UnsignedByte, pb);
      pb.position(0);
      pb.limit(sw * sh * 4);

      byte[] cb = new byte[4];
      BufferedImage im = new BufferedImage(sw, sh, BufferedImage.TYPE_INT_ARGB);
      for (int y = sh - 1; y >= 0; y--) {
        for (int x = 0; x < sw; x++) {
          pb.get(cb);
          im.setRGB(
              x, y, (cb[2] & 0xFF) | ((cb[1] & 0xFF) << 8) | ((cb[0] & 0xFF) << 16) | 0xFF000000);
        }
      }

      try {
        ImageIO.write(im, "png", new File("Diag.png"));
        System.out.println("Image Has Been Saved");
      } catch (IOException e) {
        System.out.println(e.getMessage());
      }

      savedImage = true;
    }
  }
Beispiel #12
0
 public static void setupView(int width, int height) {
   glPopAttrib();
   glPushAttrib(GL_ENABLE_BIT);
   glEnable(GL_TEXTURE_2D);
   glEnable(GL_BLEND);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   setupLighting();
   glClearDepth(1D);
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_CULL_FACE);
   glDepthFunc(GL_LEQUAL);
   glViewport(0, 0, width, height);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   gluPerspective(60F, (float) width / height, 0.1F, 1000F);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
 }
Beispiel #13
0
  public void render(int delta) {
    glClearColor(0.5f, 0.5f, 0.8f, 1.0f);
    glClearDepth(1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    update();

    // Like a cake, this has layers. We want ground at the bottom so it goes first.
    for (AbstractEntity e : Window.ground) {
      e.draw();
    }
    for (AbstractEntity e : Window.entities) {
      e.update(delta);
      e.draw();
    }
    if (Window.leftButtonHeld) {
      drawLineBox(Window.iMouseX, Window.iMouseY, Window.mouseX, Window.mouseY, true);
    }
    renderer.flushQueue();
    drawFPS(fps);
  }
  @Override
  protected void display() {
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    if (useSmoothInterpolation) {
      glUseProgram(smoothInterp.theProgram);
    } else {
      glUseProgram(linearInterp.theProgram);
    }

    if (useFakeHallway) {
      fauxHallway.render();
    } else {
      realHallway.render();
    }

    glUseProgram(0);
  }
  public void checkPicking(Renderer renderer, RenderCamera camera, int mx, int my) {
    if (camera == null) return;

    // Pick An Object
    renderer.beginPickingPass(camera);
    renderer.drawPassesPick();
    if (currentObject != null) {
      // Draw Object Manipulators
      GL11.glClearDepth(1.0);
      GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);

      DepthState.DEFAULT.set();
      BlendState.OPAQUE.set();
      RasterizerState.CULL_NONE.set();

      drawPick(camera, currentObject, renderer.pickProgram);
    }
    int id = renderer.getPickID(Mouse.getX(), Mouse.getY());

    selectedManipulator = manips.get(id);
    if (selectedManipulator != null) {
      // Begin Manipulator Operations
      System.out.println(
          "Selected Manip: " + selectedManipulator.type + " " + selectedManipulator.axis);
      return;
    }

    SceneObject o = scene.objects.get(id);
    if (o != null) {
      System.out.println("Picked An Object: " + o.getID().name);
      if (scenePanel != null) {
        scenePanel.select(o.getID().name);
        propWindow.tabToForefront("Object");
      }
      currentObject = rEnv.findObject(o);
    } else if (currentObject != null) {
      currentObject = null;
    }
  }
Beispiel #16
0
  // ***************************************************************************
  // initGL
  // ***************************************************************************
  private static boolean initGL() {
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();

    // Calculate the aspect ratio of the window
    GLU.gluPerspective(45.0f, ((float) targetWidth) / ((float) targetHeight), 0.1f, 100.0f);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();

    GL11.glEnable(GL11.GL_TEXTURE_2D);

    // Enable Texture Mapping (NEW)
    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.glDepthFunc(GL11.GL_LEQUAL);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);

    return true;
  }
Beispiel #17
0
  public static void init(VorxelSettings set, Geode gamep) {
    world = new World();
    game = gamep;
    try {
      DisplayMode d[] = Display.getAvailableDisplayModes();
      DisplayMode displayMode = d[0];
      Display.setDisplayMode(displayMode);
      Display.create();

      Mouse.create();
      Keyboard.create();

      GL11.glEnable(GL11.GL_TEXTURE_2D); // Enable Texture Mapping
      GL11.glShadeModel(GL11.GL_SMOOTH); // Enable Smooth Shading
      GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
      GL11.glClearDepth(1.0); // Depth Buffer Setup
      GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
      GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do

      GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
      GL11.glLoadIdentity(); // Reset The Projection Matrix
      // Calculate The Aspect Ratio Of The Window
      GLU.gluPerspective(
          45.0f, (float) displayMode.getWidth() / (float) displayMode.getHeight(), 0.1f, 100.0f);
      GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix

      // Really Nice Perspective Calculations
      GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
      TextureHelper.init();
      Cube.dirt.texture = new VTex(4);
      Cube.grass.texture = Cube.dirt.texture;
      Cube.grass.toptexture = new VTex(1);
      Mouse.setGrabbed(true);
      world.createSpawn();
    } catch (LWJGLException e) {
      e.printStackTrace();
    }
  }
Beispiel #18
0
  @Override
  public void run() {
    double delta = 0;
    long previousTime = System.nanoTime();
    long timer = System.currentTimeMillis();
    int ups = 0;
    double nanoUpdates = 1000000000.0 / 30.0;

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);

    GL11.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);
    GL11.glClearDepth(1);

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    setupDisplay();

    boolean doResize = false;

    while (!Display.isCloseRequested()) {
      if (Display.wasResized() && doResize) {
        setupDisplay();
      }
      doResize = true;

      long currentTime = System.nanoTime();
      double currentTickDelta = (currentTime - previousTime) / nanoUpdates;
      delta += currentTickDelta;
      frameDelta = (frameDelta + currentTickDelta) % 1.0;
      previousTime = currentTime;

      while (delta >= 1) {
        update();
        renderHandler.update();
        delta--;
        ups++;
      }

      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
      GL11.glPushMatrix();

      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

      renderHandler.render();

      fps++;

      if (System.currentTimeMillis() - timer > 1000) {
        int bytesPerSecond = 0;
        int packetsPerSecond = 0;
        if (networkManager != null) {
          bytesPerSecond = networkManager.bytesPerSecond;
          packetsPerSecond = networkManager.packetsPerSecond;
          networkManager.bytesPerSecond = 0;
          networkManager.packetsPerSecond = 0;
        }
        Display.setTitle(
            "Slyther - FPS: "
                + fps
                + " - UPS: "
                + ups
                + " - BPS: "
                + bytesPerSecond
                + " - PPS: "
                + packetsPerSecond);
        fps = 0;

        timer += 1000;
        ups = 0;
      }

      GL11.glPopMatrix();
      Display.sync(60);
      Display.update();
    }
    if (networkManager != null && networkManager.isOpen()) {
      networkManager.closeConnection(ClientNetworkManager.SHUTDOWN_CODE, "");
    }
    try {
      ConfigHandler.INSTANCE.saveConfig(CONFIGURATION_FILE, configuration);
    } catch (IOException e) {
      Log.error("Failed to save config");
      Log.catching(e);
    }
    Display.destroy();
  }
Beispiel #19
0
 public void glClearDepthf(float depth) {
   GL11.glClearDepth(depth);
 }
Beispiel #20
0
 public void startGame() throws LWJGLException {
   if (mcCanvas != null) {
     Graphics g = mcCanvas.getGraphics();
     if (g != null) {
       g.setColor(Color.BLACK);
       g.fillRect(0, 0, displayWidth, displayHeight);
       g.dispose();
     }
     Display.setParent(mcCanvas);
   } else if (fullscreen) {
     Display.setFullscreen(true);
     displayWidth = Display.getDisplayMode().getWidth();
     displayHeight = Display.getDisplayMode().getHeight();
     if (displayWidth <= 0) {
       displayWidth = 1;
     }
     if (displayHeight <= 0) {
       displayHeight = 1;
     }
   } else {
     Display.setDisplayMode(new DisplayMode(displayWidth, displayHeight));
   }
   Display.setTitle("Minecraft Minecraft Beta 1.7.3");
   try {
     Display.create();
   } catch (LWJGLException lwjglexception) {
     lwjglexception.printStackTrace();
     try {
       Thread.sleep(1000L);
     } catch (InterruptedException interruptedexception) {
     }
     Display.create();
   }
   mcDataDir = getMinecraftDir();
   saveLoader = new SaveConverterMcRegion(new File(mcDataDir, "saves"));
   gameSettings = new GameSettings(this, mcDataDir);
   texturePackList = new TexturePackList(this, mcDataDir);
   renderEngine = new RenderEngine(texturePackList, gameSettings);
   fontRenderer = new FontRenderer(gameSettings, "/font/default.png", renderEngine);
   ColorizerWater.func_28182_a(renderEngine.func_28149_a("/misc/watercolor.png"));
   ColorizerGrass.func_28181_a(renderEngine.func_28149_a("/misc/grasscolor.png"));
   ColorizerFoliage.func_28152_a(renderEngine.func_28149_a("/misc/foliagecolor.png"));
   entityRenderer = new EntityRenderer(this);
   RenderManager.instance.itemRenderer = new ItemRenderer(this);
   statFileWriter = new StatFileWriter(session, mcDataDir);
   AchievementList.openInventory.setStatStringFormatter(new StatStringFormatKeyInv(this));
   loadScreen();
   Keyboard.create();
   Mouse.create();
   mouseHelper = new MouseHelper(mcCanvas);
   try {
     Controllers.create();
   } catch (Exception exception) {
     exception.printStackTrace();
   }
   checkGLError("Pre startup");
   GL11.glEnable(3553 /*GL_TEXTURE_2D*/);
   GL11.glShadeModel(7425 /*GL_SMOOTH*/);
   GL11.glClearDepth(1.0D);
   GL11.glEnable(2929 /*GL_DEPTH_TEST*/);
   GL11.glDepthFunc(515);
   GL11.glEnable(3008 /*GL_ALPHA_TEST*/);
   GL11.glAlphaFunc(516, 0.1F);
   GL11.glCullFace(1029 /*GL_BACK*/);
   GL11.glMatrixMode(5889 /*GL_PROJECTION*/);
   GL11.glLoadIdentity();
   GL11.glMatrixMode(5888 /*GL_MODELVIEW0_ARB*/);
   checkGLError("Startup");
   glCapabilities = new OpenGlCapsChecker();
   sndManager.loadSoundSettings(gameSettings);
   renderEngine.registerTextureFX(textureLavaFX);
   renderEngine.registerTextureFX(textureWaterFX);
   renderEngine.registerTextureFX(new TexturePortalFX());
   renderEngine.registerTextureFX(new TextureCompassFX(this));
   renderEngine.registerTextureFX(new TextureWatchFX(this));
   renderEngine.registerTextureFX(new TextureWaterFlowFX());
   renderEngine.registerTextureFX(new TextureLavaFlowFX());
   renderEngine.registerTextureFX(new TextureFlamesFX(0));
   renderEngine.registerTextureFX(new TextureFlamesFX(1));
   renderGlobal = new RenderGlobal(this, renderEngine);
   GL11.glViewport(0, 0, displayWidth, displayHeight);
   effectRenderer = new EffectRenderer(theWorld, renderEngine);
   try {
     downloadResourcesThread = new ThreadDownloadResources(mcDataDir, this);
     downloadResourcesThread.start();
   } catch (Exception exception1) {
   }
   checkGLError("Post startup");
   ingameGUI = new GuiIngame(this);
   if (serverName != null) {
     displayGuiScreen(new GuiConnecting(this, serverName, serverPort));
   } else {
     displayGuiScreen(new GuiMainMenu());
   }
 }
  public static void main(String[] args) {
    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();
    try {
      GLContext.useContext(canvas);
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    canvas.addListener(
        SWT.Resize,
        new Listener() {
          public void handleEvent(Event event) {
            Rectangle bounds = canvas.getBounds();
            float fAspect = (float) bounds.width / (float) bounds.height;
            canvas.setCurrent();
            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();

    display.asyncExec(
        new Runnable() {
          int rot = 0;

          public void run() {
            if (!canvas.isDisposed()) {
              canvas.setCurrent();
              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);
            }
          }
        });

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
  @Override
  protected void onStart() {
    INSTANCE = this;

    RENDER_THREAD_ID = Thread.currentThread().getId();

    try {
      loadIcons();
      Display.setIcon(icons);
      Display.setVSyncEnabled(GameSettings.Graphics.vsync);
    } catch (IOException e) {
      e.printStackTrace();
    }

    try {
      setDisplayMode(
          GameSettings.Display.window_width,
          GameSettings.Display.window_height,
          GameSettings.Display.fullscreen);
      Display.create();
      // ROBO //todo get all this changed to proper OGL
      glClearColor(0f, 0f, 0f, 1f);
      glClearDepth(1f);
      glViewport(0, 0, GameSettings.Display.window_width, GameSettings.Display.window_height);
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();

      glOrtho(
          0.0f,
          GameSettings.Display.resolution.getWidth(),
          GameSettings.Display.resolution.getHeight(),
          0.0f,
          0.1f,
          -1f);
      glMatrixMode(GL_MODELVIEW);
      glEnable(GL_TEXTURE_2D);
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
      glLoadIdentity();
      curAlpha = 1f;
      capabilities = GLContext.getCapabilities();

      System.out.println("OpenGL version: " + glGetString(GL_VERSION));

      System.out.println("Building shaders..");
      long ms = getTime();
      ShaderFactory.buildAllShaders();
      System.out.println("Done! Took " + (getTime() - ms) + "ms.");

    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(0);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(0);
    } finally {
      if (looping) {
        looping = false;
        Display.destroy();
      }
    }

    started = getTime();
    next_tick = getTime();
    getDelta();
  }
Beispiel #23
0
  @Override
  protected void display() {
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    MatrixStack modelMatrix = new MatrixStack();
    modelMatrix.setMatrix(viewPole.calcMatrix());

    Vec4 lightDirCameraSpace = Mat4.mul(modelMatrix.top(), lightDirection);

    glUseProgram(whiteDiffuseColor.theProgram);
    glUniform3(whiteDiffuseColor.dirToLightUnif, lightDirCameraSpace.fillAndFlipBuffer(vec4Buffer));
    glUseProgram(vertexDiffuseColor.theProgram);
    glUniform3(
        vertexDiffuseColor.dirToLightUnif, lightDirCameraSpace.fillAndFlipBuffer(vec4Buffer));
    glUseProgram(0);

    {
      modelMatrix.push();

      // Render the ground plane.
      {
        modelMatrix.push();

        glUseProgram(whiteDiffuseColor.theProgram);
        glUniformMatrix4(
            whiteDiffuseColor.modelToCameraMatrixUnif,
            false,
            modelMatrix.top().fillAndFlipBuffer(mat4Buffer));
        Mat3 normMatrix = new Mat3(modelMatrix.top());
        glUniformMatrix3(
            whiteDiffuseColor.normalModelToCameraMatrixUnif,
            false,
            normMatrix.fillAndFlipBuffer(mat3Buffer));
        glUniform4f(whiteDiffuseColor.lightIntensityUnif, 1.0f, 1.0f, 1.0f, 1.0f);
        planeMesh.render();
        glUseProgram(0);

        modelMatrix.pop();
      }

      // Render the Cylinder
      {
        modelMatrix.push();

        modelMatrix.applyMatrix(objtPole.calcMatrix());

        if (drawColoredCyl) {
          glUseProgram(vertexDiffuseColor.theProgram);
          glUniformMatrix4(
              vertexDiffuseColor.modelToCameraMatrixUnif,
              false,
              modelMatrix.top().fillAndFlipBuffer(mat4Buffer));
          Mat3 normMatrix = new Mat3(modelMatrix.top());
          glUniformMatrix3(
              vertexDiffuseColor.normalModelToCameraMatrixUnif,
              false,
              normMatrix.fillAndFlipBuffer(mat3Buffer));
          glUniform4f(vertexDiffuseColor.lightIntensityUnif, 1.0f, 1.0f, 1.0f, 1.0f);
          cylinderMesh.render("lit-color");
        } else {
          glUseProgram(whiteDiffuseColor.theProgram);
          glUniformMatrix4(
              whiteDiffuseColor.modelToCameraMatrixUnif,
              false,
              modelMatrix.top().fillAndFlipBuffer(mat4Buffer));
          Mat3 normMatrix = new Mat3(modelMatrix.top());
          glUniformMatrix3(
              whiteDiffuseColor.normalModelToCameraMatrixUnif,
              false,
              normMatrix.fillAndFlipBuffer(mat3Buffer));
          glUniform4f(whiteDiffuseColor.lightIntensityUnif, 1.0f, 1.0f, 1.0f, 1.0f);
          cylinderMesh.render("lit");
        }

        glUseProgram(0);

        modelMatrix.pop();
      }

      modelMatrix.pop();
    }
  }
Beispiel #24
0
  public static void main(String[] args) {
    Window window = new Window(1280, 720, "Test", false);
    double rotAngle = 0;
    double X = 0;
    Cube cube = new Cube(0, 0, 0, 1);
    Logger log = Logger.getInstance();
    Axis axis = new Axis(0, 10, 0, 50);

    window.drawOn3D();
    // Cullface
    glCullFace(GL_BACK);
    glEnable(GL_CULL_FACE);

    // depth
    glEnable(GL_DEPTH_TEST);

    //
    glClearDepth(1.0f);
    glDepthFunc(GL_LEQUAL);
    //
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);

    while (!window.isCloseRequested()) {
      window.drawOn3D();
      // Clear the contents of the window (try disabling this and resizing the window � fun
      // guaranteed)
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

      // Polls the user input. This is very important, because it prevents your application from
      // becoming unresponsive
      glfwPollEvents();

      rotAngle = (glfwGetKey(window.getWindowID(), GLFW_KEY_RIGHT) == 1) ? rotAngle + 5 : rotAngle;
      rotAngle = (glfwGetKey(window.getWindowID(), GLFW_KEY_LEFT) == 1) ? rotAngle - 5 : rotAngle;

      X = (glfwGetKey(window.getWindowID(), GLFW_KEY_UP) == 1) ? X + .5 : X;
      X = (glfwGetKey(window.getWindowID(), GLFW_KEY_DOWN) == 1) ? X - .5 : X;

      log.debug("" + X);

      glPushMatrix();
      glTranslated(0, 0, -40 + X);
      //			glRotated(rotAngle, 0, 1, 0);

      axis.draw();
      glColor3d(0, 1, 1);
      glRotated(rotAngle, 0, 1, 0);
      cube.draw();
      glPopMatrix();

      window.drawOn2D();
      glPushMatrix();
      glColor3d(1, 1, 1);

      glBegin(GL_QUADS);
      glVertex2d(0, 0);
      glVertex2d(0, 100);
      glVertex2d(200, 100);
      glVertex2d(200, 0);
      glEnd();

      glPopMatrix();

      // Swaps the front and back framebuffers, this is a very technical process which you don't
      // necessarily
      // need to understand. You can simply see this method as updating the window contents.
      glfwSwapBuffers(window.getWindowID());
    }

    window.destroyWindow();
  }