@Override public boolean initialize() { System.out.println("OS " + System.getProperty("os.name")); System.out.println("JAVA " + System.getProperty("java.version")); System.out.println("LWJGL " + Version.getVersion()); System.out.println("GLFW " + GLFW.glfwGetVersionString()); System.out.println("JOML 1.9.2"); // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!GLFW.glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } return true; }
public void init(){ WIDTH = 1920; HEIGHT = 1080; Window.setErrorCallback(GLFWErrorCallback.createPrint(System.err)); w = new Window(WIDTH, HEIGHT, "gl3DGE", true, 4, 0); w.setKeyCallback(new GLFWKeyCallback(){ @Override public void invoke(long window, int key, int scancode, int action, int mods) { // TODO Auto-generated method stub if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) glfwSetWindowShouldClose(window, true); } }); w.setCursorPos((double) WIDTH / 2, (double) HEIGHT / 2); AudioEngine.initAudioEngine(); Resource.setGameObjectDir("/mesh/"); Resource.setOBJDir("/obj/"); Resource.setTexDir("/tex/"); Resource.setShaderDir("/shaders/"); }
/** * Initializes the game. */ public void init() { /* Set error callback */ errorCallback = GLFWErrorCallback.createPrint(); glfwSetErrorCallback(errorCallback); /* Initialize GLFW */ if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW!"); } /* Create GLFW window */ window = new Window(640, 480, "Simple Game - Pong", true); /* Initialize timer */ timer.init(); /* Initialize renderer */ renderer.init(); /* Initialize states */ initStates(); /* Initializing done, set running to true */ running = true; }
public static boolean glfwInit() { boolean ret; if (Properties.VALIDATE.enabled) { debug("Registering GLFWErrorCallback"); /* Set a GLFW error callback first and remember any possibly current callback to delegate to */ errorCallback = new GLFWErrorCallback() { private final Map<Integer, String> ERROR_CODES = APIUtil.apiClassTokens((field, value) -> 0x10000 < value && value < 0x20000, null, org.lwjgl.glfw.GLFW.class); public void invoke(int error, long description) { String msg = getDescription(description); System.err.printf("[LWJGL] %s error\n", ERROR_CODES.get(error)); System.err.println("\tDescription : " + msg); System.err.println("\tStacktrace :"); StackTraceElement[] stack = Thread.currentThread().getStackTrace(); for (int i = 4; i < stack.length; i++) { System.err.print("\t\t"); System.err.println(stack[i].toString()); } if (userCallback != null) { userCallback.invoke(error, description); } } }; userCallback = org.lwjgl.glfw.GLFW.glfwSetErrorCallback(errorCallback); ret = org.lwjgl.glfw.GLFW.glfwInit(); if (!ret) { error("glfwInit returned false"); } } else { ret = org.lwjgl.glfw.GLFW.glfwInit(); } RT.glfwInitialized = ret; return ret; }
public static void initializeGLFW() { if (initGLFW) { return; } else { initGLFW = true; } System.out.println("OS " + System.getProperty("os.name")); System.out.println("JAVA " + System.getProperty("java.version")); System.out.println("LWJGL " + Version.getVersion()); System.out.println("GLFW " + GLFW.glfwGetVersionString()); System.out.println("JOML 1.9.2"); // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!GLFW.glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } }
public static Window createWindow(Scene scene, String title) { if (!GLFW.glfwInit()) { throw new IllegalStateException(); } errorCallback = new GLFWErrorCallback() { public void invoke(int error, long description) { System.err.println("["+ error + "] " + description); } }; GLFW.glfwSetErrorCallback(errorCallback); long window = GLFW.glfwCreateWindow(scene.getWidth(), scene.getHeight(), title, MemoryUtil.NULL, MemoryUtil.NULL); if (window == MemoryUtil.NULL) { System.err.println("Window returned NULL"); System.exit(-1); } GLFW.glfwMakeContextCurrent(window); GLFW.glfwShowWindow(window); GL.createCapabilities(); GLFW.glfwSwapInterval(1); scene.setGLinitilized(); return new Window(window); }
private static void ensureGlfwLoaded() { if(!glfwLoaded) { GLFWErrorCallback.createPrint(System.err).set(); if (!glfwInit()) { throw new IllegalStateException("Error initializing GLFW"); } glfwLoaded = true; } }
public static void create() { LoggerInternal.log("Initializing GLFW"); glfwSetErrorCallback(GLFWErrorCallback.createPrint(System.err)); if(!glfwInit()) { throw new RuntimeException("Unable to initialize GLFW"); } LoggerInternal.log("GLFW Version: " + glfwGetVersionString()); }
/** * Creates and sets the GLFW error callback to {@link System.err}. * Initializes the GLFW library. * * <b>This is required before the graphicslab windowing system is able to be * used.</b> * * Returns true if successful or throws {@link IllegalStateException} in * case GLFW failed to initialize. */ protected static boolean init() { if (isActive()) { return true; } errorCallback = GLFWErrorCallback.createPrint(System.err); errorCallback.set(); if (!(isActive = glfwInit())) { throw new IllegalStateException("Unable to initialize GLFW."); } return true; }
/** * Destroys any remaining windows or cursors. Frees the error callback. Once * this function is called, you must call init() again to use any of the * windowing functions. * * Precondition: none * Postcondition: the glfw callback will be freed * the callback field will be set to null * the glfw system will be terminated * the variable will be set to inactive */ protected static void terminate() { glfwTerminate(); GLFWErrorCallback previousCallback = glfwSetErrorCallback(null); if (previousCallback != null) { previousCallback.free(); } errorCallback = null; isActive = false; }
public static void initGlfwLib() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW"); // Configure glfw glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); }
public static void setErrorCallback(Consumer<String> consumer) { GLFWErrorCallback tmp = GLFWErrorCallback.createString( (int err,String str) -> consumer.accept(""+err+": "+str) ); GLFW.glfwSetErrorCallback(tmp); errorCallback = tmp; }
/** Convenience method to throw an IllegalStateException when an error occurs. */ public static void setErrorCallbackToThrowExceptions() { //Temporary variable ensures no race conditions occur with GC for the old callback GLFWErrorCallback tmp = GLFWErrorCallback.createThrow(); GLFW.glfwSetErrorCallback(tmp); errorCallback = tmp; }
/** Convenience method to print a message out to System.err when an error occurs */ public static void setErrorCallbackToLog(Logger log) { GLFWErrorCallback tmp = GLFWErrorCallback.createString( (int err,String str) -> log.error(""+err+": "+str) ); GLFW.glfwSetErrorCallback(tmp); errorCallback = tmp; }
public void init(){ glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err)); if (!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW"); window.create(); input.create(window.getId()); scenegraph.getCamera().init(); renderEngine.init(); }
public static void main(String... args) { GLFWErrorCallback errorCallback; glfwSetCallback(errorCallback = errorCallbackPrint(System.err)); if (glfwInit() != GL_TRUE) throw new RuntimeException("GLFW couldn't be initialized"); glfwDefaultWindowHints(); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); long id = glfwCreateWindow(300, 300, "Boom", NULL, NULL); glfwShowWindow(id); while (glfwWindowShouldClose(id) != GL_TRUE) { glfwPollEvents(); } glfwDestroyWindow(id); errorCallback.release(); glfwTerminate(); }
/** * Initializes the GLFW3 library. If you are not using the built-in Game class of the SilenceEngine, you should call * this method as soon as you can after loading the LWJGL3 natives. * * @return True if initialised successful, or else False. */ public static boolean init() { if (isInitialized()) return true; boolean state = glfwInit(); // Return immediately in case of error if (!state) return initialized = false; // Error callback that does nothing setErrorCallback(null); glfwErrorCallback = GLFWErrorCallback.create((error, description) -> errorCallback.invoke(error, MemoryUtil.memUTF8(description))); // Joystick callback that does nothing setJoystickCallback(null); glfwJoystickCallback = GLFWJoystickCallback.create((joy, event) -> joystickCallback.invoke(joy, event == GLFW_CONNECTED)); // Register the callback glfwSetErrorCallback(glfwErrorCallback); return initialized = true; }
public static void setCallbacks() { glfwSetErrorCallback(GLFWErrorCallback.createPrint(System.err)); }
private void init() { ChessMaster.getLogger().info("Initializing GLFW"); errorCallback = GLFWErrorCallback.createPrint(System.err).set(); if (!glfwInit()) ChessMaster.getLogger().error("Cannot initialize GLFW!", new RuntimeException()); ChessMaster.getLogger().info("GLFW Creation complete"); glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); window = glfwCreateWindow(600, 600, "Chess Master", MemoryUtil.NULL, MemoryUtil.NULL); if (window == MemoryUtil.NULL) ChessMaster.getLogger().error("Cannot create window!", new RuntimeException()); glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> { switch (action) { case GLFW_RELEASE: ChessMaster.postEvent(new KeyEvent.Release(window, key, scancode, mods)); break; case GLFW_PRESS: ChessMaster.postEvent(new KeyEvent.Press(window, key, scancode, mods)); break; case GLFW_REPEAT: ChessMaster.postEvent(new KeyEvent.Repeat(window, key, scancode, mods)); } }); glfwSetWindowSizeCallback(window, (window1, w, h) -> { if (w > 0 && h > 0) { width = w; height = h; } }); try (MemoryStack stack = MemoryStack.stackPush()) { IntBuffer pWidth = stack.mallocInt(1); // int* IntBuffer pHeight = stack.mallocInt(1); // int* // Get the window size passed to glfwCreateWindow glfwGetWindowSize(window, pWidth, pHeight); // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center the window glfwSetWindowPos( window, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2 ); } // Make the OpenGL context current glfwMakeContextCurrent(window); glEnable(GL_TEXTURE_2D); // Make the window visible glfwShowWindow(window); board = new Board(); ChessMaster.getLogger().info("Initialization Complete"); }
private void init(int width, int height, String title) { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW if(!glfwInit()){ throw new IllegalStateException("Unable to initialize GLFW"); } // Specify OpenGL 3.2 core profile context, with forward compatibility (for Mac) glfwDefaultWindowHints(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); // Allows our window to be resizable glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // Create main window window = glfwCreateWindow(width, height, title, NULL, NULL); // Check if window was created if(window == NULL){ System.err.println("Could not create our Window!"); } // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center window glfwSetWindowPos( window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); // Set context current to this window glfwMakeContextCurrent(window); // Show the window glfwShowWindow(window); // vsync off // glfwSwapInterval(0); }
public static void main(String[] args) throws Exception { System.setProperty("org.lwjgl.librarypath", new File("libs").getAbsolutePath()); //Creation de la fenetre //------------------------------------------------------------------------------------ errorCallback = new GLFWErrorCallback() { public void invoke(int error, long description) { System.err.println("ID : " + error + " | Description :" + description); } }; // glfwSetErrorCallback(errorCallback); if(!glfwInit())throw new Exception("GLFW not init"); glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GL11.GL_FALSE); glfwWindowHint(GLFW_RESIZABLE, GL11.GL_FALSE); glfwWindowHint(GLFW_SAMPLES, 4);//Activation du MSAA x4 // glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); windowID = glfwCreateWindow(WIDTH,HEIGHT,TITLE,NULL,NULL); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); glfwSetWindowPos(windowID,(vidmode.width()-WIDTH)/2,(vidmode.height()-HEIGHT)/2); glfwShowWindow(windowID); glfwMakeContextCurrent(windowID); GL.createCapabilities(); System.out.println("OpenGL Version :" + glGetString(GL_VERSION)); System.out.println("GLSL Shader Version :" + glGetString(GL20.GL_SHADING_LANGUAGE_VERSION)); //------------------------------------------------------------------------------------ //Creation du device audio //------------------------------------------------------------------------------------ Audio.create(); //------------------------------------------------------------------------------------ //initialisation //------------------------------------------------------------------------------------ //glEnable(GL_MULTISAMPLE);//Activation du MSAA Input.init(); game = new MainMenuGame(); Camera.transform(); //------------------------------------------------------------------------------------ while(!glfwWindowShouldClose(windowID) && !isDestroy){ if(System.currentTimeMillis() - previousTicks >= 1000/120){//Update TICKS glfwPollEvents(); Input.update(); game.update(); previousTicks = System.currentTimeMillis(); delta = (float)(System.currentTimeMillis() - previous)/1000.0f; previous = System.currentTimeMillis(); TICKS++; }else{//Update FPS DisplayManager.clear(); DisplayManager.preRender2D(); DisplayManager.render2D(); DisplayManager.preRenderGUI(); DisplayManager.renderGUI(); glfwSwapBuffers(windowID); FPS++; } if(System.currentTimeMillis() - previousInfo >= 1000){ glfwSetWindowTitle(windowID, TITLE + " | FPS:" + FPS + " TICKS:" + TICKS); FPS = 0; TICKS = 0; previousInfo = System.currentTimeMillis(); } } }
public App(IState initialState) { GLFW.glfwSetErrorCallback(GLFWErrorCallback.createPrint(System.err)); init(initialState); }
public static void CreateWindow(int width, int height, String title) { try { if(!glfwInit()) throw new Exception("GLFW Initialization failed."); glfwSetErrorCallback(m_errorCallback = GLFWErrorCallback.createPrint(System.err)); glfwDefaultWindowHints(); glfwWindowHint(GLFW_VISIBLE, GL_FALSE); glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_REFRESH_RATE , GLFW_DONT_CARE); glfwWindowHint(GLFW_DOUBLEBUFFER , GL_TRUE); Window.WIDTH = width; Window.HEIGHT = height; m_window = glfwCreateWindow(width, height, title, NULL, NULL); if(m_window == 0) throw new Exception("GLFW Window creation failed."); GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( m_window, (vidmode.width() - WIDTH) / 2, (vidmode.height() - HEIGHT) / 2 ); Mouse = window.new Mouse(); Mouse.Create(m_window); glfwSetWindowSizeCallback(m_window, m_resizeCallBack = new GLFWWindowSizeCallback() { @Override public void invoke(long arg0, int arg1, int arg2) { Window.WIDTH = arg1; Window.HEIGHT = arg2; } }); glfwMakeContextCurrent(m_window); glfwSwapInterval(0); glfwShowWindow(m_window); GL.createCapabilities(); int vao = GL30.glGenVertexArrays (); GL30.glBindVertexArray (vao); } catch (Exception e) { e.printStackTrace(); System.exit(0); } }
private GLFWErrorCallback setErrorPrintStream(PrintStream printStream) { GLFWErrorCallback.createPrint(printStream).set(); return GLFWErrorCallback.createPrint(printStream).set(); }
/** * Initialize the renderer. */ public void init() { // Show a status message System.out.println("Initializing " + VoxelTex.ENGINE_NAME + " renderer..."); // Create and configure the error callback, make sure it was created successfully glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err)); if(glfwInit() != GL11.GL_TRUE) throw new IllegalStateException("Unable to initialize GLFW"); // Set the default window hints this.window.glDefaultWindowHints(); // Set the visibility and resizability of the window this.window.setHintVisible(false); this.window.setHintResizable(true); // Create the window this.window.glCreateWindow(); // Initialize the input manager for this window Input.init(this.window); // Create the framebuffer size callback glfwSetFramebufferSizeCallback(this.window.getWindowId(), fbCallback = new GLFWFramebufferSizeCallback() { @Override public void invoke(long windowId, int width, int height) { // Update the window size if(width > 0 && height > 0) window.setSize(width, height); } }); // Center the window this.window.centerWindow(); // Create an int buffer for the window IntBuffer framebufferSize = BufferUtils.createIntBuffer(2); nglfwGetFramebufferSize(this.window.getWindowId(), memAddress(framebufferSize), memAddress(framebufferSize) + 4); // Set the window size this.window.setSize(framebufferSize.get(0), framebufferSize.get(1)); // Make the window context this.window.glMakeContextCurrent(); // Set the swap interval (V-sync) glfwSwapInterval(0); // Show the window this.window.glShowWindow(); // Center the cursor Input.centerMouseCursor(); // Create the rendering capabilities, required by LWJGL GL.createCapabilities(); // Print the OpenGL version System.out.println("OpenGL " + GL11.glGetString(GL11.GL_VERSION)); // Set the clear color glClearColor(0.9f, 0.9f, 0.9f, 1.0f); // Enable depth testing glEnable(GL_DEPTH_TEST); // Load the engine shaders ShaderManager.load(); // Initialize the Time object Time.init(); // Show a status message System.out.println(VoxelTex.ENGINE_NAME + " renderer initialized successfully!"); }
/** * Sets the error callback for the game */ public static void setCallbacks() { glfwSetErrorCallback(GLFWErrorCallback.createPrint(System.err)); }
public static void setErrorCallback(GLFWErrorCallback ecb){ glfwSetErrorCallback(ecb); }
public static void setErrorCallback(GLFWErrorCallback callback) { GLFW.glfwSetErrorCallback(callback); errorCallback = callback; //GLFWErrorCallback.createString((int err,String str) -> LOGGER.warning(""+err+": "+str)); }
/** Convenience method to print a message out to System.err when an error occurs */ public static void setErrorCallbackToPrintToSterr() { GLFWErrorCallback tmp = GLFWErrorCallback.createPrint(System.err); GLFW.glfwSetErrorCallback(tmp); errorCallback = tmp; }
public void init() { ar = Aargon.getInstance(); graphicsThread = ar.getThreadPool().submit(() -> { try { errorCb = GLFWErrorCallback.createPrint(); GLFW.glfwSetErrorCallback(errorCb); if (GLFW.glfwInit() != GLFW.GLFW_TRUE) throw new IllegalStateException("Could not initialize GLFW!"); GLFW.glfwDefaultWindowHints(); GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE); GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GLFW.GLFW_FALSE); winId = GLFW.glfwCreateWindow(DEF_WIDTH, DEF_HEIGHT, "OpenAargon", MemoryUtil.NULL, MemoryUtil.NULL); if (winId == MemoryUtil.NULL) throw new IllegalStateException("Could not initialize window!"); GLFW.glfwSetKeyCallback(winId, ar.getInputManager().getKeyCallback()); GLFW.glfwSetMouseButtonCallback(winId, ar.getInputManager().getMouseCallback()); GLFW.glfwSetCursorPosCallback(winId, ar.getInputManager().getCursorCallback()); windowSizeCb = new GLFWWindowSizeCallback() { @Override public void invoke(long id, int w, int h) { windowSize.setX(w).setY(h); windowResized.set(true); } }; GLFW.glfwSetWindowSizeCallback(winId, windowSizeCb); GLFWVidMode vidMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); GLFW.glfwSetWindowPos(winId, (vidMode.width() - DEF_WIDTH) / 2, (vidMode.height() - DEF_HEIGHT) / 2); GLFW.glfwMakeContextCurrent(winId); GLFW.glfwSwapInterval(1); GL.createCapabilities(); vaoId = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vaoId); vboId = GL15.glGenBuffers(); GL30.glBindVertexArray(0); initShaders(); GL11.glClearColor(0F, 0F, 0F, 1F); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glEnable(GL11.GL_LINE_SMOOTH); GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST); GL11.glViewport(0, 0, windowSize.getX(), windowSize.getY()); while (GLFW.glfwWindowShouldClose(winId) == GLFW.GLFW_FALSE) { if (windowResized.getAndSet(false)) GL11.glViewport(0, 0, windowSize.getX(), windowSize.getY()); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); ar.bufferRenders(WORLD_WIDTH, WORLD_HEIGHT, (float)windowSize.getX() / (float)windowSize.getY()); render(); GLFW.glfwSwapBuffers(winId); GLFW.glfwPollEvents(); } } catch (Exception e) { Aargon.getLogger().error("Graphics thread errored!"); e.printStackTrace(); } finally { destruct(); new Thread(Main::exitRequested, "Exit Thread").run(); } }); }
protected GLFWPlatform(IImageSupport imageSupport) { this.errorCallback = GLFWErrorCallback.createPrint(System.err); this.imageSupport = imageSupport; this.mainThread = Thread.currentThread(); }
@RequiresNonNull("this.mav") @EnsuresNonNull("this.canvas") @UIEffect private void finishInitialization(boolean es) { GLFWErrorCallback ecb = GLFWErrorCallback.createPrint(System.err); mav.keepAlive(ecb); glfwSetErrorCallback(ecb); GLFWWindowSizeCallback scb = GLFWWindowSizeCallback.create(this::updateWindowSize); mav.keepAlive(scb); glfwSetWindowSizeCallback(window, scb); updateWindowSize(window, DEFAULT_WIDTH, DEFAULT_HEIGHT); String version = getGLVersion(es); int major = version.charAt(0)-'0'; int minor = version.charAt(2)-'0'; if (es) { if (major >= 3) { log.info("Using OpenGL ES 3 rendering"); canvas = new NanoVGGLES3Canvas(mav); } else if (major >= 2) { log.info("Using OpenGL ES 2 rendering"); canvas = new NanoVGGLES2Canvas(mav); } else { throw new Panic("panic.noSuitableContext", I18n.get("panic.noSuitableContext.onlyGlEs", version)); } } else { if (major >= 3) { log.info("Using OpenGL 3 rendering"); canvas = new NanoVGGL3Canvas(mav); } else if (major >= 2) { log.info("Using OpenGL 2 rendering"); canvas = new NanoVGGL2Canvas(mav); } else { throw new Panic("panic.noSuitableContext", I18n.get("panic.noSuitableContext.onlyGl", version)); } } glfwShowWindow(window); if (glfwExtensionSupported("WGL_EXT_swap_control_tear") || glfwExtensionSupported("GLX_EXT_swap_control_tear")) { log.info("Using tearing prevention"); glfwSwapInterval(-1); } else { glfwSwapInterval(1); } }
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); }
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); }
public void init() { // Setup an error callback. The default implementation // will print the error message in System.err. GLFWErrorCallback.createPrint(System.err).set(); // Initialize GLFW. Most GLFW functions will not work before doing this. if (!glfwInit()) { throw new IllegalStateException("Unable to initialize GLFW"); } glfwDefaultWindowHints(); // optional, the current window hints are already the default glfwWindowHint(GLFW_VISIBLE, GL_FALSE); // the window will stay hidden after creation glfwWindowHint(GLFW_RESIZABLE, GL_TRUE); // the window will be resizable glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Create the window windowHandle = glfwCreateWindow(width, height, title, NULL, NULL); if (windowHandle == NULL) { throw new RuntimeException("Failed to create the GLFW window"); } // Setup resize callback glfwSetFramebufferSizeCallback(windowHandle, (window, width, height) -> { this.width = width; this.height = height; this.setResized(true); }); // Setup a key callback. It will be called every time a key is pressed, repeated or released. glfwSetKeyCallback(windowHandle, (window, key, scancode, action, mods) -> { if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) { glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop } }); // Get the resolution of the primary monitor GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); // Center our window glfwSetWindowPos( windowHandle, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2 ); // Make the OpenGL context current glfwMakeContextCurrent(windowHandle); if (isvSync()) { // Enable v-sync glfwSwapInterval(1); } // Make the window visible glfwShowWindow(windowHandle); GL.createCapabilities(); // Set the clear color glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glEnable(GL_DEPTH_TEST); //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); // Support for transparencies glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); }