List of usage examples for org.lwjgl.opengl GL11 glViewport
public static void glViewport(@NativeType("GLint") int x, @NativeType("GLint") int y, @NativeType("GLsizei") int w, @NativeType("GLsizei") int h)
From source file:com.opengrave.og.light.DepthCubeFramebuffer.java
License:Open Source License
public void bindDraw(int direction) { Util.checkErr();//from ww w . ja v a 2 s . c o m GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer); shadowMap.bindToFrameBuffer(direction); Util.checkErr(); Util.checkErr(); GL11.glDisable(GL11.GL_BLEND); Util.checkErr(); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthFunc(GL11.GL_LESS); GL11.glDepthMask(true); Util.checkErr(); GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT); Util.checkErr(); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glViewport(0, 0, framebufferSize, framebufferSize); }
From source file:com.opengrave.og.MainThread.java
License:Open Source License
public void gameLoop() { Util.checkErr();/*w w w .jav a 2 s .co m*/ double lasttime = getTime(), lastFPS = getTime(); int fps = 0; while (running) { if (needsConfigUpdate) { createConfig(); needsConfigUpdate = false; } synchronized (toDoList) { while (toDoList.size() > 0) { Runnable runnable = toDoList.remove(0); runnable.run(); } } if (nextState != null) { // Something has caused us to switch states, stop the last // cleanly and start the next if (state != null) { state.stop(); state.finalise(); } state = nextState; state.prestart(); state.start(); nextState = null; } // Update FPS counter in window title TODO: Remove from window title // and place into a debug context ingame if (getTime() - lastFPS > 1000) { // use fps value fps = 0; lastFPS += 1000; } fps++; // Prepare time delta for updating graphics double time = getTime(); float delta = (float) (time - lasttime); // TODO Change delta to double as a rule? lasttime = time; input.doEet(state, delta); Util.checkErr(); state.updateGUI(delta); Util.checkErr(); state.update(delta); // Pre-render update Util.checkErr(); // Clear frame ready for next frame GL11.glClearColor(0.5f, 0.5f, 0.5f, 1.0f); GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_COLOR_BUFFER_BIT); GL11.glViewport(0, 0, lastW, lastH); set2D(); state.renderGUI(); if (glfwWindowShouldClose(window) == GL_TRUE) { running = false; } glfwPollEvents(); // if (fpsCap > 10) { glfwSwapBuffers(window); // } Util.checkErr(); } running = false; // soundSystem.cleanup(); System.exit(1); }
From source file:com.owens.oobjloader.Main.java
License:BSD License
/** * @throws Exception if init fails//from ww w .j ava 2 s . c om */ private static void init(boolean fullscreen) throws Exception { // Create a fullscreen window with 1:1 orthographic 2D projection (default) Display.setTitle(WINDOW_TITLE); Display.setFullscreen(fullscreen); // Enable vsync if we can (due to how OpenGL works, it cannot be guarenteed to always work) Display.setVSyncEnabled(true); // Create default display of 640x480 Display.create(); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); float fAspect = (float) Display.getDisplayMode().getWidth() / (float) Display.getDisplayMode().getHeight(); GLU.gluPerspective(45.0f, fAspect, 1.0f, 400.0f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glViewport(0, 0, Display.getDisplayMode().getWidth() - 100, Display.getDisplayMode().getHeight() - 100); }
From source file:com.pwootage.pokebot.PokebotUI.java
License:Open Source License
private void render() { glMatrixMode(GL11.GL_PROJECTION);/*from ww w . java 2 s . c o m*/ glLoadIdentity(); GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight()); GLU.gluOrtho2D(0, 1, 0, 1); glMatrixMode(GL11.GL_MODELVIEW); glLoadIdentity(); updateTextureIfRequired(); if (frameTex != null) { drawFrame(); } if (tilesTex != null) { drawTilesTex(); } }
From source file:com.runescape.client.revised.editor.modelviewer.Viewport.java
License:Open Source License
public void render() { final Dimension size = this.canvas.getSize(); if ((size.width > 0) && (size.height > 0)) { if ((this.width != size.width) || (this.height != size.height)) { this.width = size.width; this.height = size.height; GL11.glViewport(0, 0, this.width, this.height); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity();//from w w w . j av a 2 s . c o m final float c = (float) Math .sqrt((double) (this.width * this.width) + (double) (this.height * this.height)); GL11.glOrtho(0.0F, this.width, 0.0F, this.height, -c, c); GL11.glMatrixMode(GL11.GL_MODELVIEW); final boolean useShader = this.initShader(); if (ModelConstants.ENABLE_VERTEX_SHADER && useShader) { ARBShaderObjects.glUseProgramObjectARB(this.program); } if (ModelConstants.ENABLE_LIGHTING) { GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_LIGHT0); final FloatBuffer diffuse = BufferUtils.createFloatBuffer(4) .put(new float[] { 1F, 1F, 1F, 1F }); final FloatBuffer position = BufferUtils.createFloatBuffer(4) .put(new float[] { 3F, 0F, 1F, 0F }); final FloatBuffer ambient = BufferUtils.createFloatBuffer(4) .put(new float[] { .1F, .1F, .2F, .3F }); final FloatBuffer specular = BufferUtils.createFloatBuffer(4) .put(new float[] { 1F, 1F, 1F, 1F }); GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, (FloatBuffer) specular.flip()); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, (FloatBuffer) ambient.flip()); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, (FloatBuffer) diffuse.flip()); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, (FloatBuffer) position.flip()); GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SHININESS, 50.0f); } } if (Mouse.isButtonDown(0) && !Mouse.isButtonDown(1)) { this.yaw -= Mouse.getDX(); this.pitch -= Mouse.getDY(); } if (Mouse.isButtonDown(0) && Mouse.isButtonDown(1)) { this.offset_z += Mouse.getDY(); } float wheel = Mouse.getDWheel() / 960.0F; if (wheel > 1.0F) { wheel = 1.0F; } else if (wheel < -1.0F) { wheel = -1.0F; } this.scale -= this.scale * wheel; if (this.scale < 0.01F) { this.scale = 0.01F; } for (final Model3D dragonModel : this.getDragonList()) { final float x = this.width / 1.2F; final float y = (-((100.0F * (this.scale))) + (this.offset_z + 0.1F)) + ((this.height - dragonModel.height()) / 2.0F); final float z = 0.0F; dragonModel.calcDimms(false); dragonModel.render(x, y, z, this.pitch, this.yaw, this.roll, this.scale, this.scale, this.scale); } for (final Model3D torvaModel : this.getTorvaList()) { final float x = this.width / 1.7F; final float y = (-((100.0F * (this.scale))) + this.offset_z) + ((this.height - torvaModel.height()) / 2.0F); final float z = 0.0F; torvaModel.calcDimms(false); torvaModel.render(x, y, z, this.pitch, this.yaw, this.roll, this.scale, this.scale, this.scale); } for (final Model3D jadModel : this.getJadList()) { final float x = this.width / 3.2F; final float y = (-((100.0F * (this.scale))) + this.offset_z) + ((this.height - jadModel.height()) / 2.0F); final float z = 0.0F; jadModel.calcDimms(false); jadModel.render(x, y, z, this.pitch, this.yaw, this.roll, this.scale, this.scale, this.scale); } for (final Model3D trollModel : this.getTrollList()) { final float x = this.width / 3.8F; final float y = (-((100.0F * (this.scale))) + this.offset_z) + ((this.height - trollModel.height()) / 2.0F); final float z = 0.0F; trollModel.calcDimms(false); trollModel.render(x, y, z, this.pitch, this.yaw, this.roll, this.scale, this.scale, this.scale); } if (ModelConstants.ENABLE_VERTEX_SHADER && this.initShader()) { ARBShaderObjects.glUseProgramObjectARB(0); } Display.update(); } }
From source file:com.samrj.devil.game.Game.java
License:Open Source License
/** * Creates a new game object. Initializes the window with the given config. * /* ww w . j av a 2 s. c o m*/ * @param title The title of the window. * @param hints The window hints to use. * @param config The configuration to use. */ public Game(String title, HintSet hints, GameConfig config) { if (title == null || config == null) throw new NullPointerException(); if (!initialized) throw new IllegalStateException("Game.init() not called."); ensureMainThread(); // <editor-fold defaultstate="collapsed" desc="Initialize Window"> { GLFW.glfwDefaultWindowHints(); GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GL11.GL_FALSE); GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GL11.GL_FALSE); GLFW.glfwWindowHint(GLFW.GLFW_DECORATED, config.borderless ? GL11.GL_FALSE : GL11.GL_TRUE); GLFW.glfwWindowHint(GLFW.GLFW_FLOATING, GL11.GL_FALSE); GLFW.glfwWindowHint(GLFW.GLFW_STENCIL_BITS, 0); if (config.msaa > 0) GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES, config.msaa); if (hints != null) hints.glfw(); GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_DEBUG_CONTEXT, GL11.GL_TRUE); monitor = config.fullscreen ? GLFW.glfwGetPrimaryMonitor() : 0; window = GLFW.glfwCreateWindow(config.resolution.x, config.resolution.y, title, monitor, 0); GLFW.glfwMakeContextCurrent(window); GLFW.glfwSwapInterval(config.vsync ? 1 : 0); GLFW.glfwSetInputMode(window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_DISABLED); } if (!config.fullscreen) //Center window { Vec2i windowSize = GLFWUtil.getWindowSize(window); GLFWVidMode mode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); GLFW.glfwSetWindowPos(window, (mode.width() - windowSize.x) / 2, (mode.height() - windowSize.y) / 2); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Initialize OpenGL Context"> { capabilities = GL.createCapabilities(); GL11.glViewport(0, 0, config.resolution.x, config.resolution.y); GL11.glDisable(GL13.GL_MULTISAMPLE); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Initialize Sync"> { if (!config.vsync && config.fps > 0) { sync = new Sync(config.fps, config.sleeper); frameTime = sync.getFrameTime(); } else { sync = null; GLFWVidMode mode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); frameTime = Math.round(1_000_000_000.0 / mode.refreshRate()); } } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="Initialize Input"> { mouse = new Mouse(window, this::onMouseMoved, this::onMouseButton, this::onMouseScroll); mouse.setGrabbed(false); keyboard = new Keyboard(this::onKey); eventBuffer = new EventBuffer(window, mouse, keyboard); } // </editor-fold> stepper = config.stepper; }
From source file:com.sriramramani.droid.inspector.ui.InspectorCanvas.java
License:Mozilla Public License
private void doResize() { // Get the aspect ratio. Rectangle bounds = getBounds(); float aspectRatio = (float) bounds.width / (float) bounds.height; // Set current. setCurrent();// w w w . j a v a 2s.c o m // Reset viewport. GL11.glViewport(0, 0, bounds.width, bounds.height); // Set the projection matrix. GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); if (mIsOrtho) { // Changing top and bottom to make it draw in 4th quadrant. GL11.glOrtho(0, bounds.width, bounds.height, 0, mZNear, mZFar); } else { // Perspective is viewing-angle, aspect-ratio, (-z, z). GLU.gluPerspective(45.0f, aspectRatio, mZNear, mZFar); } // Set the model view matrix. GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); refresh(); }
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 {/* ww w . ja va 2 s . co m*/ 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.voxelplugineering.voxelsniper.render.RenderMain.java
License:Open Source License
private void setupOpenGL() { // Setup an OpenGL context with API version 3.2 try {// w w w . j a v a2s . c o m PixelFormat pixelFormat = new PixelFormat(); ContextAttribs contextAtrributes = new ContextAttribs(3, 2).withForwardCompatible(true) .withProfileCore(true); Display.setDisplayMode(new DisplayMode(this.width, this.height)); Display.setTitle("VoxelGunsmithEngine"); Display.create(pixelFormat, contextAtrributes); GL11.glViewport(0, 0, this.width, this.height); } catch (LWJGLException e) { if (Standalone.DEBUG) { System.out.println("Failed creating display"); } e.printStackTrace(); System.exit(-1); } // Setup an XNA like background color GL11.glClearColor(RenderingConstants.CLEAR_COLOUR_R, RenderingConstants.CLEAR_COLOUR_G, RenderingConstants.CLEAR_COLOUR_B, RenderingConstants.CLEAR_COLOUR_A); GL11.glViewport(0, 0, this.width, this.height); // cull back faces GL11.glEnable(GL11.GL_CULL_FACE); GL11.glCullFace(GL11.GL_BACK); GL11.glFrontFace(GL11.GL_CW); OpenGLUtilities.checkGLError("setup OpenGL"); }
From source file:com.xrbpowered.gl.Client.java
License:Open Source License
public void switchToWindowed(int width, int height, boolean resizeResources) throws LWJGLException { System.setProperty("org.lwjgl.opengl.Window.undecorated", "false"); Display.setFullscreen(false);// w w w . ja va 2s . c o m Display.setDisplayMode(new DisplayMode(width, height)); Display.setResizable(true); if (resizeResources) { GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight()); createRenderTarget(); resizeResources(); } }