Code Search for Developers
 
 
  

NewDisplay.java from Lightweight Java Game Library at Krugle


Show NewDisplay.java syntax highlighted

package org.lwjgl.d3d;

import java.util.Arrays;
import java.util.HashSet;

import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;

public class NewDisplay {
    private static final DisplayMode initialMode;
    private static DisplayMode currentMode;
    private static long hwnd;
    private static boolean created;
    private static boolean fullscreen;
    private static boolean modeSet;

    static {
        try {
            currentMode = initialMode = nGetCurrentDisplayMode();
            LWJGLUtil.log("Initial mode: " + initialMode);
        } catch (LWJGLException e) {
            throw new RuntimeException(e);
        }
    }
    
    private NewDisplay(){}
    public static DisplayMode[] getAvailableDisplayModes() throws LWJGLException {
        synchronized (GlobalLock.lock) {
            Object[] unfilteredModes = nGetAvailableDisplayModes();

            if (unfilteredModes == null) {
                return new DisplayMode[0];
            }

            // We'll use a HashSet to filter out the duplicated modes
            HashSet modes = new HashSet(unfilteredModes.length);

            modes.addAll(Arrays.asList(unfilteredModes));
            DisplayMode[] filteredModes = new DisplayMode[modes.size()];
            modes.toArray(filteredModes);

            LWJGLUtil.log("Removed " + (unfilteredModes.length - filteredModes.length) + " duplicate displaymodes");

            return filteredModes;
        }
    }
    
    public static void setDisplayMode(DisplayMode mode) throws LWJGLException {
        synchronized (GlobalLock.lock) {
            if (mode == null)
                throw new NullPointerException("mode must be non-null");
            currentMode = mode;
            if (isCreated()) {
                destroyWindow();
                // If mode is not fullscreen capable, make sure we are in windowed mode
                if (!mode.isFullscreen())
                    resetFullscreen();
                try {
                    if (fullscreen) {
                        switchDisplayMode();
                    }
                    createWindow();
//                    makeCurrentAndSetSwapInterval();
                } catch (LWJGLException e) {
//                    destroyContext();
//                    destroyPeerInfo();
                    resetDisplayMode();
                    throw e;
                }
            }
        }
    }
    
    public static void create() throws LWJGLException {
        //TODO
    }
    public static void destroy() {
        //TODO
    }
    
    public static boolean isCreated() {
        return created;
    }
    private static void destroyWindow() {
        if (created) {
//            if (Mouse.isCreated()) {
//                Mouse.destroy();
//            }
//            if (Keyboard.isCreated()) {
//                Keyboard.destroy();
//            }
            nDestroyWindow();
//            resetCursorClipping();
            created = false;
        }
    }
    private static void resetFullscreen() {
        synchronized (GlobalLock.lock) {
            if (NewDisplay.fullscreen) {
                NewDisplay.fullscreen = false;
                resetDisplayMode();
            }
        }
    }
    private static void switchDisplayMode() throws LWJGLException {
        if (!currentMode.isFullscreen()) {
            LWJGLUtil.log("Switching to " + initialMode);
            setDisplayMode(initialMode);
        }
        switchDisplayMode(initialMode);
    }
    public static void switchDisplayMode(DisplayMode mode) throws LWJGLException {
        nSwitchDisplayMode(mode);
        currentMode = mode;
        modeSet = true;
    }
    private static void createWindow() {
        //TODO
    }
    private static void resetDisplayMode() {
        if (modeSet) {
            modeSet = false;
            nResetDisplayMode();
        }
//        resetCursorClipping();
    }
    private static native void nDestroyWindow();
    private static native DisplayMode[] nGetAvailableDisplayModes();
    private static native void nSetDisplayMode(DisplayMode mode);
    private static native void nSwitchDisplayMode(DisplayMode mode) throws LWJGLException;
    private static native void nResetDisplayMode();
    private static native DisplayMode nGetCurrentDisplayMode() throws LWJGLException;
}




See more files for this project here

Lightweight Java Game Library

A Java Game Library extension: 1. Handles the graphics, sound, and input simply 2. Wraps OpenGL, OpenAL, fmod3 and DevIL 3. Hires timers LWJGL currently supports Linux, Mac OS X (10.2 and above) and Windows (98 and above).

Project homepage: http://sourceforge.net/projects/java-game-lib
Programming language(s): C,Java
License: other

  Context.java
  ContextImplementation.java
  D3DAdapterIdentifier9.java
  D3DBox.java
  D3DCaps9.java
  D3DClipStatus9.java
  D3DColorValue.java
  D3DDeviceCreationParameters.java
  D3DDisplaymode.java
  D3DDisplaymodeEx.java
  D3DDisplaymodeFilter.java
  D3DGammaRamp.java
  D3DIndexBufferDesc.java
  D3DLight9.java
  D3DLockedBox.java
  D3DLockedRect.java
  D3DMaterial9.java
  D3DMatrix.java
  D3DPShaderCaps2_0.java
  D3DPresentParameters.java
  D3DPresentStats.java
  D3DRasterStatus.java
  D3DRectPatchInfo.java
  D3DRegionData.java
  D3DRegionDataHeader.java
  D3DSsurfaceDesc.java
  D3DSurfaceDesc.java
  D3DTriPatchInfo.java
  D3DUtil.java
  D3DVShaderCaps2_0.java
  D3DVector.java
  D3DVertexBufferDesc.java
  D3DVertexElement9.java
  D3DViewport9.java
  D3DVolumeDesc.java
  Direct3DConstants.java
  Display.java
  DisplayImplementation.java
  DisplayMode.java
  Drawable.java
  EventQueue.java
  GUID.java
  GlobalLock.java
  IDirect3D9.java
  IDirect3D9Ex.java
  IDirect3DBaseTexture9.java
  IDirect3DCubeTexture9.java
  IDirect3DDevice9.java
  IDirect3DDevice9Ex.java
  IDirect3DIndexBuffer9.java
  IDirect3DPixelShader9.java
  IDirect3DQuery9.java
  IDirect3DResource9.java
  IDirect3DStateBlock9.java
  IDirect3DSurface9.java
  IDirect3DSwapChain9.java
  IDirect3DSwapChain9Ex.java
  IDirect3DTexture9.java
  IDirect3DVertexBuffer9.java
  IDirect3DVertexDeclaration9.java
  IDirect3DVertexShader9.java
  IDirect3DVolume9.java
  IDirect3DVolumeTexture9.java
  InputImplementation.java
  LUID.java
  NewDisplay.java
  PaletteEntry.java
  PeerInfo.java
  PixelFormat.java
  Point.java
  Rectangle.java
  RegionData.java
  RegionDataHeader.java
  WindowsContextImplementation.java
  WindowsDirectInput.java
  WindowsDirectInput3.java
  WindowsDirectInput8.java
  WindowsDirectInputDevice.java
  WindowsDirectInputDevice3.java
  WindowsDirectInputDevice8.java
  WindowsDirectInputDeviceObjectCallback.java
  WindowsDisplay.java
  WindowsDisplayPeerInfo.java
  WindowsFileVersion.java
  WindowsKeyboard.java
  WindowsKeycodes.java
  WindowsMouse.java
  WindowsPeerInfo.java
  WindowsRegistry.java