Search in sources :

Example 1 with DisplayMode

use of org.lwjgl.opengl.DisplayMode in project playn by threerings.

the class JavaGraphics method setDisplayMode.

protected void setDisplayMode(int width, int height, boolean fullscreen) {
    try {
        // check if current mode is suitable
        DisplayMode mode = Display.getDisplayMode();
        if (fullscreen == Display.isFullscreen() && mode.getWidth() == width && mode.getHeight() == height)
            return;
        if (fullscreen) {
            // try and find a mode matching width and height
            DisplayMode matching = null;
            for (DisplayMode test : Display.getAvailableDisplayModes()) {
                if (test.getWidth() == width && test.getHeight() == height && test.isFullscreenCapable()) {
                    matching = test;
                }
            }
            if (matching == null) {
                platform.log().info("Could not find a matching fullscreen mode, available: " + Arrays.asList(Display.getAvailableDisplayModes()));
            } else {
                mode = matching;
            }
        } else {
            mode = new DisplayMode(width, height);
        }
        platform.log().debug("Updating display mode: " + mode + ", fullscreen: " + fullscreen);
        // TODO: fix crashes when fullscreen is toggled repeatedly
        if (fullscreen) {
            Display.setDisplayModeAndFullscreen(mode);
        // TODO: fix alt-tab, maybe add a key listener or something?
        } else {
            Display.setDisplayMode(mode);
        }
    } catch (LWJGLException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : DisplayMode(org.lwjgl.opengl.DisplayMode) LWJGLException(org.lwjgl.LWJGLException)

Example 2 with DisplayMode

use of org.lwjgl.opengl.DisplayMode in project lwjgl by LWJGL.

the class Gears method init.

/**
	 *
	 */
private void init() throws LWJGLException {
    final int WIDTH = 640;
    final int HEIGHT = 480;
    Display.setLocation((Display.getDisplayMode().getWidth() - WIDTH) / 2, (Display.getDisplayMode().getHeight() - HEIGHT) / 2);
    try {
        Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
    } catch (PowerManagementEventException e) {
        e.printStackTrace();
    }
    Display.setTitle("Gears");
    Display.create(new PixelFormat());
    //glCoverageMaskNV(true);
    // setup ogl
    glViewport(0, 0, WIDTH, HEIGHT);
    glFrontFace(GL_CCW);
    glCullFace(GL_BACK);
    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    final Vector3f lp = new Vector3f(5.0f, 5.0f, 10.0f);
    lp.normalise();
    glLight(GL_LIGHT0, GL_POSITION, lp.getX(), lp.getY(), lp.getZ(), 0.0f);
    /* make the gears */
    gear1 = new Gear(gear(1.0f, 4.0f, 1.0f, 20, 0.7f), new float[] { 0.8f, 0.1f, 0.0f, 1.0f });
    gear2 = new Gear(gear(0.5f, 2.0f, 2.0f, 10, 0.7f), new float[] { 0.0f, 0.8f, 0.2f, 1.0f });
    gear3 = new Gear(gear(1.3f, 2.0f, 0.5f, 10, 0.7f), new float[] { 0.2f, 0.2f, 1.0f, 1.0f });
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    final 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);
    vsh = new Shader(GL_VERTEX_SHADER, "uniform highp vec4 LIGHT_POS;\n" + "uniform highp mat4 MODEL_VIEW_PROJECTION_MATRIX;\n" + "uniform mediump mat3 NORMAL_MATRIX;\n" + "uniform lowp vec3 GEAR_COLOR;\n" + "attribute highp vec3 vPosition;\n" + "attribute mediump vec3 vNormal;\n" + "varying lowp vec3 color;\n" + "void main(void) {\n" + "\tgl_Position = MODEL_VIEW_PROJECTION_MATRIX * vec4(vPosition, 1.0);\n" + "\tvec3 normal = NORMAL_MATRIX * vNormal;\n" + "\tcolor = max(dot(normal, vec3(LIGHT_POS)), 0.0) * GEAR_COLOR + vec3(0.05);\n" + "}");
    fsh = new Shader(GL_FRAGMENT_SHADER, "varying lowp vec3 color;\n" + "void main(void) {\n" + "\tgl_FragColor = vec4(color, 1.0);\n" + "}");
    program = new ShaderProgram(vsh, fsh);
    program.enable();
    LIGHT_POS = program.getUniformLocation("LIGHT_POS");
    MVP = program.getUniformLocation("MODEL_VIEW_PROJECTION_MATRIX");
    NM = program.getUniformLocation("NORMAL_MATRIX");
    GEAR_COLOR = program.getUniformLocation("GEAR_COLOR");
    vPosition = program.getAttributeLocation("vPosition");
    vNormal = program.getAttributeLocation("vNormal");
    glEnableVertexAttribArray(vNormal);
    glEnableVertexAttribArray(vPosition);
}
Also used : DisplayMode(org.lwjgl.opengl.DisplayMode) ShaderProgram(org.lwjgl.test.opengles.util.ShaderProgram) Vector3f(org.lwjgl.util.vector.Vector3f) Shader(org.lwjgl.test.opengles.util.Shader)

Example 3 with DisplayMode

use of org.lwjgl.opengl.DisplayMode in project lwjgl by LWJGL.

the class Display method getAvailableDisplayModes.

/**
	 * Determine the available display modes that match the specified minimum and maximum criteria.
	 * If any given criterium is specified as -1 then it is ignored.
	 *
	 * @param minWidth the minimum display resolution in pixels
	 * @param minHeight the minimum display resolution in pixels
	 * @param maxWidth the maximum display resolution in pixels
	 * @param maxHeight the maximum display resolution in pixels
	 * @param minBPP the minimum bit depth per pixel
	 * @param maxBPP the maximum bit depth per pixel
	 * @param minFreq the minimum display frequency in Hz
	 * @param maxFreq the maximum display frequency in Hz
	 * @return an array of matching display modes
	 */
public static DisplayMode[] getAvailableDisplayModes(int minWidth, int minHeight, int maxWidth, int maxHeight, int minBPP, int maxBPP, int minFreq, int maxFreq) throws LWJGLException {
    // First get the available display modes
    DisplayMode[] modes = org.lwjgl.opengl.Display.getAvailableDisplayModes();
    if (LWJGLUtil.DEBUG || DEBUG) {
        System.out.println("Available screen modes:");
        for (DisplayMode mode : modes) {
            System.out.println(mode);
        }
    }
    ArrayList<DisplayMode> matches = new ArrayList<DisplayMode>(modes.length);
    for (int i = 0; i < modes.length; i++) {
        assert modes[i] != null : "" + i + " " + modes.length;
        if (minWidth != -1 && modes[i].getWidth() < minWidth)
            continue;
        if (maxWidth != -1 && modes[i].getWidth() > maxWidth)
            continue;
        if (minHeight != -1 && modes[i].getHeight() < minHeight)
            continue;
        if (maxHeight != -1 && modes[i].getHeight() > maxHeight)
            continue;
        if (minBPP != -1 && modes[i].getBitsPerPixel() < minBPP)
            continue;
        if (maxBPP != -1 && modes[i].getBitsPerPixel() > maxBPP)
            continue;
        //	continue;
        if (modes[i].getFrequency() != 0) {
            if (minFreq != -1 && modes[i].getFrequency() < minFreq)
                continue;
            if (maxFreq != -1 && modes[i].getFrequency() > maxFreq)
                continue;
        }
        matches.add(modes[i]);
    }
    DisplayMode[] ret = new DisplayMode[matches.size()];
    matches.toArray(ret);
    if (LWJGLUtil.DEBUG && DEBUG) {
        System.out.println("Filtered screen modes:");
        for (DisplayMode mode : ret) {
            System.out.println(mode);
        }
    }
    return ret;
}
Also used : DisplayMode(org.lwjgl.opengl.DisplayMode) ArrayList(java.util.ArrayList)

Example 4 with DisplayMode

use of org.lwjgl.opengl.DisplayMode in project lwjgl by LWJGL.

the class TessellationTest method createDisplay.

private void createDisplay() throws LWJGLException {
    int width = 300;
    int height = 300;
    Display.setDisplayMode(new DisplayMode(width, height));
    Display.create();
    Display.setVSyncEnabled(true);
    glEnable(GL_TEXTURE_2D);
    glShadeModel(GL_SMOOTH);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(1);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glViewport(0, 0, width, height);
    glMatrixMode(GL_MODELVIEW);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, width, height, 0, 1, -1);
    glMatrixMode(GL_MODELVIEW);
}
Also used : DisplayMode(org.lwjgl.opengl.DisplayMode)

Example 5 with DisplayMode

use of org.lwjgl.opengl.DisplayMode in project lwjgl by LWJGL.

the class FullScreenWindowedTest method processKeyboard.

/**
	 * Processes keyboard input
	 */
private void processKeyboard() {
    //check for fullscreen key
    if (Keyboard.isKeyDown(Keyboard.KEY_F)) {
        try {
            switchMode();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //check for window key
    if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
        try {
            mode = new DisplayMode(640, 480);
            Display.setDisplayModeAndFullscreen(mode);
            glInit();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //check for speed changes
    if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
        quadVelocity.y += 0.1f;
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
        quadVelocity.y -= 0.1f;
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
        quadVelocity.x += 0.1f;
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
        quadVelocity.x -= 0.1f;
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_ADD)) {
        angleRotation += 0.1f;
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_SUBTRACT)) {
        angleRotation -= 0.1f;
    }
    //throttle
    if (quadVelocity.x < -MAX_SPEED) {
        quadVelocity.x = -MAX_SPEED;
    }
    if (quadVelocity.x > MAX_SPEED) {
        quadVelocity.x = MAX_SPEED;
    }
    if (quadVelocity.y < -MAX_SPEED) {
        quadVelocity.y = -MAX_SPEED;
    }
    if (quadVelocity.y > MAX_SPEED) {
        quadVelocity.y = MAX_SPEED;
    }
    if (angleRotation < 0.0f) {
        angleRotation = 0.0f;
    }
    if (angleRotation > MAX_SPEED) {
        angleRotation = MAX_SPEED;
    }
    while (Mouse.next()) ;
}
Also used : DisplayMode(org.lwjgl.opengl.DisplayMode) LWJGLException(org.lwjgl.LWJGLException)

Aggregations

DisplayMode (org.lwjgl.opengl.DisplayMode)14 LWJGLException (org.lwjgl.LWJGLException)7 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 FloatBuffer (java.nio.FloatBuffer)1 Comparator (java.util.Comparator)1 List (java.util.List)1 ContextCapabilities (org.lwjgl.opengl.ContextCapabilities)1 PowerManagementEventException (org.lwjgl.opengles.PowerManagementEventException)1 Shader (org.lwjgl.test.opengles.util.Shader)1 ShaderProgram (org.lwjgl.test.opengles.util.ShaderProgram)1 Vector3f (org.lwjgl.util.vector.Vector3f)1