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 -----------// }
public static void update() { if (displayMode.getWidth() != Display.getWidth() || displayMode.getHeight() != Display.getHeight()) { displayMode = new DisplayMode(Display.getWidth(), Display.getHeight()); // TODO: MAKE FOV, zNear, zFar CHANGABLE GameEngine.getInstance() .getRenderer() .getCamera() .setParameters(70f, getWidth() / getHeight(), 0.1f, 1000); GameEngine.getInstance().getRenderer().getCamera().updateCenterPosition(); glViewport(0, 0, displayMode.getWidth(), displayMode.getHeight()); } }
public static Dimension getFullscreenDimension() { if (desktopDisplayMode == null) { return null; } else if (gameSettings == null) { return new Dimension(desktopDisplayMode.getWidth(), desktopDisplayMode.getHeight()); } else { String var0 = gameSettings.ofFullscreenMode; if (var0.equals("Default")) { return new Dimension(desktopDisplayMode.getWidth(), desktopDisplayMode.getHeight()); } else { String[] var1 = tokenize(var0, " x"); return var1.length < 2 ? new Dimension(desktopDisplayMode.getWidth(), desktopDisplayMode.getHeight()) : new Dimension(parseInt(var1[0], -1), parseInt(var1[1], -1)); } } }
private void onGameStateEnd() { Point position = ball.getPosition(); if (position.getX() <= 0.0f) { wonControl.setPosition( new Point((displayMode.getWidth() * (3.0f / 4.0f)), (displayMode.getHeight() / 2.0f))); lostControl.setPosition( new Point((displayMode.getWidth() / 4.0f), (displayMode.getHeight() / 2.0f))); } else { wonControl.setPosition( new Point((displayMode.getWidth() / 4.0f), (displayMode.getHeight() / 2.0f))); lostControl.setPosition( new Point((displayMode.getWidth() * (3.0f / 4.0f)), (displayMode.getHeight() / 2.0f))); } wonControl.setVisible(true); lostControl.setVisible(true); gameState = GameState.Ready; }
/** * Set the display mode to be used * * @param width The width of the display required * @param height The height of the display required * @param fullscreen True if we want fullscreen mode */ public void setDisplayMode(int width, int height, boolean fullscreen) { // return if requested DisplayMode is already set if ((Display.getDisplayMode().getWidth() == width) && (Display.getDisplayMode().getHeight() == height) && (Display.isFullscreen() == fullscreen)) { return; } try { DisplayMode targetDisplayMode = null; if (fullscreen) { DisplayMode[] modes = Display.getAvailableDisplayModes(); int freq = 0; for (int i = 0; i < modes.length; i++) { DisplayMode current = modes[i]; if ((current.getWidth() == width) && (current.getHeight() == height)) { if ((targetDisplayMode == null) || (current.getFrequency() >= freq)) { if ((targetDisplayMode == null) || (current.getBitsPerPixel() > targetDisplayMode.getBitsPerPixel())) { targetDisplayMode = current; freq = targetDisplayMode.getFrequency(); } } // if we've found a match for bpp and frequence against the // original display mode then it's probably best to go for this one // since it's most likely compatible with the monitor if ((current.getBitsPerPixel() == Display.getDesktopDisplayMode().getBitsPerPixel()) && (current.getFrequency() == Display.getDesktopDisplayMode().getFrequency())) { targetDisplayMode = current; break; } } } } else { targetDisplayMode = new DisplayMode(width, height); } if (targetDisplayMode == null) { System.out.println( "Failed to find value mode: " + width + "x" + height + " fs=" + fullscreen); return; } Display.setDisplayMode(targetDisplayMode); Display.setFullscreen(fullscreen); } catch (LWJGLException e) { System.out.println( "Unable to setup mode " + width + "x" + height + " fullscreen=" + fullscreen + e); } }
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(); }
public static String[] getFullscreenModes() { DisplayMode[] var0 = getFullscreenDisplayModes(); String[] var1 = new String[var0.length]; for (int var2 = 0; var2 < var0.length; ++var2) { DisplayMode var3 = var0[var2]; String var4 = "" + var3.getWidth() + "x" + var3.getHeight(); var1[var2] = var4; } return var1; }
private DisplayMode findDisplayMode(int width, int height, int bpp) throws LWJGLException { DisplayMode[] modes = Display.getAvailableDisplayModes(); DisplayMode mode = null; for (DisplayMode dm : modes) { if ((dm.getBitsPerPixel() == bpp) || (mode == null)) { if ((dm.getWidth() == width) && (dm.getHeight() == height)) { mode = dm; } } } return mode; }
private void onGameStateReady() { ball.setVisible(true); ball.setPosition(new Point((displayMode.getWidth() / 2.0f), (displayMode.getHeight() / 2.0f))); bouncedControl = null; shadowCount = 0; ballSpeed = BALL_SPEED; previousBallPositions.clear(); // gameState = GameState.Start; ball.setVisible(false); for (VisualControl visualControl : ballShadows) { visualControl.setVisible(false); } }
@Override public boolean init(Engine engine) { Window window = engine.getGlobal(Window.class); try { DisplayMode[] modes = Display.getAvailableDisplayModes(); DisplayMode chosen = modes[0]; for (DisplayMode mode : modes) { if (mode.getWidth() == window.width && mode.getHeight() == window.height && mode.isFullscreenCapable()) { chosen = mode; } break; } chosen = (DisplayMode) JOptionPane.showInputDialog( null, "Display Options", "Display Mode", JOptionPane.QUESTION_MESSAGE, null, modes, chosen); if (chosen == null) { return false; } Display.setDisplayMode(chosen); Display.setFullscreen( JOptionPane.showConfirmDialog( null, "Fullscreen?", "Display Options", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION); Display.setVSyncEnabled(true); Display.create(); glClearColor(1, 1, 1, 1); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); } catch (LWJGLException ex) { System.err.println("Error creating display: " + ex.getMessage()); return false; } return true; }
public void update() { Display.update(); Display.sync(fps); detectKonami(); if (Constants.allowFullScr) { if ((fullScr && !Display.isFullscreen()) || (!fullScr && Display.isFullscreen())) { System.out.println("Performing Display.destroy()/create() cycle"); sM = Display.getDisplayMode(); Display.destroy(); try { // DisplayMode[] d = Display.getAvailableDisplayModes(); // int value = 0; // int index = 0; // for(int i = 0; i < d.length; i++){ // if(d[i].getWidth() > value){ // value = d[i].getWidth(); // index = i; // } // } Display.setDisplayMode(sM); Display.setTitle("Music Dots"); Display.setFullscreen(fullScr); Display.create(); Display.setVSyncEnabled(true); Constants.VIEW_HEIGHT = sM.getHeight(); Constants.VIEW_WIDTH = sM.getWidth(); setupOpenGl(); Fonts.initialize(); } catch (LWJGLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } Theme.setClearColor(); // TODO: we should be calling a "recreateView" function and call this in there. Not sure why // we're recreating the view in an update function. if (!bPlayerModelInitialized) { StaticDrawer.initializeTextures(); bPlayerModelInitialized = true; } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }
public static DisplayMode getDisplayMode(Dimension var0) throws LWJGLException { DisplayMode[] var1 = Display.getAvailableDisplayModes(); for (int var2 = 0; var2 < var1.length; ++var2) { DisplayMode var3 = var1[var2]; if (var3.getWidth() == var0.width && var3.getHeight() == var0.height && (desktopDisplayMode == null || var3.getBitsPerPixel() == desktopDisplayMode.getBitsPerPixel() && var3.getFrequency() == desktopDisplayMode.getFrequency())) { return var3; } } return desktopDisplayMode; }
/** * Get all LWJGL DisplayModes into the DropDown * * @param screen */ private void fillResolutionDropDown(final Screen screen) { try { DisplayMode currentMode = Display.getDisplayMode(); List<DisplayMode> sorted = new ArrayList<DisplayMode>(); DisplayMode[] modes = Display.getAvailableDisplayModes(); for (int i = 0; i < modes.length; i++) { DisplayMode mode = modes[i]; if (mode.getBitsPerPixel() == 32 && mode.getFrequency() == currentMode.getFrequency()) { // since Nifty does not yet support automatically rescaling of the GUI and since this // example/demo was designed for 1024x768 pixel we can't allow resolutions below this // size. if (mode.getWidth() >= 1024 && mode.getHeight() >= 768) { sorted.add(mode); } } } Collections.sort( sorted, new Comparator<DisplayMode>() { @Override public int compare(DisplayMode o1, DisplayMode o2) { int widthCompare = Integer.valueOf(o1.getWidth()).compareTo(Integer.valueOf(o2.getWidth())); if (widthCompare != 0) { return widthCompare; } int heightCompare = Integer.valueOf(o1.getHeight()).compareTo(Integer.valueOf(o2.getHeight())); if (heightCompare != 0) { return heightCompare; } return o1.toString().compareTo(o2.toString()); } }); DropDown dropDown = screen.findNiftyControl("resolutions", DropDown.class); for (DisplayMode mode : sorted) { dropDown.addItem(mode); } } catch (Exception e) { } }
private void createDisplay() { try { // Get the current screen size Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension scrnsize = toolkit.getScreenSize(); float myResolution = (float) scrnsize.width / scrnsize.height; float availableRes = 0; int compatibleResI = 0; float smallWidth = scrnsize.width; System.out.println(Display.getDisplayMode().isFullscreenCapable()); DisplayMode[] d = Display.getAvailableDisplayModes(); for (int i = 0; i < d.length; i++) { System.out.println(d[i]); availableRes = (float) d[i].getWidth() / d[i].getHeight(); // check if this resolution is compatible and if smaller if (myResolution == availableRes && d[i].getWidth() >= smallWidth) { compatibleResI = i; smallWidth = d[i].getWidth(); } } sM = d[compatibleResI]; Display.setDisplayMode(sM); Constants.VIEW_HEIGHT = sM.getHeight(); Constants.VIEW_WIDTH = sM.getWidth(); Display.setFullscreen(fullScr); // set font scale depending on resolution (800 x 600 is base, dependant on height) Fonts.resolutionScale = (float) Constants.VIEW_HEIGHT / 600; Constants.DEFAULT_PLAYER_X = Constants.VIEW_WIDTH / 2; Constants.DEFAULT_PLAYER_Y = Constants.VIEW_HEIGHT / 2; // Display.setDisplayMode(new DisplayMode(Constants.VIEW_WIDTH, Constants.VIEW_HEIGHT)); Display.setTitle(Constants.GAME_NAME); Display.create(); Display.setVSyncEnabled(true); } catch (LWJGLException e) { e.printStackTrace(); } }
public void setDisplayMode(int width, int height, boolean fullscreen) { if ((Display.getDisplayMode().getWidth() == width) && (Display.getDisplayMode().getHeight() == height) && (Display.isFullscreen() == fullscreen)) { return; } try { DisplayMode targetDisplayMode = null; if (fullscreen) { DisplayMode[] modes = Display.getAvailableDisplayModes(); int freq = 0; for (int i = 0; i < modes.length; i++) { DisplayMode current = modes[i]; if ((current.getWidth() == width) && (current.getHeight() == height)) { if ((targetDisplayMode == null) || (current.getFrequency() >= freq)) { if ((targetDisplayMode == null) || (current.getBitsPerPixel() > targetDisplayMode.getBitsPerPixel())) { targetDisplayMode = current; freq = targetDisplayMode.getFrequency(); } } if ((current.getBitsPerPixel() == Display.getDesktopDisplayMode().getBitsPerPixel()) && (current.getFrequency() == Display.getDesktopDisplayMode().getFrequency())) { targetDisplayMode = current; break; } } } } else targetDisplayMode = new DisplayMode(width, height); if (targetDisplayMode == null) { System.out.println( "Failed to find value mode: " + width + "x" + height + " fs=" + fullscreen); return; } Display.setDisplayMode(targetDisplayMode); Display.setFullscreen(fullscreen); } catch (LWJGLException e) { System.out.println( "Unable to setup mode " + width + "x" + height + " fullscreen=" + fullscreen + e); } }
/** * Called when the screen is resized, and sets some variables, like {@link JumboMathHandler#xmod} * and {@link JumboMathHandler#ymod}. */ public static void update() { // JumboLaunchConfig config = JumboSettings.launchConfig; final int width, height; final float factor; if (JumboSettings.launchConfig.fullscreen) { final DisplayMode current = Display.getDisplayMode(); factor = Display.getPixelScaleFactor(); width = current.getWidth(); height = current.getHeight(); } else { width = Display.getWidth(); height = Display.getHeight(); factor = Display.getPixelScaleFactor(); } // Dynamic resizing only works if its larger than the launch // dimensions. // If its not, it gets strectched, which looks a bit ugly. Because // of // this, developers should make their base window as small as // possible. // if (width < config.width || height < config.height) { // renderwidth = config.width; // renderheight = config.height; // GL11.glOrtho(0.0f, config.width, 0, config.height, 0.0f, 1.0f); // GL11.glViewport(0, 0, width, height); // Maths.currentdim = new Dimension(config.width, config.height); // } else { // for high dpi modes renderwidth = (int) (width * factor); renderheight = (int) (height * factor); for (JumboRenderModule m : modes) { m.resize(renderwidth, renderheight); } JumboPaintClass.getScene().onWindowUpdate(); JumboPaintClass.getPreviousScene().onWindowUpdate(); wasResized = false; }
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(); } }
/** * @param args ... * @throws Exception ... */ public static void main(final String[] args) throws Exception { logger.info("Miner client started"); try { // initialize task system so we can start up in parallel tasks Thread.currentThread().setName("Startup (later OpenGL)"); TaskSystem.initialize(); // parse command-line options logger.trace("parsing command line options..."); boolean fullscreen = false; for (final String arg : args) { if (arg.equals("-fs")) { fullscreen = true; } else if (arg.equals("-6")) { screenWidth = 640; screenHeight = 480; } else if (arg.equals("-8")) { screenWidth = 800; screenHeight = 600; } else if (arg.equals("-1")) { screenWidth = 1024; screenHeight = 768; } else if (arg.equals("-12")) { screenWidth = 1280; screenHeight = 720; } else if (arg.equals("-16")) { screenWidth = 1680; screenHeight = 1050; } } logger.trace("command line options parsed"); // create a worker loop -- we need to access this in closures logger.trace("initializing OpenGL worker scheme..."); SimpleWorkerScheme.initialize(); logger.trace("OpenGL worker scheme initialized"); // prepare native libraries logger.trace("preparing native libraries..."); LwjglNativeLibraryHelper.prepareNativeLibraries(); logger.trace("native libraries prepared"); // configure the display logger.trace("finding optimal display mode..."); DisplayMode bestMode = null; int bestModeFrequency = -1; for (DisplayMode mode : Display.getAvailableDisplayModes()) { if (mode.getWidth() == screenWidth && mode.getHeight() == screenHeight && (mode.isFullscreenCapable() || !fullscreen)) { if (mode.getFrequency() > bestModeFrequency) { bestMode = mode; bestModeFrequency = mode.getFrequency(); } } } if (bestMode == null) { bestMode = new DisplayMode(screenWidth, screenHeight); } logger.trace("setting intended display mode..."); Display.setDisplayMode(bestMode); if (fullscreen) { Display.setFullscreen(true); } logger.trace("switching display mode..."); Display.create(new PixelFormat(0, 24, 0)); logger.trace("display initialized"); // initialize LWJGL logger.trace("preparing mouse..."); Mouse.create(); Mouse.poll(); logger.trace("mouse prepared"); // build the frame loop OsmWorld world = new OsmLoader().loadWorld(new File("resource/map.osm")); OsmViewer viewer = new OsmViewer(world); HandlerList handlerList = new HandlerList(); handlerList.add(viewer); handlerList.add(new ExitHandler(true, Keyboard.KEY_ESCAPE)); frameLoop = new FrameLoop(SimpleWorkerScheme.getGlWorkerLoop()); frameLoop.getRootHandler().setWrappedHandler(handlerList); // TODO remove, used for development logger.info("auto-login..."); logger.info("auto-login successful"); // run the game logic in a different thread, then run the OpenGL worker in the main thread new Thread("Application") { @Override public void run() { frameLoop.executeLoop(10); SimpleWorkerScheme.requestStop(); }; }.start(); logger.debug("startup thread becoming the OpenGL thread now"); Thread.currentThread().setName("OpenGL"); SimpleWorkerScheme.workAndWait(); // clean up Display.destroy(); } catch (final Exception e) { e.printStackTrace(); } System.exit(0); }
public static float getHeight() { return displayMode.getHeight(); }
private void loadImages() throws Exception { // background backgroundControl = new FramedControl(); backgroundControl.setColor(Color.BLACK); backgroundControl.setOpacity(0.5f); backgroundControl.setSize(new Size(displayMode.getWidth(), displayMode.getHeight())); backgroundControl.setTopLeftPosition(new Point(0, 0)); WindowManager.getInstance().setBackgroundControl(backgroundControl); // middle dot middleDotControl = new VisualControl(); middleDotControl.setTexture(getClass().getResource(URL_IMAGE_MIDDLE_DOT)); Size middleDotControlSize = middleDotControl.getSize(); middleDotControl.setSize(new Size(middleDotControlSize.getWidth(), displayMode.getHeight())); middleDotControl.setTopLeftPosition( new Point(((displayMode.getWidth() / 2.0f) - (middleDotControlSize.getWidth() / 2.0f)), 0)); // top bar BounceableControl topBar = new BounceableControl(); topBar.setTexture(getClass().getResource(URL_IMAGE_WHITE_RECTANGLE)); topBar.setSize(new Size(displayMode.getWidth(), BAR_SIZE)); topBar.setTopLeftPosition(new Point(0, 0)); bounceableControls.add(topBar); // bottom bar BounceableControl bottomBar = new BounceableControl(); bottomBar.setTexture(getClass().getResource(URL_IMAGE_WHITE_RECTANGLE)); bottomBar.setSize(new Size(displayMode.getWidth(), BAR_SIZE)); bottomBar.setTopLeftPosition(new Point(0, (displayMode.getHeight() - BAR_SIZE))); bounceableControls.add(bottomBar); // win/lose wonControl = new VisualControl(); // wonControl.setColor(Color.BLACK); wonControl.setTexture(getClass().getResource(URL_IMAGE_WON)); wonControl.setVisible(false); lostControl = new VisualControl(); // lostControl.setColor(Color.BLACK); lostControl.setTexture(getClass().getResource(URL_IMAGE_LOST)); lostControl.setVisible(false); // paddles for (int i = 0; i < NUMBER_OF_PADDLES; i++) { BounceableControl paddle = new BounceableControl(); paddle.setTexture(getClass().getResource(URL_IMAGE_WHITE_RECTANGLE)); paddle.setVisible(false); paddles.put(i, paddle); } // ball shadows for (int i = 0; i < NUMBER_OF_BALL_SHADOWS; i++) { float opacity = (1.0f - ((1.0f / (float) (NUMBER_OF_BALL_SHADOWS + 1)) * (i + 1))); float size = (BALL_SIZE * (NUMBER_OF_BALL_SHADOWS / (float) (NUMBER_OF_BALL_SHADOWS + (i + 1)))); log.debug("opacity: " + opacity + ", size: " + size); VisualControl visualControl = new VisualControl(); visualControl.setTexture(getClass().getResource(URL_IMAGE_WHITE_RECTANGLE)); visualControl.setSize(new Size(size, size)); visualControl.setOpacity(opacity); visualControl.setVisible(false); ballShadows.addLast(visualControl); } // ball ball = new VisualControl(); // ball.setColor(Color.BLACK); ball.setTexture(getClass().getResource(URL_IMAGE_WHITE_RECTANGLE)); ball.setSize(new Size(BALL_SIZE, BALL_SIZE)); // ball.setMargin(1.0f); ball.setVisible(false); // listeners backgroundControl.addTouchListener(this); }
private static int getModeDist(final DisplayMode mode) { return Math.abs(mode.getWidth() - 1024) + Math.abs(mode.getHeight() - 768); }
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(); } } }