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:org.cogaen.lwjgl.scene.Camera.java

License:Open Source License

void applyTransform() {
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();// w  ww  . j a  v a  2  s.  c  om
    GL11.glOrtho(0, this.width, 0, this.height, 1, -1);
    GL11.glTranslated(this.width / 2, this.height / 2, 0.0);

    GL11.glScaled(this.zoom, this.zoom, 0.0);
    GL11.glRotatef((float) -this.angle, 0, 0, 1);
    GL11.glTranslated(-this.posX, -this.posY, 0);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glViewport(this.viewport.getX(), this.viewport.getY(), this.viewport.getWidth(),
            this.viewport.getHeight());
}

From source file:org.cogaen.lwjgl.scene.SceneService.java

License:Open Source License

public void renderScene() {

    // quite and dirty frame counter
    this.clock.tick();
    this.fpsSum += this.clock.getDelta();
    if (++this.fpsCnt >= this.fpsAvg) {
        this.fpsCnt = 0;
        this.fps = String.format("FPS: %2.2f", (1.0 / (this.fpsSum / this.fpsAvg)));
        this.fpsSum = 0.0;
    }//from w  w w .j av  a 2  s.c o  m

    // Clear the screen and depth buffer
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

    // render layers in each camera
    for (Camera camera : cameras) {
        if (!camera.isActive()) {
            continue;
        }

        camera.applyTransform();
        for (int i = this.layers.size() - 1; i >= 0; --i) {
            this.layers.get(i).render(camera.getMask());
        }

        for (RenderSubsystem rs : this.subSystems) {
            rs.render(camera.getMask());
        }
    }

    // draw overlays
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, 1.0, 0, 1.0 / getAspectRatio(), 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glViewport(0, 0, this.config.getWidth(), this.config.getHeight());

    this.overlayRoot.renderWithAspectRatio(0xFFFFFFFF, getAspectRatio());
    //      this.overlayRoot.render(0xFFFFFFFF);

    // render frame counter
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, this.config.getWidth(), this.config.getHeight(), 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glColor4d(1, 0, 1, 1);
    font.drawString(5, this.config.getHeight() - 20, this.fps);

    Display.update();

    if (Display.isCloseRequested()) {
        this.evtSrv.dispatchEvent(new SimpleEvent(WINDOW_CLOSE_REQUEST));
    }
}

From source file:org.eclipse.swt.opengl.examples.LWJGLExample.java

License:Open Source License

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Composite comp = new Composite(shell, SWT.NONE);
    comp.setLayout(new FillLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;/*w w w .  ja v a2s .  co m*/
    final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);

    canvas.setCurrent();
    try {
        GLContext.useContext(canvas);
    } catch (LWJGLException e) {
        e.printStackTrace();
    }

    canvas.addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event event) {
            Rectangle bounds = canvas.getBounds();
            float fAspect = (float) bounds.width / (float) bounds.height;
            canvas.setCurrent();
            try {
                GLContext.useContext(canvas);
            } catch (LWJGLException e) {
                e.printStackTrace();
            }
            GL11.glViewport(0, 0, bounds.width, bounds.height);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
        }
    });

    GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glColor3f(1.0f, 0.0f, 0.0f);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glClearDepth(1.0);
    GL11.glLineWidth(2);
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    shell.setText("SWT/LWJGL Example");
    shell.setSize(640, 480);
    shell.open();

    display.asyncExec(new Runnable() {
        int rot = 0;

        public void run() {
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                try {
                    GLContext.useContext(canvas);
                } catch (LWJGLException e) {
                    e.printStackTrace();
                }
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                GL11.glClearColor(.3f, .5f, .8f, 1.0f);
                GL11.glLoadIdentity();
                GL11.glTranslatef(0.0f, 0.0f, -10.0f);
                float frot = rot;
                GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
                GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
                rot++;
                GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
                GL11.glColor3f(0.9f, 0.9f, 0.9f);
                drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
                canvas.swapBuffers();
                display.asyncExec(this);
            }
        }
    });

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet195.java

License:Open Source License

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Composite comp = new Composite(shell, SWT.NONE);
    comp.setLayout(new FillLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;/* w  w w . j  a  v a  2s  . com*/
    final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);

    canvas.setCurrent();
    try {
        GLContext.useContext(canvas);
    } catch (LWJGLException e) {
        e.printStackTrace();
    }

    canvas.addListener(SWT.Resize, new Listener() {
        @Override
        public void handleEvent(Event event) {
            Rectangle bounds = canvas.getBounds();
            float fAspect = (float) bounds.width / (float) bounds.height;
            canvas.setCurrent();
            try {
                GLContext.useContext(canvas);
            } catch (LWJGLException e) {
                e.printStackTrace();
            }
            GL11.glViewport(0, 0, bounds.width, bounds.height);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
        }
    });

    GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glColor3f(1.0f, 0.0f, 0.0f);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glClearDepth(1.0);
    GL11.glLineWidth(2);
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    shell.setText("SWT/LWJGL Example");
    shell.setSize(640, 480);
    shell.open();

    final Runnable run = new Runnable() {
        int rot = 0;

        @Override
        public void run() {
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                try {
                    GLContext.useContext(canvas);
                } catch (LWJGLException e) {
                    e.printStackTrace();
                }
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                GL11.glClearColor(.3f, .5f, .8f, 1.0f);
                GL11.glLoadIdentity();
                GL11.glTranslatef(0.0f, 0.0f, -10.0f);
                float frot = rot;
                GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
                GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
                rot++;
                GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
                GL11.glColor3f(0.9f, 0.9f, 0.9f);
                drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
                canvas.swapBuffers();
                display.asyncExec(this);
            }
        }
    };
    canvas.addListener(SWT.Paint, new Listener() {
        @Override
        public void handleEvent(Event event) {
            run.run();
        }
    });
    display.asyncExec(run);

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.eclipse.swt.snippets.Snippet341.java

License:Open Source License

public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;//ww  w.j av a 2  s . co m
    final GLCanvas canvas = new GLCanvas(shell, SWT.NONE, data);
    canvas.setLayoutData(new GridData(640, 480));

    canvas.setCurrent();
    try {
        GLContext.useContext(canvas);
    } catch (LWJGLException e) {
        e.printStackTrace();
    }

    canvas.addListener(SWT.Resize, new Listener() {
        @Override
        public void handleEvent(Event event) {
            Rectangle bounds = canvas.getBounds();
            float fAspect = (float) bounds.width / (float) bounds.height;
            canvas.setCurrent();
            try {
                GLContext.useContext(canvas);
            } catch (LWJGLException e) {
                e.printStackTrace();
            }
            GL11.glViewport(0, 0, bounds.width, bounds.height);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
        }
    });

    GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glColor3f(1.0f, 0.0f, 0.0f);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glClearDepth(1.0);
    GL11.glLineWidth(2);
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    Button button = new Button(shell, SWT.PUSH);
    button.setText("Capture");
    button.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event event) {
            capture(canvas);
        }
    });
    shell.pack();
    shell.open();

    display.asyncExec(new Runnable() {
        int rot = 0;

        @Override
        public void run() {
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                try {
                    GLContext.useContext(canvas);
                } catch (LWJGLException e) {
                    e.printStackTrace();
                }
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                GL11.glClearColor(.3f, .5f, .8f, 1.0f);
                GL11.glLoadIdentity();
                GL11.glTranslatef(0.0f, 0.0f, -10.0f);
                float frot = rot;
                GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
                GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
                rot++;
                GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
                GL11.glColor3f(0.9f, 0.9f, 0.9f);
                drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
                canvas.swapBuffers();
                display.asyncExec(this);
            }
        }
    });

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.fenggui.binding.render.lwjgl.LWJGLOpenGL.java

License:Open Source License

public void setViewPort(int x, int y, int width, int height) {
    GL11.glViewport(x, y, width, height);
}

From source file:org.fenggui.example.ExampleBasisLWJGL.java

License:Open Source License

private void glInit(int width, int height) {
    // Go into orthographic projection mode.
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();/*from  w w  w . j  a v  a2  s.  co m*/
    GLU.gluOrtho2D(0, width, 0, height);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    GL11.glViewport(0, 0, width, height);

    //set clear color to ... ugly
    GL11.glClearColor(0.1f, 0.5f, 0.2f, 0.0f);
    //sync frame (only works on windows )   => THAT IS NOT TRUE (ask Rainer)
    Display.setVSyncEnabled(false);
}

From source file:org.free.jake2.render.lwjgl.Main.java

License:Open Source License

/**
 * R_SetupGL/*from w w w.j  a  va2 s. c o  m*/
 */
void R_SetupGL() {

    //
    // set up viewport
    //
    //int x = (int) Math.floor(r_newrefdef.x * vid.width / vid.width);
    int x = r_newrefdef.x;
    //int x2 = (int) Math.ceil((r_newrefdef.x + r_newrefdef.width) * vid.width / vid.width);
    int x2 = r_newrefdef.x + r_newrefdef.width;
    //int y = (int) Math.floor(vid.height - r_newrefdef.y * vid.height / vid.height);
    int y = vid.height - r_newrefdef.y;
    //int y2 = (int) Math.ceil(vid.height - (r_newrefdef.y + r_newrefdef.height) * vid.height / vid.height);
    int y2 = vid.height - (r_newrefdef.y + r_newrefdef.height);

    int w = x2 - x;
    int h = y - y2;

    GL11.glViewport(x, y2, w, h);

    //
    // set up projection matrix
    //
    float screenaspect = (float) r_newrefdef.width / r_newrefdef.height;
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    MYgluPerspective(r_newrefdef.fov_y, screenaspect, 4, 4096);

    GL11.glCullFace(GL11.GL_FRONT);

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

    GL11.glRotatef(-90, 1, 0, 0); // put Z going up
    GL11.glRotatef(90, 0, 0, 1); // put Z going up
    GL11.glRotatef(-r_newrefdef.viewangles[2], 1, 0, 0);
    GL11.glRotatef(-r_newrefdef.viewangles[0], 0, 1, 0);
    GL11.glRotatef(-r_newrefdef.viewangles[1], 0, 0, 1);
    GL11.glTranslatef(-r_newrefdef.vieworg[0], -r_newrefdef.vieworg[1], -r_newrefdef.vieworg[2]);

    GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, r_world_matrix);
    r_world_matrix.clear();

    //
    // set drawing parms
    //
    if (gl_cull.value != 0.0f) {
        GL11.glEnable(GL11.GL_CULL_FACE);
    } else {
        GL11.glDisable(GL11.GL_CULL_FACE);
    }

    GL11.glDisable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_ALPHA_TEST);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
}

From source file:org.free.jake2.render.lwjgl.Main.java

License:Open Source License

/**
 * R_BeginFrame/* w w w  . j  a va  2 s.c o  m*/
 */
protected void R_BeginFrame(float camera_separation) {

    gl_state.camera_separation = camera_separation;

    /*
     ** change modes if necessary
     */
    if (gl_mode.modified || vid_fullscreen.modified) {
        // FIXME: only restart if CDS is required
        cvar ref;

        ref = Cvar.Get("vid_ref", "lwjgl", 0);
        ref.modified = true;
    }

    if (gl_log.modified) {
        GLimp_EnableLogging((gl_log.value != 0.0f));
        gl_log.modified = false;
    }

    if (gl_log.value != 0.0f) {
        GLimp_LogNewFrame();
    }

    /*
     ** update 3Dfx gamma -- it is expected that a user will do a vid_restart
     ** after tweaking this value
     */
    if (vid_gamma.modified) {
        vid_gamma.modified = false;

        if ((gl_config.renderer & GL_RENDERER_VOODOO) != 0) {
            // wird erstmal nicht gebraucht

            /*
            char envbuffer[1024];
            float g;
                    
            g = 2.00 * ( 0.8 - ( vid_gamma->value - 0.5 ) ) + 1.0F;
            Com_sprintf( envbuffer, sizeof(envbuffer), "SSTV2_GAMMA=%f", g );
            putenv( envbuffer );
            Com_sprintf( envbuffer, sizeof(envbuffer), "SST_GAMMA=%f", g );
            putenv( envbuffer );
             */
            VID.Printf(Defines.PRINT_DEVELOPER, "gamma anpassung fuer VOODOO nicht gesetzt");
        }
    }

    GLimp_BeginFrame(camera_separation);

    /*
     ** go into 2D mode
     */
    GL11.glViewport(0, 0, vid.width, vid.height);
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, vid.width, vid.height, 0, -99999, 99999);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glColor4f(1, 1, 1, 1);

    /*
     ** draw buffer stuff
     */
    if (gl_drawbuffer.modified) {
        gl_drawbuffer.modified = false;

        if (gl_state.camera_separation == 0 || !gl_state.stereo_enabled) {
            if (gl_drawbuffer.string.equalsIgnoreCase("GL_FRONT")) {
                GL11.glDrawBuffer(GL11.GL_FRONT);
            } else {
                GL11.glDrawBuffer(GL11.GL_BACK);
            }
        }
    }

    /*
     ** texturemode stuff
     */
    if (gl_texturemode.modified) {
        GL_TextureMode(gl_texturemode.string);
        gl_texturemode.modified = false;
    }

    if (gl_texturealphamode.modified) {
        GL_TextureAlphaMode(gl_texturealphamode.string);
        gl_texturealphamode.modified = false;
    }

    if (gl_texturesolidmode.modified) {
        GL_TextureSolidMode(gl_texturesolidmode.string);
        gl_texturesolidmode.modified = false;
    }

    /*
     ** swapinterval stuff
     */
    GL_UpdateSwapInterval();

    //
    // clear screen if desired
    //
    R_Clear();
}

From source file:org.geekygoblin.nedetlesmaki.game.systems.DrawSystem.java

License:Open Source License

@Override
protected void processEntities(ImmutableBag<Entity> entities) {
    GL11.glClearColor(99f / 255f, 201f / 255f, 183f / 255f, 1f);
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
    Sort.instance().sort(sprites, 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();/*from   w  w  w . j  a va  2 s. c o  m*/
    GL11.glLoadIdentity();

    updateViewPort();
    GL11.glViewport(viewPort.x, viewPort.y, viewPort.width, viewPort.height);
    GLU.gluOrtho2D(-VirtualResolution.WIDTH / 2.0f, VirtualResolution.WIDTH / 2.0f,
            VirtualResolution.HEIGHT / 2.0f, -VirtualResolution.HEIGHT / 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);

    NedGame game = (NedGame) world;
    Entity ned = game.getNed();
    if (null != ned) {
        Sprite nedSprite = spriteMapper.get(ned);
        Vector nedPos = spriteProjector.project(nedSprite.getPosition());
        GL11.glTranslatef(-nedPos.x, -nedPos.y, 0.0f);
    }

    for (Entity e : backgrounds) {
        LevelBackground level = levelBackgroundMapper.getSafe(e);
        if (null != level) {
            drawLevel(level);
        }
    }

    GL11.glPushMatrix();
    GL11.glScalef(spriteGlobalScale, spriteGlobalScale, 1.0f);
    spriteBatcher.begin();
    for (Entity e : sprites) {
        spriteBatcher.draw(spriteMapper.getSafe(e));
    }
    spriteBatcher.end();
    for (Entity e : sprites) {
        drawSpriteLabel(spriteMapper.getSafe(e));
    }
    GL11.glPopMatrix();

    for (Entity e : uis) {
        MainMenu mainMenu = mainMenuMapper.getSafe(e);
        if (null != mainMenu) {
            nuitRenderer.render(mainMenu.getRoot());
        }
        DialogComponent dialog = dialogMapper.getSafe(e);
        if (null != dialog) {
            nuitRenderer.render(dialog.getRoot());
        }
        InGameUI inGameUI = inGameUIMapper.getSafe(e);
        if (null != inGameUI) {
            nuitRenderer.render(inGameUI.getRoot());
        }
    }
    GL11.glPopMatrix();
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPopMatrix();
    GL11.glPopAttrib();

}