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:$.DrawSystem.java

License:Open Source License

@Override
    protected void processEntities(ImmutableBag<Entity> entities) {
        GL11.glClearColor(0.1f, 0, 0, 1f);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
        List<Entity> entititesSortedByZ = new ArrayList<>(entities.size());
        for (int i = 0, n = entities.size(); i < n; ++i) {
            final Entity e = entities.get(i);
            if (e.isEnabled()) {
                entititesSortedByZ.add(e);
            }//w  w w  . java  2  s .  c  o  m
        }
        Collections.sort(entititesSortedByZ, zComparator);

        GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_TRANSFORM_BIT | GL11.GL_HINT_BIT | GL11.GL_COLOR_BUFFER_BIT
                | GL11.GL_SCISSOR_BIT | GL11.GL_LINE_BIT | GL11.GL_TEXTURE_BIT);
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();

        updateViewPort();
        GL11.glViewport(viewPort.x, viewPort.y, viewPort.width, viewPort.height);
        GLU.gluOrtho2D(-toolkit.getVirtualResolutionWidth() / 2.0f, toolkit.getVirtualResolutionWidth() / 2.0f,
                toolkit.getVirtualResolutionHeight() / 2.0f, -toolkit.getVirtualResolutionHeight() / 2.0f);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_LINE_SMOOTH);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glDisable(GL11.GL_SCISSOR_TEST);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);

        Game game = (Game) world;
        Entity hero = game.getHero();
        if (null != hero) {
            Sprite heroSprite = spriteMapper.get(hero);
            Vector heroPos = spriteProjector.project(heroSprite.getPosition());
            GL11.glTranslatef(-heroPos.x, -heroPos.y, 0.0f);
        }

        for (Entity e : entititesSortedByZ) {
            MainMenu mainMenu = mainMenuMapper.getSafe(e);
            if (null != mainMenu) {
                mainMenu.draw();
            }
            DialogueComponent dialog = dialogMapper.getSafe(e);
            if (null != dialog) {
                dialog.draw();
            }
            Level level = levelMapper.getSafe(e);
            if (null != level) {
                drawLevel(level);
            }
            Sprite sprite = spriteMapper.getSafe(e);
            if (null != sprite) {
                drawSprite(sprite);
            }
        }
        GL11.glPopMatrix();
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPopMatrix();
        GL11.glPopAttrib();

    }

From source file:a1.Main.java

License:Open Source License

private void setView(int screenWidth, int screenHeight) {
    GL11.glViewport(0, 0, screenWidth, screenHeight);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();//from w w  w  . j  a  v a  2  s.  c om
    GL11.glOrtho(0, screenWidth, screenHeight, 0, -1, 1);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
}

From source file:akarnokd.opengl.experiment.FontExample.java

License:Apache License

/**
 * Initialise the GL display//w  w w.j a  v a2 s . c o  m
 * 
 * @param width The width of the display
 * @param height The height of the display
 */
private void initGL(int width, int height) {
    try {
        Display.setDisplayMode(new DisplayMode(width, height));
        Display.create();
        Display.setVSyncEnabled(true);
    } catch (LWJGLException e) {
        e.printStackTrace();
        System.exit(0);
    }

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);

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

    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);
}

From source file:aphelion.client.Client.java

License:Open Source License

public static void initGL() {
    int displayWidth = Display.getWidth();
    int displayHeight = Display.getHeight();

    glDisableAll();/* w  ww  .  j  av a 2  s .c  o  m*/

    GL11.glViewport(0, 0, displayWidth, displayHeight);

    GL11.glMatrixMode(GL11.GL_PROJECTION); // Apply subsequent matrix operations to the projection matrix stack.
    GL11.glLoadIdentity();
    GL11.glOrtho(0, displayWidth, displayHeight, 0, -1, 1);

    GL11.glMatrixMode(GL11.GL_TEXTURE);
    GL11.glLoadIdentity();

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
    AsyncTexture.unbind();

    // Enable alpha channels for images
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_BLEND);

    Graph.g.setDimensions(displayWidth, displayHeight);
    Graphics.setCurrent(Graph.g);
    Graph.g.setDrawMode(Graphics.MODE_NORMAL);
}

From source file:ar.com.quark.backend.lwjgl.opengl.DesktopGLES20.java

License:Apache License

/**
 * {@inheritDoc}/*  w w w .  j  a  v  a  2s .  c  o  m*/
 */
@Override
public void glViewport(int x, int y, int width, int height) {
    GL11.glViewport(x, y, width, height);
}

From source file:arg.RenderRecipe.java

License:Open Source License

public void draw() {

    File dir = new File(Minecraft.getMinecraft().mcDataDir, "recipes");
    if (!dir.exists() && !dir.mkdirs()) {
        throw new RuntimeException("The recipes directory could not be created: " + dir);
    }/*from ww  w. jav  a  2s  .  c o m*/

    name = name.replace(" ", "");
    File file = new File(Minecraft.getMinecraft().mcDataDir, "recipes/" + name + ".png");

    if (file.exists())
        return;

    GL11.glPushMatrix();
    GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
    GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glViewport(0, 0, width, height);
    GL11.glOrtho(0.0D, xSize, ySize, 0.0D, 1000.0D, 3000.0D);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    GL11.glTranslatef(0.0F, 0.0F, -2000.0F);
    GL11.glLineWidth(1.0F);

    GL11.glEnable(GL11.GL_COLOR_MATERIAL);

    try {
        drawScreen(0, 0, 0);
    } catch (Exception e) {
        e.printStackTrace();
    }

    int[] pixels = new int[width * height];
    int bindex;

    ByteBuffer fb = ByteBuffer.allocateDirect(width * height * 3);

    GL11.glReadPixels(0, 0, width, height, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, fb);
    GL11.glPopMatrix();
    GL11.glPopAttrib();
    GL11.glPopClientAttrib();
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    try {
        Display.swapBuffers();
    } catch (LWJGLException e1) {
        e1.printStackTrace();
    }

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            int i = (x + (width * y)) * 3;
            int r = fb.get(i) & 0xFF;
            int g = fb.get(i + 1) & 0xFF;
            int b = fb.get(i + 2) & 0xFF;
            image.setRGB(x, height - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | b);
        }
    }

    try {
        ImageIO.write(image, "png", file);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:br.com.perin.renderEngine.DisplayManager.java

public static void createDisplay() {
    // Version 3.2
    ContextAttribs attribs = new ContextAttribs(3, 2).withForwardCompatible(true).withProfileCore(true)
            .withDebug(true);/*from  w  w w .ja v a  2s .  com*/
    // Create the screen
    try {
        Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
        Display.create(new PixelFormat(), attribs);
        Display.setTitle(TITLE);
    } catch (LWJGLException e) {
        System.out.println(e);
    }
    GL11.glViewport(0, 0, WIDTH, HEIGHT);
}

From source file:br.org.archimedes.gui.opengl.OpenGLWrapper.java

License:Open Source License

/**
 * Updates the window size in the workspace and resets the openGL
 * coordinates./*from w  w w .  jav a 2  s.  co m*/
 */
public void resize() {

    if (currentCanvas != null) {
        org.eclipse.swt.graphics.Rectangle rect = currentCanvas.getClientArea();
        GL11.glOrtho(-rect.width / 2, rect.width / 2, -rect.height / 2, rect.height / 2, -1.0, 1.0);
        Rectangle window = new Rectangle(0, 0, rect.width, rect.height);
        GL11.glViewport(0, 0, rect.width, rect.height);
        br.org.archimedes.Utils.getWorkspace().setWindowSize(window);
    }
}

From source file:cellularautomata.CellularAutomata.java

public static void renderGL() {
    try { //Trys to create a game window size 500x700.
        Display.setDisplayMode(new org.lwjgl.opengl.DisplayMode(800, 600));
        Display.create();//from  w  w  w .ja  v a2 s  . c o  m
    } catch (LWJGLException e) { //Catches exception if game window is not created.
        e.printStackTrace();
        System.exit(0);
    }

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);

    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Sets colour to white.
    GL11.glClearDepth(1);

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    GL11.glViewport(0, 0, 800, 600);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, 800, 600, 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    Display.setVSyncEnabled(vsync);
}

From source file:colonialdisplay.AntDisplayGL.java

@Override
protected void initGL() {
    Rectangle bounds = canvas.getClientArea();
    GL11.glViewport(bounds.x, bounds.y, bounds.width, bounds.height);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();//w w w.  j a v a 2 s  .co  m

    GL11.glOrtho(0, bounds.width, bounds.height, 0, 1, -1);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    initTextures();
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    createModel();
}