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:net.minecraft.client.gui.GuiAchievement.java

private void updateAchievementWindowScale() {
    GL11.glViewport(0, 0, this.theGame.displayWidth, this.theGame.displayHeight);
    GL11.glMatrixMode(5889 /*GL_PROJECTION*/);
    GL11.glLoadIdentity();/* w w  w. ja  v a 2  s . c o  m*/
    GL11.glMatrixMode(5888 /*GL_MODELVIEW0_ARB*/);
    GL11.glLoadIdentity();
    this.achievementWindowWidth = this.theGame.displayWidth;
    this.achievementWindowHeight = this.theGame.displayHeight;
    ScaledResolution var1 = new ScaledResolution(this.theGame.gameSettings, this.theGame.displayWidth,
            this.theGame.displayHeight);
    this.achievementWindowWidth = var1.getScaledWidth();
    this.achievementWindowHeight = var1.getScaledHeight();
    GL11.glClear(256);
    GL11.glMatrixMode(5889 /*GL_PROJECTION*/);
    GL11.glLoadIdentity();
    GL11.glOrtho(0.0D, (double) this.achievementWindowWidth, (double) this.achievementWindowHeight, 0.0D,
            1000.0D, 3000.0D);
    GL11.glMatrixMode(5888 /*GL_MODELVIEW0_ARB*/);
    GL11.glLoadIdentity();
    GL11.glTranslatef(0.0F, 0.0F, -2000.0F);
}

From source file:net.neilcsmith.praxis.video.opengl.internal.FrameBuffer.java

License:Apache License

/** Makes the frame buffer current so everything gets drawn to it. */
public void begin() {
    GL11.glViewport(0, 0, colorTexture.getWidth(), colorTexture.getHeight());
    bind();
}

From source file:net.neilcsmith.praxis.video.opengl.internal.FrameBuffer.java

License:Apache License

/** Unbinds the framebuffer, all drawing will be performed to the normal framebuffer from here on. */
public void end() {
    GL11.glViewport(0, 0, GLContext.getCurrent().getWidth(), GLContext.getCurrent().getHeight());
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
}

From source file:net.neilcsmith.praxis.video.opengl.internal.GLRenderer.java

License:Apache License

private void activate() {
    if (active) {
        return;/*ww w.  j  a  v a 2  s  .c  o  m*/
    }

    GL11.glDepthMask(false);
    GL11.glEnable(GL11.GL_TEXTURE_2D);

    FrameBuffer fbo = null;
    boolean clear = false;
    target = null;

    if (surface != null) {
        GLSurfaceData data = surface.getData();
        if (data == null) {
            LOGGER.finest("Setting up render to empty surface");
            data = new GLSurfaceData(surface.getWidth(), surface.getHeight(), surface.hasAlpha());
            data.texture = context.getTextureManager().acquire(data.width, data.height);
            surface.setData(data);
            clear = true;
        } else if (data.usage > 1) {
            LOGGER.finest("Setting up render to shared surface");
            data.usage--;
            if (data.texture == null) {
                data.texture = context.getTextureManager().acquire(data.width, data.height);
                syncPixelsToTexture(data);
            }
            data.texture.getFrameBuffer().bind();
            data = new GLSurfaceData(surface.getWidth(), surface.getHeight(), surface.hasAlpha());
            data.texture = context.getTextureManager().acquire(data.width, data.height);
            data.texture.bind();
            GL11.glCopyTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, 0, 0, data.width, data.height);
            surface.setData(data);
        } else if (data.texture == null) {
            LOGGER.finest("Setting up render to pixel backed surface");
            data.texture = context.getTextureManager().acquire(data.width, data.height);
            syncPixelsToTexture(data);
        }
        data.pixels = null;
        target = data.texture;
        fbo = data.texture.getFrameBuffer();
    }

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

    if (fbo == null) {
        LOGGER.finest("Setting up render to screen");
        int w = GLContext.getCurrent().getWidth();
        int h = GLContext.getCurrent().getHeight();
        FrameBuffer.unbind();
        GL11.glViewport(0, 0, w, h);
        projectionMatrix.setToOrtho2D(0, 0, w, h);
    } else {
        LOGGER.finest("Setting up render to texture");
        fbo.bind();
        int w = surface.getWidth();
        int h = surface.getHeight();
        GL11.glViewport(0, 0, w, h);
        projectionMatrix.setToOrtho2D(0, h, w, -h);
    }

    if (customShader != null) {
        customShader.begin();
    } else {
        shader.begin();
    }
    setupMatrices();

    active = true;

    if (clear) {
        clear();
    }

}

From source file:net.phatcode.rel.multimedia.Renderer.java

License:Open Source License

Renderer(int screenWidth, int screenHeight) {
    try {/*from  ww w .j a v a  2s  .c  o m*/
        Display.setDisplayMode(new DisplayMode(screenWidth, screenHeight));
        Display.create();
        Display.setTitle("AnyaBasic 0.4.0 beta");
    } catch (LWJGLException e) {
        e.printStackTrace();
    }

    this.screenWidth = screenWidth;
    this.screenHeight = screenHeight;

    GL11.glViewport(0, 0, screenWidth, screenHeight);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();

    GL11.glOrtho(0, screenWidth, screenHeight, 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glLoadIdentity();

    GL11.glShadeModel(GL11.GL_SMOOTH); //set shading to smooth(try GL_FLAT)
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); //set Clear color to BLACK
    GL11.glClearDepth(1.0f); //Set Depth buffer to 1(z-Buffer)
    GL11.glDisable(GL11.GL_DEPTH_TEST); //Disable Depth Testing so that our z-buffer works

    GL11.glDepthFunc(GL11.GL_LEQUAL);

    GL11.glEnable(GL11.GL_COLOR_MATERIAL);

    GL11.glEnable(GL11.GL_TEXTURE_2D);

    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glAlphaFunc(GL11.GL_GREATER, 0);

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

    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);

    GL11.glDisable(GL11.GL_CULL_FACE);

    GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    GL11.glTranslatef(0.375f, 0.375f, 0); // magic trick

}

From source file:net.smert.frameworkgl.opengl.OpenGL1.java

License:Apache License

public OpenGL1 setViewport(int x, int y, int width, int height) {
    viewportX = x;//w ww  . j  av  a2 s  .  c o  m
    viewportY = y;
    viewportWidth = width;
    viewportHeight = height;
    GL11.glViewport(x, y, width, height);
    return this;
}

From source file:opengl.test.OpenGL.java

public OpenGL() {
    GLFW.glfwSetErrorCallback(errorCallback);
    if (GLFW.glfwInit() != GLFW.GLFW_TRUE) {
        throw new RuntimeException("Khong the khoi tao glfw");
    }/*from www.  j  a v  a 2s .c o m*/

    GLFW.glfwDefaultWindowHints();
    GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 3);// su dung opengl phien ban 3.2 --> GLSL phien bn 1.50
    GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 2);
    GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
    GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GLFW.GLFW_TRUE);

    this.windowID = GLFW.glfwCreateWindow(this.width, this.height, this.title, MemoryUtil.NULL,
            MemoryUtil.NULL);
    if (this.windowID == MemoryUtil.NULL) {
        throw new RuntimeException("Khong the tao window");
    }

    GLFW.glfwMakeContextCurrent(windowID);
    GL.createCapabilities();
    GLFW.glfwSwapInterval(1);

    this.keyCallback = new GLFWKeyCallback() {
        @Override
        public void invoke(long arg0, int arg1, int arg2, int arg3, int arg4) {
            if (arg1 == GLFW.GLFW_KEY_ESCAPE && arg3 != GLFW.GLFW_RELEASE) {
                GLFW.glfwSetWindowShouldClose(windowID, GL11.GL_TRUE);
            }
            OpenGL.this.keyCallback(arg0, arg1, arg2, arg3, arg4);
        }
    };
    this.windowSizeCallback = new GLFWWindowSizeCallback() {
        @Override
        public void invoke(long arg0, int arg1, int arg2) {
            GL11.glViewport(0, 0, arg1, arg2);// view port 0,0 goc tre, arg1, arg2 goc duoi cung !
        }

    };
    this.cursorPosCallback = new GLFWCursorPosCallback() {
        @Override
        public void invoke(long arg0, double arg1, double arg2) {
            OpenGL.this.cursorCallback(arg0, arg1, arg2);
        }

    };
    GLFW.glfwSetWindowSizeCallback(windowID, windowSizeCallback);
    GLFW.glfwSetKeyCallback(windowID, keyCallback);
    GLFW.glfwSetCursorPosCallback(windowID, cursorPosCallback);
    try {
        this.init();
        this.loop();
    } catch (InterruptedException ex) {
        throw new RuntimeException("Loop !!!1");
    }

}

From source file:org.agpu.oc.common.tileentity.AdvancedMonitor.java

public void startDrawing3D(int x, int y, int width, int height, float fov, float zNear, float zFar) {
    if (worldObj.isRemote) {
        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID);

        GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
        GL11.glViewport(0, 0, width, height);

        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPushMatrix();//from   w w w . j  a  v a2 s .c  o  m
        GL11.glLoadIdentity();
        GLU.gluPerspective(fov, (float) width / (float) height, zNear, zFar);

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

        GL11.glClearColor(cr, cg, cb, ca);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    }
}

From source file:org.agpu.oc.common.tileentity.AdvancedMonitor.java

public void startDrawing2D(int x, int y, int width, int height) {
    if (worldObj.isRemote) {
        GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferID);

        GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
        GL11.glViewport(x, y, width, height);

        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPushMatrix();/*from www. j a v a2s.c  o m*/
        GL11.glLoadIdentity();
        GL11.glOrtho(0, width, height, 0, 1, -1);

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

        GL11.glClearColor(cr, cg, cb, ca);
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
    }
}

From source file:org.bonsaimind.badgersvoyage.tools.planetstudio.Studio.java

License:Open Source License

public void run() {
    GL11.glClearColor(0.2f, 0.5f, 1f, 0f);
    GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight());

    //GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);

    while (!Display.isCloseRequested() && !closeRequested) {
        processKeyboard();//from w  w  w.  j  a  va2 s .co  m
        ErrorChecker.exitOnOpenGlError("After processKeyboard.");

        camera.startTranslate();
        sphere.translate();
        camera.endTranslate();
        ErrorChecker.exitOnOpenGlError("End of Translate.");

        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

        GL20.glUseProgram(programId);
        sphere.render();

        GL20.glDisableVertexAttribArray(0);
        GL30.glDeleteVertexArrays(0);

        GL20.glUseProgram(0);

        Display.sync(60);
        Display.update();

        ErrorChecker.exitOnOpenGlError("End of main loop.");

    }

    Display.destroy();

}