List of usage examples for org.lwjgl.opengl GL11 glOrtho
public static native void glOrtho(@NativeType("GLdouble") double l, @NativeType("GLdouble") double r, @NativeType("GLdouble") double b, @NativeType("GLdouble") double t, @NativeType("GLdouble") double n, @NativeType("GLdouble") double f);
(lb – n)T
and (rt – n)T
specify the points on the near clipping plane that are mapped to the lower left and upper right corners of the window, respectively (assuming that the eye is located at (0 0 0)T
). From source file:com.telinc1.rpjg.Game.java
License:Apache License
public void start() { // Start logging. Configurator.defaultConfig().writer(new ConsoleWriter()) .formatPattern("[{date:yyyy-MM-dd HH:mm:ss}] [{level}] [{class_name}] {message}").activate(); Logger.info("Creating and initializing game."); // Create the display. try {//from w w w .j a va 2 s. c om Display.setTitle(GameOptions.GAME_NAME); Display.setResizable(false); Display.setDisplayMode(new DisplayMode(640, 360)); Display.setVSyncEnabled(true); Display.setFullscreen(false); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); System.exit(ExitCodes.INIT_DISPLAY); } finally { this.isRunning = true; Logger.info("Finished display creation."); } // Initialize OpenGL. GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_LIGHTING); GL11.glClearColor(0f, 0f, 0f, 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, Display.getWidth(), Display.getHeight()); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); // Load all textures. TextureLoader.initialize(); // Initialize the game. this.initialize(); // Load the default map. this.loadMap("dungeon"); ModuleManager.getInstance().openModule(new ModuleMap()); // Main game loop while (this.isRunning() && !Display.isCloseRequested()) { // Clear the screen from the previous frame. GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); this.loop(); this.draw(); this.collectInput(); // Sync and update the display. Display.update(); Display.sync(GameOptions.FRAME_RATE); } // Free up all resources and exit. Logger.info("Close requested!"); TextureLoader.destroy(); Display.destroy(); Logger.info("Resources destroyed - exiting."); System.exit(ExitCodes.CLOSE_REQUESTED); }
From source file:com.telinc1.rpjg.Game.java
License:Apache License
private void resize() { GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1); }
From source file:de.codesourcery.flocking.LWJGLRenderer.java
License:Apache License
private void initGL() { GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity();//from w ww . j a va 2 s . c o m GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight()); GL11.glOrtho(0, Display.getWidth(), 0, Display.getHeight(), 1, -1); // GL11.glMatrixMode(GL11.GL_MODELVIEW); }
From source file:displayexample.DisplayExample.java
public void start() { x = 15;/*w w w.j av a2 s . c o m*/ y = 15; try { Display.setTitle("Exemple de fentre !"); Display.setDisplayMode(new DisplayMode(800, 600)); Display.create(); } catch (LWJGLException e) { e.printStackTrace(); System.exit(0); } box = new Box2D(30.0f, 50.0f, 25.0f); box.setUp(); // init OpenGL here GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, 800, 0, 600, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); while (!Display.isCloseRequested() && !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { // render OpenGL here box.draw(); pollInput(); Display.update(); Display.sync(60); } Display.destroy(); System.exit(0); }
From source file:dripdisplay.DripDisplayLWJGL.java
protected void initGLLWJGL() { if (!LEVEL_EDITOR) { GL11.glViewport(0, 0, 800, 600); } else {// w w w . ja v a2 s .c o m GL11.glViewport(0, 0, 1000, 800); } GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); if (!LEVEL_EDITOR) { GL11.glOrtho(0, 800, 600, 0, 1, -1); } else { GL11.glOrtho(0, 1000, 800, 0, 1, -1); } GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); initTextures(); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); createModel(); }
From source file:edu.csun.ecs.cs.multitouchj.ui.utility.OpenGlUtility.java
License:Apache License
public static void orthoMode(Size size) { GL11.glDisable(GL11.GL_DEPTH_TEST);//from ww w . j a v a 2 s. c om GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glPushMatrix(); GL11.glLoadIdentity(); GL11.glOrtho(0, size.getWidth(), 0, size.getHeight(), -10, 10); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glPushMatrix(); GL11.glLoadIdentity(); }
From source file:espresso3d.engine.window.viewport.E3DViewport.java
License:Open Source License
/** * This will automatically be called by the engine. Users needn't worry about this. * Sets the perspective to the values stored in this viewport. This keeps track of whether * the values have changed or not, so it will keep the GL calls to a minimum (only set the perspective * if something has actually changed).//from w w w .jav a 2 s. c o m * */ private void setPerspective() { if (perspectiveChanged) { GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix GL11.glLoadIdentity(); // Reset The Projection Matrix if (mode == VIEWPORT_MODE_PERSPECTIVE) { // Calculate The Aspect Ratio Of The Window GLU.gluPerspective((float) fovY, (float) ((float) width / (float) height), (float) nearClipPlane, (float) farClipPlane); } else if (mode == VIEWPORT_MODE_ORTHOGRAPHIC) GL11.glOrtho(left * orthoZoom, right * orthoZoom, bottom * orthoZoom, top * orthoZoom, nearClipPlane, farClipPlane); //todo: this needs to center around the camera. Need to determin whether to use X/Y, Y/Z, or X/Z to center on recalcProjectionViewMatrix(); perspectiveChanged = false; } GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Projection Matrix GL11.glLoadIdentity(); // Reset The Modelview Matrix GL11.glDepthMask(true); //Re-enable this. IF particles turn this off, it has to be turned on to be able to clear the depth buffer GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer GLU.gluLookAt((float) cameraActor.getOrientation().getPosition().getX(), (float) cameraActor.getOrientation().getPosition().getY(), (float) cameraActor.getOrientation().getPosition().getZ(), ((float) (cameraActor.getOrientation().getPosition().getX() + cameraActor.getOrientation().getForward().getX())), ((float) (cameraActor.getOrientation().getPosition().getY() + cameraActor.getOrientation().getForward().getY())), ((float) (cameraActor.getOrientation().getPosition().getZ() + cameraActor.getOrientation().getForward().getZ())), (float) cameraActor.getOrientation().getUp().getX(), (float) cameraActor.getOrientation().getUp().getY(), (float) cameraActor.getOrientation().getUp().getZ()); //If something has changed camera wise, we need to recalculate the viewport matrix // the next time something asks for a projection or unprojection if (!cameraActor.getOrientation().getPosition().equals(lastPosition) || !cameraActor.getOrientation().getForward().equals(lastForward) || !cameraActor.getOrientation().getUp().equals(lastUp)) { lastPosition.set(cameraActor.getOrientation().getPosition()); lastForward.set(cameraActor.getOrientation().getForward()); lastUp.set(cameraActor.getOrientation().getUp()); needViewArrayRecalc = true; } }
From source file:eu.over9000.veya.gui.Gui.java
License:Open Source License
private static void setUpStates(final int width, final int height) { try {//w w w . ja va 2 s. c o m Display.setDisplayMode(new DisplayMode(width, height)); Display.create(); //Display.create(new PixelFormat().withSamples(4).withDepthBits(24), new ContextAttribs(3, 3)); Display.setVSyncEnabled(true); } catch (final 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.3f, 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:fable.framework.ui.views.chiPlotView.java
License:Open Source License
/** * This is a callback that will allow us to create the viewer and initialize * it.//w w w . j a v a 2 s . c om */ /* * (non-Javadoc) * * @see * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets * .Composite) */ /* * (non-Javadoc) * * @see * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets * .Composite) */ public void createPartControl(Composite parent) { // logger = FableLogger.getLogger(); console = new FableMessageConsole("Peaksearch console"); ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console }); console.displayOut("Welcome to chiplotview " + ToolBox.getPluginVersion(Activator.PLUGIN_ID)); IOConsoleOutputStream stream = console.newOutputStream(); // console_debug = new ConsoleLineTracker(); System.setOut(new PrintStream(stream, true)); System.setErr(new PrintStream(stream)); thisView = this; parent.setLayout(new GridLayout()); Composite controlPanelComposite = new Composite(parent, SWT.NULL); GridLayout controlGridLayout = new GridLayout(); controlGridLayout.numColumns = 8; controlPanelComposite.setLayout(controlGridLayout); controlPanelComposite.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); freezeButton = new Button(controlPanelComposite, SWT.CHECK); freezeButton.setText("Freeze"); freezeButton.setToolTipText("freeze 3d relief, disable rotation"); freezeButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (freezeButton.getSelection()) freeze = true; else freeze = false; } }); resetButton = new Button(controlPanelComposite, SWT.NULL); resetButton.setText("Reset"); resetButton.setToolTipText("reset 3d projection to be flat and fill the canvas"); resetButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { grip.init(); } }); autoscaleButton = new Button(controlPanelComposite, SWT.CHECK); autoscaleButton.setText("Autoscale"); autoscaleButton.setToolTipText("autoscale 3d relief between minimum and mean"); autoscaleButton.setSelection(true); autoscaleButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (autoscaleButton.getSelection()) { if (!autoscale) { autoscale = true; scaleImage(); drawReliefList(); } minimumSpinner.setEnabled(false); maximumSpinner.setEnabled(false); } else { if (autoscale) { autoscale = false; scaleImage(); drawReliefList(); } minimumSpinner.setEnabled(true); maximumSpinner.setEnabled(true); } } }); Label minLabel = new Label(controlPanelComposite, SWT.NULL); minLabel.setText("Minimum"); minimumSpinner = new Spinner(controlPanelComposite, SWT.NULL); minimumSpinner.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); minimumSpinner.setMinimum(0); minimumSpinner.setMaximum(Integer.MAX_VALUE); minimumSpinner.setEnabled(false); Label maxLabel = new Label(controlPanelComposite, SWT.NULL); maxLabel.setText("Maximum"); maximumSpinner = new Spinner(controlPanelComposite, SWT.NULL); maximumSpinner.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false)); maximumSpinner.setMinimum(0); maximumSpinner.setMaximum(Integer.MAX_VALUE); maximumSpinner.setEnabled(false); updateButton = new Button(controlPanelComposite, SWT.NULL); updateButton.setText("Update"); updateButton.setToolTipText("redraw 3d relief plot"); updateButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { scaleImage(); drawReliefList(); drawRelief(); } }); Composite comp = new Composite(parent, SWT.NONE); comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); comp.setLayout(new FillLayout()); GLData data = new GLData(); data.doubleBuffer = true; canvas = new GLCanvas(comp, SWT.NONE, data); canvas.setSize(comp.getSize()); canvas.setCurrent(); // context = // GL11.GLDrawableFactory.getFactory().createExternalGLContext(); canvas.addListener(SWT.Resize, new Listener() { public void handleEvent(Event event) { Rectangle bounds = canvas.getBounds(); 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 glu = new GLU(); // aspect = (float) imageWidth / (float) imageHeight; // gl.glMatrixMode(GL.GL_MODELVIEW); // gl.glLoadIdentity(); drawRelief(); canvas.swapBuffers(); } }); try { GLContext.useContext(canvas); } catch (LWJGLException e) { e.printStackTrace(); } GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glColor3f(1.0f, 0.0f, 0.0f); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); // gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); // gl.glClearDepth(1.0); // gl.glLineWidth(2); // / gl.glEnable(GL.GL_DEPTH_TEST); GL11.glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); // create the grip for users to change the orientation, translation and // zoom grip = new SceneGrip(); canvas.addMouseListener(grip); canvas.addMouseMoveListener(grip); canvas.addListener(SWT.MouseWheel, grip); canvas.addKeyListener(grip); // apparently opengl has to be redrawn constantly (why ?) Display.getCurrent().asyncExec(new Runnable() { public void run() { if (!canvas.isDisposed()) { canvas.setCurrent(); // Rectangle bounds = canvas.getBounds(); /* * canvasWidth = bounds.width; canvasHeight = bounds.height; */ // context.makeCurrent(); // GL gl = context.getGL (); // gl.glClear(GL.GL_COLOR_BUFFER_BIT | // GL.GL_DEPTH_BUFFER_BIT); // gl.glClearColor(.0f, .0f, .0f, 1.0f); // black // background*/ drawRelief(); canvas.swapBuffers(); } } }); }
From source file:fable.imageviewer.views.SceneGrip.java
License:Open Source License
/** * Warning called constantly in display loop - change with care. *///from w ww . j a v a2s.c o m public void adjust() { canvas.setCurrent(); try { GLContext.useContext(canvas); } catch (LWJGLException ex) { FableUtils.excMsg(ReliefView.class, "Error in adjust using GLContext.useContext", ex); } // gl = context.getGL (); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); /* set the orthogonal projection to the size of the window */ GL11.glOrtho(0, canvasWidth, canvasHeight, 0, -1.0e5f, 1.0e5f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glTranslatef(canvasWidth / 2 + this.xoff, canvasHeight / 2 + this.yoff, 0); GL11.glScalef(zoff, zoff, zoff); /* * zoff has no effect on the orthogonal projection therefore zoom by * passing zoff to scale */ GL11.glRotatef(this.xrot, 1f, 0.0f, 0.0f); GL11.glRotatef(this.yrot, 0.0f, 1f, 0.0f); GL11.glTranslatef(-prov.getImageWidth() / 2, -prov.getImageHeight() / 2, 0); }