Esempio n. 1
1
  @Override
  public void drawScreen(int mouseX, int mouseY, float partialTicks) {
    this.drawDefaultBackground();

    mc.getTextureManager().bindTexture(skrivemaskinegui);

    this.drawTexturedModalRect(this.width / 2 - 128, this.height / 2 - 128, 0, 0, 256, 256);

    /* this is where the editor reads keys and writes to the screen */
    if (org.lwjgl.input.Keyboard.getEventKeyState()) {
      //
      if (isAllowedDeletion()) {
        text.deleteCharAt(cursorLocation);
        cursorLocation--;
        text.deleteCharAt(cursorLocation);
        text.insert(cursorLocation, cursor); // moving cursor
      } else if (isAllowedNewLine()) {
        text.deleteCharAt(cursorLocation);
        text.insert(cursorLocation, '\n');
        cursorLocation++;
        text.insert(cursorLocation, cursor); // moving cursor
      } else if (isAllowedLeftArrowNavigation()) {
        text.deleteCharAt(cursorLocation);
        cursorLocation--;
        text.insert(cursorLocation, cursor); // moving cursor

      } else if (isAllowedRightArrowNavigation()) {
        text.deleteCharAt(cursorLocation);
        cursorLocation++;
        text.insert(cursorLocation, cursor); // moving cursor

      } else if (Keyboard.getEventKey() == Keyboard.KEY_TAB) {
        text.deleteCharAt(cursorLocation);
        for (int i = 0; i < 3; i++) {
          text.insert(cursorLocation, " ");
          cursorLocation++;
        }
        text.insert(cursorLocation, cursor); // moving cursor

      } else {
        if (isAllowedCharacters()) {
          // System.out.println(org.lwjgl.input.Keyboard.getEventKey());
          text.deleteCharAt(cursorLocation);
          text.insert(cursorLocation, org.lwjgl.input.Keyboard.getEventCharacter());
          cursorLocation++;
          text.insert(cursorLocation, cursor); // moving cursor
        }
      }

      org.lwjgl.input.Keyboard.destroy();
    } else if (!org.lwjgl.input.Keyboard.isCreated()) {
      try {
        org.lwjgl.input.Keyboard.create();
      } catch (Exception e) {
      }
    }

    /* writes the text string to the screen */
    renderer.drawSplitString(
        text.toString(), this.width / 2 - 118, this.height / 2 - 119, 238, 0xFFFFF0);

    super.drawScreen(mouseX, mouseY, partialTicks);
  }
 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);
         }
       }
     }
   }
 }
Esempio n. 3
0
 // Initializes keyboard use
 public static void init() {
   try {
     Keyboard.create();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  /**
   * *************************************************************************************************************************************************************************************************
   * 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();
  }
Esempio n. 5
0
 private static void createKeyboard() {
   try {
     Keyboard.create();
   } catch (Exception e) {
     e.printStackTrace();
     System.exit(-1);
   }
 }
Esempio n. 6
0
  /** Setups the Display */
  private void initDisplay() throws LWJGLException {
    Display.setDisplayMode(standartDisplayMode);
    Display.setResizable(true);
    Display.setVSyncEnabled(true);
    Display.setTitle("LLC - " + VERSION);
    Display.create();

    Keyboard.create();
    Mouse.create();
  }
Esempio n. 7
0
 public static void create() {
   try {
     Display.create();
     Mouse.create();
     Keyboard.create();
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
Esempio n. 8
0
 /** When Minecraft gains focus, reset all pressed keys to avoid the "stuck keys" bug. */
 private void unlockKeysIfNecessary() {
   boolean hasFocus = Display.isActive();
   if (!hadFocus && hasFocus) {
     Keyboard.destroy();
     boolean firstTry = true;
     while (!Keyboard.isCreated()) {
       try {
         Keyboard.create();
       } catch (LWJGLException e) {
         if (firstTry) {
           logInGameError("invtweaks.keyboardfix.error", e);
           firstTry = false;
         }
       }
     }
     if (!firstTry) {
       logInGame("invtweaks.keyboardfix.recover");
     }
   }
   hadFocus = hasFocus;
 }
Esempio n. 9
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();
    }
  }
Esempio n. 10
0
 @Override
 public void init() {
   try {
     DisplayMode[] modes = Display.getAvailableDisplayModes();
     int closestindex = -1;
     for (int i = 0; i < modes.length; i++) {
       if (closestindex == -1) closestindex = 0;
       else if (getModeDist(modes[closestindex]) > getModeDist(modes[i])) closestindex = i;
     }
     Display.setDisplayMode(modes[closestindex]);
     Display.setTitle("Voxels " + Main.Version);
     Display.create();
     setVSyncEnabled(Main.isVSyncEnabled);
     org.lwjgl.input.Mouse.create();
     org.lwjgl.input.Keyboard.create();
     org.lwjgl.input.Keyboard.enableRepeatEvents(true);
     if (!AL.isCreated()) AL.create();
     this.mouse.init();
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
Esempio n. 11
0
  /** Runs the actual test, using supplied arguments */
  protected void execute(String[] args) {
    if (args.length < 1) {
      System.out.println("no argument supplied, assuming Footsteps.wav");
      args = new String[] {"Footsteps.wav"};
    }

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

    int lastError;
    Vector3f sourcePosition = new Vector3f();
    Vector3f listenerPosition = new Vector3f();

    // initialize keyboard
    try {
      Keyboard.create();
    } catch (Exception e) {
      e.printStackTrace();
      exit(-1);
    }

    // create 1 buffer and 1 source
    IntBuffer buffers = BufferUtils.createIntBuffer(1);
    IntBuffer sources = BufferUtils.createIntBuffer(1);

    // al generate buffers and sources
    buffers.position(0).limit(1);
    AL10.alGenBuffers(buffers);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    sources.position(0).limit(1);
    AL10.alGenSources(sources);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    // load wave data
    WaveData wavefile = WaveData.create(args[0]);

    // copy to buffers
    AL10.alBufferData(buffers.get(0), wavefile.format, wavefile.data, wavefile.samplerate);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    // unload file again
    wavefile.dispose();

    // set up source input
    AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffers.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    AL10.alSourcef(sources.get(0), AL10.AL_REFERENCE_DISTANCE, 1024.0f);
    AL10.alSourcef(sources.get(0), AL10.AL_ROLLOFF_FACTOR, 0.5f);

    // lets loop the sound
    AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, AL10.AL_TRUE);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    // play source 0
    AL10.alSourcePlay(sources.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    System.out.println(
        "Move source with arrow keys\nMove listener with right shift and arrowkeys\nExit with ESC");

    while (!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
      Display.update();

      Keyboard.poll();
      if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
        if (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
          listenerPosition.x -= MOVEMENT;
          AL10.alListener3f(
              AL10.AL_POSITION, listenerPosition.x, listenerPosition.y, listenerPosition.z);
          System.out.println("listenerx: " + listenerPosition.x);
        } else {
          sourcePosition.x -= MOVEMENT;
          AL10.alSource3f(
              sources.get(0),
              AL10.AL_POSITION,
              sourcePosition.x,
              sourcePosition.y,
              sourcePosition.z);
          System.out.println("sourcex: " + sourcePosition.x);
        }
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
        if (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
          listenerPosition.x += MOVEMENT;
          AL10.alListener3f(
              AL10.AL_POSITION, listenerPosition.x, listenerPosition.y, listenerPosition.z);
          System.out.println("listenerx: " + listenerPosition.x);
        } else {
          sourcePosition.x += MOVEMENT;
          AL10.alSource3f(
              sources.get(0),
              AL10.AL_POSITION,
              sourcePosition.x,
              sourcePosition.y,
              sourcePosition.z);
          System.out.println("sourcex: " + sourcePosition.x);
        }
      }

      if (Display.isCloseRequested()) {
        break;
      }

      try {
        Thread.sleep(100);
      } catch (InterruptedException inte) {
      }
    }

    // stop source 0
    AL10.alSourceStop(sources.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    // delete buffers and sources
    sources.position(0).limit(1);
    AL10.alDeleteSources(sources);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    buffers.position(0).limit(1);
    AL10.alDeleteBuffers(buffers);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    // shutdown
    alExit();
  }
Esempio n. 12
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());
   }
 }
Esempio n. 13
0
  public void run(Map<String, String> parameters) {
    DisplayManager.create();
    DisplayManager displayManager = DisplayManager.getInstance();
    displayManager.setWindowTitle(TITLE);
    ObjectObserver objectObserver = new ObjectObserverMoteJ();
    WindowManager windowManager = null;

    try {
      for (DisplayMode mode : displayManager.getAvailableDisplayModes()) {
        log.info(mode.getWidth() + "x" + mode.getHeight() + ":" + mode.getBitsPerPixel());
      }
      displayMode = displayManager.getDisplayMode(800, 600, 32);
      displayManager.createDisplay(displayMode);
      Keyboard.create();

      objectObserver.initialize(parameters);

      WindowManager.create(displayManager, objectObserver);
      windowManager = WindowManager.getInstance();
      windowManager.getWindowManagerCalibrator().addWindowManagerCalibratorListener(this);

      FrameMeter frameMeter = new FrameMeter();
      calibrationRequested = true;
      isCalibrated = false;
      isRunning = true;
      while (isRunning) {
        if (Display.isCloseRequested()) {
          break;
        }

        while (Keyboard.next()) {
          if (Keyboard.getEventKey() == Keyboard.KEY_F) {
            if (Keyboard.getEventKeyState()) {
              displayManager.setFullScreen(!displayManager.isFullScreen());
            }
          }
          if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
            isRunning = false;
          }
          if (Keyboard.getEventKey() == Keyboard.KEY_C) {
            calibrationRequested = true;
          }
          if (Keyboard.getEventKey() == Keyboard.KEY_UP) {
            ballSpeed += 0.1f;
          }
          if (Keyboard.getEventKey() == Keyboard.KEY_DOWN) {
            ballSpeed -= 0.1f;
          }
        }

        if (calibrationRequested) {
          windowManager.calibrate();
          calibrationRequested = false;
          isCalibrated = false;
        } else if (isCalibrated) {
          windowManager.setCursorCollection(new CursorCollectionDefault());

          log.info("Loading images...");
          loadImages();
          isCalibrated = false;

          gameState = GameState.Ready;
        }

        if (frameMeter.update()) {
          displayManager.setWindowTitle(TITLE + " - " + frameMeter.getFps() + " fps");
        }

        // game state
        if (gameState != null) {
          if (gameState.equals(GameState.Ready)) {
            onGameStateReady();
          } else if (gameState.equals(GameState.Start)) {
            onGameStateStart();
          } else if (gameState.equals(GameState.Playing)) {
            onGameStatePlaying();
          } else if (gameState.equals(GameState.End)) {
            onGameStateEnd();
          }
        }

        windowManager.update();
        Thread.sleep(30);
      }
    } catch (Exception exception) {
      exception.printStackTrace();
    } finally {
      try {
        if (windowManager != null) {
          windowManager.destroy();
        }
        Keyboard.destroy();
        displayManager.destroy();
      } catch (Exception exception) {
        exception.printStackTrace();
      }
    }
  }