List of usage examples for org.lwjgl.opengl GL11 glClearColor
public static void glClearColor(@NativeType("GLfloat") float red, @NativeType("GLfloat") float green, @NativeType("GLfloat") float blue, @NativeType("GLfloat") float alpha)
From source file:com.runescape.client.revised.editor.modelviewer.Main.java
License:Open Source License
public static void main(final String[] args) { Main.setMain(new Main()); try {// w ww . j ava 2s. c om Main.getMain().setCanvas(Main.getMain().setup("RuneScape Model Viewer", 1024, 768, true)); } catch (final Exception e) { e.printStackTrace(); } final Canvas canvas = Main.getMain().getCanvas(); final Frame frame = (Frame) canvas.getParent(); if (frame == null) { return; } try { Main.initialize(canvas); Main.getMain().setViewport(new Viewport(canvas)); final long[] timerCache = new long[10]; long timerCur = 0L; long timerDst = 0L; long timerLast = 0L; final long timerRate = (1000000L * 1000L) / 60L; int timerCacheIndex = 0; int timerCacheSize = 0; final boolean minSleep = Runtime.getRuntime().availableProcessors() <= 1; final long[] clockCache = new long[32]; int clockIndex = 0; while (frame.isVisible()) { final long clock = System.nanoTime(); final long lastClock = clockCache[clockIndex]; clockCache[clockIndex] = clock; if (++clockIndex == 32) { clockIndex = 0; } if ((lastClock != 0L) && (clock > lastClock)) { if (frame != null) { // frame.setTitle("" + fps); } } GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); GL11.glClearColor(.5F, .6F, .9F, 1F); Main.getMain().viewport.render(); if (minSleep) { try { Thread.sleep(1L); } catch (final Exception ex) { } } timerCache[timerCacheIndex++] = System.nanoTime(); if (timerCacheSize < timerCacheIndex) { timerCacheSize = timerCacheIndex; } if (timerCacheIndex == 10) { timerCacheIndex = 0; } long time = 0L; for (int i = 0; i != timerCacheSize; time += timerCache[i++]) { ; } time /= timerCacheSize; if (timerCacheSize == 1) { timerLast = time; } timerCur += time - timerLast; timerLast = time; timerDst += timerRate; if (timerDst > timerCur) { final long sleep = timerDst - timerCur; try { Thread.sleep(sleep / 1000000L, (int) (sleep % 1000000L)); } catch (final Exception ex) { } timerCur = timerDst; for (int i = 0; i != timerCacheSize; ++i) { timerCache[i] += sleep; } timerLast += sleep; } } } catch (final LWJGLException e) { e.printStackTrace(); } finally { Main.dispose(frame); } }
From source file:com.runescape.client.revised.editor.modelviewer.Main.java
License:Open Source License
public static void initialize(final Canvas modelCanvas) { try {/*from w w w . j av a2 s . c om*/ Display.setParent(modelCanvas); Display.create(new PixelFormat(8, 24, 8, 8)); Display.makeCurrent(); } catch (final LWJGLException lwjgle) { try { Display.create(new PixelFormat(8, 24, 8, 0)); } catch (final LWJGLException e) { e.printStackTrace(); } } Display.setVSyncEnabled(false); Display.setSwapInterval(0); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glClearColor(0.0F, 0.0F, 0.0F, 0.0F); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glClearDepth(1.0F); GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); GL11.glEnable(GL11.GL_NORMALIZE); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glEnable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_POINT_SMOOTH); GL11.glEnable(GL11.GL_POLYGON_SMOOTH); GL11.glEnable(GL11.GL_LINE_SMOOTH); GL11.glEnable(GL11.GL_COLOR_MATERIAL); GL11.glEnable(GL11.GL_ALPHA_TEST); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glEnable(GL11.GL_COLOR_MATERIAL); GL11.glColorMaterial(GL11.GL_FRONT, GL11.GL_DIFFUSE); GL11.glCullFace(GL11.GL_BACK); }
From source file:com.rvantwisk.cnctools.controls.opengl.OpenGLRenderer.java
License:Open Source License
protected void init() { GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glClearDepth(1.0);//w w w.j a v a2s . c om GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glEnable(GL11.GL_COLOR_MATERIAL); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); }
From source file:com.samrj.devil.graphics.GraphicsUtil.java
public static void glClearColor(Vec3 v) { GL11.glClearColor(v.x, v.y, v.z, 1.0f); }
From source file:com.samrj.devil.graphics.GraphicsUtil.java
public static void glClearColor(Vec4 v) { GL11.glClearColor(v.x, v.y, v.z, v.w); }
From source file:com.sriramramani.droid.inspector.ui.InspectorCanvas.java
License:Mozilla Public License
public InspectorCanvas(Composite parent, int style, GLData data) { super(parent, style, data); setCurrent();/*from w w w. ja v a 2 s.co m*/ // Clear the canvas. GL11.glClearColor(CLEAR_COLOR[0], CLEAR_COLOR[1], CLEAR_COLOR[2], CLEAR_COLOR[3]); GL11.glClearDepth(1.0f); GL11.glLineWidth(1.0f); GL11.glPointSize(1.0f); GL11.glShadeModel(GL11.GL_FLAT); GL11.glEnable(GL11.GL_LINE_SMOOTH); GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST); GL11.glEnable(GL11.GL_POLYGON_SMOOTH); GL11.glHint(GL11.GL_POLYGON_SMOOTH_HINT, GL11.GL_NICEST); GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); GL11.glDisable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthMask(true); GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glEnable(GL11.GL_ALPHA_TEST); GL11.glAlphaFunc(GL11.GL_GREATER, 0.01f); GL11.glEnable(GL11.GL_STENCIL_TEST); GL11.glStencilFunc(GL11.GL_ALWAYS, 0x1, 0xf); GL11.glStencilOp(GL11.GL_INCR, GL11.GL_KEEP, GL11.GL_INCR); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); reset(); mTransform = new Matrix4f(); mTransform.setIdentity(); addListener(SWT.Resize, this); addListener(SWT.Paint, this); addMouseListener(this); addMouseWheelListener(this); }
From source file:com.swinggl.elements.GLFrame.java
License:Open Source License
/** * This method starts the both the render and update loops. The thread that this is called on will become the render loop and occupy that thread entirely. * All glfwWindowHint's must be called before this is called while all other window attributes can be altered while the loop is running including changing * the FPS and UPS.//ww w. j a v a 2 s . co m */ public void run() { if (fullscreen) { window = glfwCreateWindow(windowWidth, windowHeight, title, glfwGetPrimaryMonitor(), secondWindowHandle); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); if (!(windowWidth == vidmode.width() && windowHeight == vidmode.height())) { Debug.println("GLFWVidMode [" + windowWidth + ", " + windowHeight + "] not available, switching to GLFWVidMode [" + vidmode.width() + ", " + vidmode.height() + "]", Debug.ANSI_YELLOW); windowWidth = vidmode.width(); windowHeight = vidmode.height(); } } else window = glfwCreateWindow(windowWidth, windowHeight, title, NULL, secondWindowHandle); if (window == NULL) throw new RuntimeException("Failed to create the GLFW window"); if (windowPosition == WINDOW_POSITION_CUSTOM && !fullscreen) glfwSetWindowPos(window, windowX, windowY); else if (!fullscreen) updateWindowPosition(); glfwSetKeyCallback(window, keyCallback); glfwSetCursorPosCallback(window, cursorPosCallback); glfwSetCursorEnterCallback(window, cursorEnterCallback); glfwSetMouseButtonCallback(window, mouseButtonCallback); glfwSetScrollCallback(window, scrollCallback); glfwSetWindowPosCallback(window, windowPosCallback); glfwSetWindowSizeCallback(window, windowSizeCallback); glfwSetWindowCloseCallback(window, windowCloseCallback); glfwSetWindowRefreshCallback(window, windowRefreshCallback); glfwSetWindowFocusCallback(window, windowFocusCallback); glfwSetWindowIconifyCallback(window, windowIconifyCallback); glfwSetDropCallback(window, dropCallback); if (mouseDisabled) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); else if (mouseHidden) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); else glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); glfwMakeContextCurrent(window); glfwSwapInterval(1); GL.createCapabilities(); GLUtil.setupDebugMessageCallback(); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, windowWidth, windowHeight, 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glClearColor(backgroundColor.getRed() / 255f, backgroundColor.getGreen() / 255f, backgroundColor.getBlue() / 255f, backgroundColor.getAlpha() / 255f); Debug.initialize(); if (visible) glfwShowWindow(window); new Thread(new Update(), "SwingGL | update").start(); long now = System.nanoTime(); long lastTime = now; double deltaR = 0.0; long lastRender = now; running = true; while (running) { if (glfwWindowShouldClose(window) == GL_TRUE) running = false; now = System.nanoTime(); deltaR += (now - lastTime) / renderNS; lastTime = now; if (deltaR >= 1.0) { renderDelta = (now - lastRender) / 1000000000.0f; render(renderDelta); lastRender = now; deltaR--; } } if (currentGameState != null) currentGameState.dispose(); try { glfwDestroyWindow(window); keyCallback.release(); cursorPosCallback.release(); mouseButtonCallback.release(); scrollCallback.release(); } finally { glfwTerminate(); errorCallback.release(); } }
From source file:com.swinggl.elements.GLFrame.java
License:Open Source License
/** * Sets the background color of the window * * @param color - The background color/* w w w.j av a2 s .c o m*/ */ public void setBackgroundColor(GLColor color) { backgroundColor = color; if (window != 0L) GL11.glClearColor(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); }
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 ww w .java 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.map.Map.java
License:Apache License
/** * Loads in and returns the given map.// www .jav a2s. co m * * @param name - The name of the directory which contains the map. * @return The loaded map, or null if not found or invalid. */ public static Map loadMap(String name) { String path = GameOptions.ASSETS_LOCATION + "maps/" + name + "/"; Map map = new Map(); try { // Load map header. DataInputStream header = new DataInputStream(new FileInputStream(new File(path + "header.dat"))); map.width = header.readShort(); map.height = header.readShort(); Tileset.loadTileset(header.readShort()); map.border = header.readShort(); map.clearColor = new Color(header.readInt()); GL11.glClearColor(map.clearColor.r, map.clearColor.g, map.clearColor.b, map.clearColor.a); map.name = header.readUTF(); map.floor = header.readByte(); header.close(); // Load tiles. map.tiles = new int[map.width * map.height]; DataInputStream tiles = new DataInputStream(new FileInputStream(new File(path + "tiles.dat"))); for (int i = 0; i < map.tiles.length; i++) { map.tiles[i] = tiles.readShort(); } tiles.close(); // Load collision data. map.collision = new int[map.width * map.height]; DataInputStream collision = new DataInputStream(new FileInputStream(new File(path + "collision.dat"))); for (int j = 0; j < map.collision.length; j++) { map.collision[j] = collision.readByte(); } collision.close(); // Load event data. map.events = new ArrayList<>(); DataInputStream events = new DataInputStream(new FileInputStream(new File(path + "events.dat"))); short amount = events.readShort(); for (int k = 0; k < amount; k++) { map.addEvent(events); } events.close(); } catch (IOException e) { e.printStackTrace(); } return map; }