Example usage for org.lwjgl.opengl GL11 glViewport

List of usage examples for org.lwjgl.opengl GL11 glViewport

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 glViewport.

Prototype

public static void glViewport(@NativeType("GLint") int x, @NativeType("GLint") int y,
        @NativeType("GLsizei") int w, @NativeType("GLsizei") int h) 

Source Link

Document

Specifies the viewport transformation parameters for all viewports.

Usage

From source file:me.sunchiro.game.engine.gl.Graphic.java

License:Open Source License

private GLFWWindowSizeCallback resizeCallback() {
    return windowSizeCalback = new GLFWWindowSizeCallback() {

        @Override//from  w  w  w. java 2  s . com
        public void invoke(long window, int newwidth, int newheight) {
            width = newwidth;
            height = newheight;
            cam.resize(newwidth, newheight);
            GL11.glViewport(0, 0, width, height);

        }
    };
}

From source file:me.thehutch.fusion.engine.render.opengl.GLContext.java

License:Open Source License

@Override
public void setViewPort(Rectangle viewport) {
    ensureCreated("Can not set viewport if the context has not been created");
    GL11.glViewport(viewport.getX(), viewport.getY(), viewport.getWidth(), viewport.getHeight());
}

From source file:modeledit.ModelView3D.java

License:Open Source License

public void draw() {
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();//from w  w  w .  j a  v a 2  s. co  m

    GL11.glMatrixMode(GL11.GL_VIEWPORT);
    GL11.glViewport(0, 0, getWidth(), getHeight());

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GLU.gluPerspective(40, ((float) this.getWidth()) / ((float) this.getHeight()), 1, 100);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glTranslatef(panX, panY, 0);

    //(float)(camDist*Math.sin(camTheta)*Math.cos(camPhi))
    GLU.gluLookAt((float) (camDist * Math.sin(camTheta) * Math.sin(camPhi)),
            (float) (camDist * Math.cos(camTheta) * Math.sin(camPhi)), (float) (camDist * Math.cos(camPhi)), 0,
            0, 0, 0, 0, 1);
    if (model != null) {
        model.draw(state);
    }
}

From source file:mss.View.java

License:Open Source License

public void init() {
    this.modul.registerObserver("view", this);
    updateComboBoxes();/*  ww  w  . j  a  v a 2  s . co m*/

    try {
        Display.setParent(this.canvas);
        Keyboard.enableRepeatEvents(true);
        this.frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        this.frame.setLayout(new BorderLayout());
        this.frame.add(this.tabbedPane, BorderLayout.LINE_START);
        this.frame.add(this.canvas, BorderLayout.CENTER);
        this.frame.add(this.panel, BorderLayout.PAGE_END);
        this.frame.setPreferredSize(new Dimension(1024, 786));
        this.frame.setMinimumSize(new Dimension(800, 600));
        this.frame.pack();

        this.frame.setVisible(true);

        Display.setTitle(this.title);
        Display.setResizable(true);
        Display.setFullscreen(false);
        Display.create();
        this.initOpenGL();
        this.wasInitialized = true;
        LWJGLRenderer renderer = new LWJGLRenderer();

        Dimension newDim;

        while (!Display.isCloseRequested() && !View.closeRequested) {
            if (this.shouldReInit) {
                this.initOpenGL();
                this.shouldReInit = false;
            }

            if (this.shouldTakeScreenshot) {
                this.saveScreenshot();
                this.shouldTakeScreenshot = false;
            }

            GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
            newDim = newCanvasSize.getAndSet(null);
            checkKeyInput();
            if (newDim != null) {
                GL11.glViewport(0, 0, newDim.width, newDim.height);
                renderer.syncViewportSize();
            }

            for (int i = 0; i < this.planets.size(); i++) {
                this.planets.get(i).draw2D(this.debug);
            }

            if (!this.isPaused && this.results != null && this.currentIndex < this.results.size() - 1
                    && this.getDelta() / this.deltaT >= this.speed) {
                this.planets = this.results.get(this.currentIndex);
                int add = (int) (1 / deltaT);
                if (add == 0) {
                    add = 1;
                }
                this.time = this.getTime();
                this.currentIndex += add;
                this.slider.setValue(this.slider.getValue() + add);
            }

            checkKeyInput();
            checkMouseInput();
            Display.update();
            Display.sync(60);
        }

        Display.destroy();
        this.frame.dispose();
    } catch (LWJGLException e) {
        System.out.println(e.getMessage());
        System.exit(-1);
    }
}

From source file:name.martingeisse.swtlib.canvas.AbstractOpenGlBlockCanvas.java

License:Open Source License

/**
 * //from   w  w w .j a v  a  2 s .com
 */
private void prepareOpenGl() {
    setCurrent();
    try {
        GLContext.useContext(this);
    } catch (LWJGLException e) {
        throw new RuntimeException(e);
    }
    GL11.glViewport(0, 0, blockWidth * horizontalBlockCount, blockHeight * verticalBlockCount);
}

From source file:net.ae97.notlet.client.GameInstance.java

License:Open Source License

public static void createTextures() throws LWJGLException {
    Display.setDisplayMode(new DisplayMode(width, height));
    Display.create();/*  w w w .  jav  a 2s. c  om*/
    Display.setVSyncEnabled(true);

    GL11.glEnable(GL11.GL_TEXTURE_2D);

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

    // enable alpha blending
    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);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, width, height, 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    Font awtFont = new Font("Times New Roman", Font.BOLD, 18);
    font = new TrueTypeFont(awtFont, true);

    try {
        textureMapping.put("SMALLLET",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("SMALLLET.png")));
        textureMapping.put("healthbar",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("healthbar.png")));
        textureMapping.put("score",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("score.png")));
        textureMapping.put("arrow",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("arrow.png")));
        textureMapping.put("dirt",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("dirt.png")));
        textureMapping.put("rangerD",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("rangerD.png")));
        textureMapping.put("rangerL",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("rangerL.png")));
        textureMapping.put("rangerR",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("rangerR.png")));
        textureMapping.put("rangerU",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("rangerU.png")));
        textureMapping.put("skele",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("skele.png")));
        textureMapping.put("slime",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("slime.png")));
        textureMapping.put("hp", TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("hp.png")));
        textureMapping.put("pb", TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("pb.png")));
        textureMapping.put("wall",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("wall.png")));
        textureMapping.put("exit",
                TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("exit.png")));
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:net.betabears.the2dlibrary.graphics.DisplayHandler.java

public void init(final DisplaySettings ds) {
    this.ds = ds;

    glfwSetErrorCallback(new GLFWErrorCallback() {
        @Override/*from   w  w  w  . j a  v  a  2  s.  c  o  m*/
        public void invoke(int error, long description) {
            LOGGER.log(Level.SEVERE, "GLFW error occurred. Error code: {0}. Description {1}",
                    new Object[] { error, description });
            ev.post(new ExitEvent());
        }
    });

    if (glfwInit() != GL11.GL_TRUE) {
        LOGGER.log(Level.SEVERE, "Unable to initialize ");
        ev.post(new ExitEvent());
    }

    window = glfwCreateWindow(ds.getWidth(), ds.getHeight(), "A game", 0L, 0L);

    if (window == 0) {
        LOGGER.log(Level.SEVERE, "Unable to create window.");
        ev.post(new ExitEvent());
    }

    glfwSetFramebufferSizeCallback(window, new GLFWFramebufferSizeCallback() {
        @Override
        public void invoke(long window, int width, int height) {
            ds.setWidth(width);
            ds.setHeight(height);
            GL11.glViewport(0, 0, width, height);
        }
    });

    glfwSetKeyCallback(window, new GLFWKeyCallback() {
        @Override
        public void invoke(long window, int key, int scancode, int action, int mods) {
            ev.post(new KeyEvent(window, key, scancode, action, mods));
        }
    });

    glfwMakeContextCurrent(window);
    GLContext.createFromCurrent();
}

From source file:net.bryanbergen.lwjgl.display.Window.java

private void initCallbacks() {
    errorCallback = GLFWErrorCallback.createPrint();
    errorCallback.set();/* w  w  w.j  a v a2 s  . c om*/

    framebufferSizeCallback = new GLFWFramebufferSizeCallback() {
        @Override
        public void invoke(long window, int width, int height) {
            GL11.glViewport(0, 0, width, height);
        }
    };
    framebufferSizeCallback.set(windowHandle);

    windowSizeCallback = new GLFWWindowSizeCallback() {
        @Override
        public void invoke(long window, int width, int height) {
            dimension.setWidth(width);
            dimension.setHeight(height);
        }
    };
    windowSizeCallback.set(windowHandle);
    keyboard = new Keyboard();
    keyboard.set(windowHandle);
    mouse = new Mouse();
    mouse.set(windowHandle);
}

From source file:net.kubin.game.Game.java

License:Apache License

public void handleResize() {
    //Prevent negative UI sizes
    if (Display.getWidth() < 250) {
        return;/*from   www . j a v  a2  s  .c o  m*/
    }

    if (Display.getHeight() < 250) {
        return;
    }

    //Resize the UI and Viewport
    _configuration.setDisplaySettings(Display.getWidth(), Display.getHeight(), Display.isFullscreen());
    GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
    getWorld().handleDisplayResize();
}

From source file:net.kubin.game.StartupManager.java

License:Apache License

public void handleResize() {
    //Prevent negative UI sizes
    if (Display.getWidth() < 250) {
        return;/*from   w w  w.  j  a v a 2s  .co m*/
    }

    if (Display.getHeight() < 250) {
        return;
    }

    //Resize the UI and Viewport
    Kubin.getConfiguration().setDisplaySettings(Display.getWidth(), Display.getHeight(),
            Display.isFullscreen());
    GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());
    GUIManager.renderer.setViewport(0, 0, Display.getWidth(), Display.getHeight());
}