Java 类org.lwjgl.opengl.GL 实例源码

项目:ChessMaster    文件:RenderLoop.java   
@Override
public void run() {
    init();
    glfwMakeContextCurrent(window);
    GL.createCapabilities();

    // Set the clear color
    glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
    while (!glfwWindowShouldClose(window)) {
        loop();
    }

    // Free the window callbacks and destroy the window
    glfwFreeCallbacks(window);
    glfwDestroyWindow(window);

    // Terminate GLFW and free the error callback
    glfwTerminate();
    glfwSetErrorCallback(errorCallback).free();
}
项目:Prepare4LudumDare    文件:Game.java   
/**
 * Initialize default state.
 */
private void init() {
    if (glfwInit() != GL_TRUE) {
        throw new IllegalStateException("GLFW failed to initialize!");
    }

    win = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, TITLE, 0, 0);
    glfwShowWindow(win);
    glfwMakeContextCurrent(win);

    GLContext.createFromCurrent();
    GL.createCapabilities(true);
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
项目:lambda    文件:OpenGLEngine.java   
public OpenGLEngine() {
    // Set OpenGL context
    GL.createCapabilities();

    // Set the clear color
    glClearColor(0.0f, 0.4f, 0.8f, 0.0f);

    // Enable transparent textures
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND); 
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    renderQueue = new RenderQueue();

    // TODO shader support
       shader = new ShaderProgram(
        new Shader("shaders/vertex.glsl", GL20.GL_VERTEX_SHADER),
        new Shader("shaders/fragment.glsl", GL20.GL_FRAGMENT_SHADER)
    );
}
项目:Geoscape    文件:Window.java   
/**
 * Initializes the GL parameters
 */
private void initGL() {
    GL.createCapabilities();

       for (int flag : GL_FLAGS) {
        glEnable(flag);
       }

       glClearColor(Colour.BACKDROP[0], Colour.BACKDROP[1], Colour.BACKDROP[2], Colour.BACKDROP[3]);

    // Matrix Initialization
       glMatrixMode(GL_PROJECTION);
       glLoadIdentity();

       // Define frustum
       float yTop  = (float) (VIEW_Z_NEAR * Math.tan(Math.toRadians(VIEW_FOV / 2)));
    float xLeft = yTop * VIEW_ASPECT;
    glFrustum(xLeft, -xLeft, -yTop, yTop, VIEW_Z_NEAR, VIEW_Z_FAR);

       glMatrixMode(GL_MODELVIEW);
       glLoadIdentity();
}
项目:gl3DGE    文件:LightingDemo.java   
public void loop(){
    GL.createCapabilities();

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glClearColor(0, 0, 0, 1);

    screen = new MainScreen(w);
    w.navigate(screen);

    while(!w.shouldClose()){
        w.loop();
    }
}
项目:lwjgl-utils    文件:Display.java   
/**
 * Initializes the GLFW display and GL capabilities.
 */
public void create()
{
    if (glfwInit() != GLFW_TRUE)
        throw new RuntimeException("Could not init GLFW.");
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    window = glfwCreateWindow(width, height, title, 0, 0);

    if (window == 0)
    {
        glfwTerminate();
        throw new RuntimeException("Window pointer is NULL.");
    }

    glfwMakeContextCurrent(window);
    glfwSwapInterval(vSync ? 1 : 0);
    GL.createCapabilities(true);
    glfwSetInputMode(window, GLFW_STICKY_KEYS, GLFW_TRUE);
    isCreated = true;
}
项目:Null-Engine    文件:Window.java   
/**
 * Create a window
 *
 * @param title               The window title
 * @param width               The window width
 * @param height              The window height
 * @param fullscreen          Wether it should be a fullscreen window
 * @param fullscreenVideoMode The video mode (ignored if fullscreen is <code>false</code>)
 * @param monitor             The monitor to put the window on (ignored if fullscreen is <code>false</code>)
 */
public Window(String title, int width, int height, boolean fullscreen, @Nullable GLFWVidMode fullscreenVideoMode, long monitor) {
    this.width = width;
    this.height = height;
    this.title = title;
    this.fullscreen = fullscreen;

    if (fullscreen) {
        GLFW.glfwWindowHint(GLFW.GLFW_RED_BITS, fullscreenVideoMode.redBits());
        GLFW.glfwWindowHint(GLFW.GLFW_GREEN_BITS, fullscreenVideoMode.greenBits());
        GLFW.glfwWindowHint(GLFW.GLFW_BLUE_BITS, fullscreenVideoMode.blueBits());
        GLFW.glfwWindowHint(GLFW.GLFW_REFRESH_RATE, fullscreenVideoMode.refreshRate());
        width = fullscreenVideoMode.width();
        height = fullscreenVideoMode.height();
    }

    window = GLFW.glfwCreateWindow(width, height, title, fullscreen ? monitor : MemoryUtil.NULL, MemoryUtil.NULL
    );
    GLFW.glfwMakeContextCurrent(window);
    GLFW.glfwSwapInterval(0);
    glCapabilities = GL.createCapabilities();
    initCallbacks();
    setCursorEnabled(cursorEnabled);
}
项目:Mavkit    文件:Display.java   
@UIEffect
private String getGLVersion(boolean es) {
    String fullVersion;
    String renderer;

    if (es) {
        GLES.createCapabilities();
        fullVersion = GLES20.glGetString(GLES20.GL_VERSION);
        renderer = GLES20.glGetString(GLES20.GL_RENDERER);
    } else {
        GL.createCapabilities();
        fullVersion = GL11.glGetString(GL11.GL_VERSION);
        renderer = GL11.glGetString(GL11.GL_RENDERER);
    }

    log.info("{}", fullVersion);
    log.info("{}", renderer);

    String version = fullVersion.split(" ", 2)[0];
    return version;
}
项目:gl3DGE    文件:LightingDemo.java   
public void loop(){
    GL.createCapabilities();

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glClearColor(0, 0, 0, 1);

    screen = new MainScreen(w);
    w.navigate(screen);

    while(!w.shouldClose()){
        w.loop();
    }
}
项目:Abstract-Java-Game-Library    文件:ShaderProgramTest.java   
@Before
public void setUp() throws Exception {
    window = new Window();
    window.setup();

    GLFW.glfwMakeContextCurrent(window.getWindowHandler());
    GL.createCapabilities();
    final String VERTEX_SHADER_STRING = "#version 100\n" +
            "\n" +
            "uniform mat4 projTrans;\n" +
            "\n" +
            "attribute vec2 Position;\n" +
            "attribute vec2 TexCoord;\n" +
            "\n" +
            "varying vec2 vTexCoord;\n" +
            "\n" +
            "void main() {\n" +
            "    vTexCoord = TexCoord;\n" +
            "    gl_Position = 80.0 * vec4(Position, 0.0, 1.0);\n" +
            "}";
    shader = new Shader(ShaderUtil.VERTEX_SHADER, VERTEX_SHADER_STRING);
}
项目:oreon-engine    文件:GLWindow.java   
public void create()
{
    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);    
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);  
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);  
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);  

    setId(glfwCreateWindow(getWidth(), getHeight(), "OE3", 0, 0));

    if(getId() == 0) {
        throw new RuntimeException("Failed to create window");
    }

    setIcon("textures/logo/oreon_lwjgl_icon32.png");

    glfwMakeContextCurrent(getId());
    glfwSwapInterval(0);
    glfwShowWindow(getId());
    capabilities = GL.createCapabilities();
}
项目:CubeEngine    文件:GLH.java   
/** set the opengl context to the given window */
public static void glhSetContext(GLFWContext context) {
    Logger.get().log(Level.FINE, "OpenGL context set: " + context);
    // set current context
    GLFW.glfwMakeContextCurrent(context.getWindow().getPointer());
    // create context capa
    context.createCapabilities();
    // set current capa to use
    GL.setCapabilities(context.getCapabilities());

    // singleton update
    theContext = context;

    // add the window to GLH objects so it is clean properly on program
    // termination
    GLH.glhAddObject(context.getWindow());
}
项目:joml-lwjgl3-demos    文件:CoordinateSystemDemo.java   
void loop() {
    glfwMakeContextCurrent(window);
    GL.createCapabilities();
    glClearColor(0.97f, 0.97f, 0.97f, 1.0f);
    while (!glfwWindowShouldClose(window)) {
        glfwPollEvents();
        glViewport(0, 0, fbWidth, fbHeight);
        viewport[2] = fbWidth; viewport[3] = fbHeight;
        glClear(GL_COLOR_BUFFER_BIT);
        computeVisibleExtents();
        glMatrixMode(GL_PROJECTION);
        glLoadMatrixf(cam.viewproj().get(fb));
        renderGrid();
        renderTickLabels();
        //renderMouseCursorCoordinates();
        glfwSwapBuffers(window);
    }
}
项目:joml-lwjgl3-demos    文件:PolygonDrawer.java   
void loop() {
    GL.createCapabilities();

    glClearColor(0.99f, 0.99f, 0.99f, 1.0f);
    glLineWidth(1.8f);

    while (!glfwWindowShouldClose(window)) {
        glViewport(0, 0, fbWidth, fbHeight);
        glClear(GL_COLOR_BUFFER_BIT);

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, fbWidth, fbHeight, 0, -1, 1);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        renderPolygon();

        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    // autosave current polygon
    // store("autopoly.gon");
}
项目:ldparteditor    文件:vboWithRGBA.java   
@Override
public void drawScene(float mouseX, float mouseY) {
    final GLCanvas canvas = cp.getCanvas();

    if (!canvas.isCurrent()) {
        canvas.setCurrent();
        GL.setCapabilities(cp.getCapabilities());
    }

    GL11.glColorMask(true, true, true, true);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);

    Rectangle bounds = cp.getBounds();
    GL11.glViewport(0, 0, bounds.width, bounds.height);

    shaderProgram.use();
    GL30.glBindVertexArray(VAO);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);
    GL30.glBindVertexArray(0);

    canvas.swapBuffers();
}
项目:ldparteditor    文件:vboWithIndices.java   
@Override
public void drawScene(float mouseX, float mouseY) {
    final GLCanvas canvas = cp.getCanvas();

    if (!canvas.isCurrent()) {
        canvas.setCurrent();
        GL.setCapabilities(cp.getCapabilities());
    }

    GL11.glColorMask(true, true, true, true);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);

    Rectangle bounds = cp.getBounds();
    GL11.glViewport(0, 0, bounds.width, bounds.height);

    shaderProgram.use();
    GL30.glBindVertexArray(VAO);
    // GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION); // <-- Not necessary!
    GL11.glDrawElements(GL11.GL_TRIANGLES, 6, GL11.GL_UNSIGNED_INT, 0);
    // GL20.glDisableVertexAttribArray(POSITION_SHADER_LOCATION); // <-- Not necessary!
    GL30.glBindVertexArray(0);

    canvas.swapBuffers();
}
项目:ldparteditor    文件:OpenGLRenderer.java   
/**
 * Disposes old textures
 */
public synchronized void disposeOldTextures() {
    final GLCanvas canvas = c3d.getCanvas();
    if (!canvas.isCurrent()) {
        canvas.setCurrent();
        GL.setCapabilities(c3d.getCapabilities());
    }
    Iterator<GTexture> ti = textureSet.iterator();
    for (GTexture tex = null; ti.hasNext() && (tex = ti.next()) != null;) {
        if (tex.isTooOld()) {
            NLogger.debug(getClass(), "Dispose old texture: {0}", tex); //$NON-NLS-1$
            tex.dispose(this);
            ti.remove();
        }
    }
}
项目:SquareOne    文件:Window.java   
/**
 * Create window and OpenGL context
 * @param title Window title
 * @param width Window width
 * @param height Window height
 * @param resizable Should the window be resizable
 * @param game CoreGame instance
 */
public static void init(String title, int width, int height, boolean resizable, CoreGame game) {
    if (!glfwInit()) {
        System.err.println("Could not initialize window system!");
        System.exit(1);
    }

    if (!resizable)
        glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
    if (anti_alias)
        glfwWindowHint(GLFW_SAMPLES, 4);

    window = glfwCreateWindow(width, height, title, 0, 0);
    if (window == 0) {
        glfwTerminate();
        System.err.println("Could not create window!");
        System.exit(1);
    }

    glfwMakeContextCurrent(window);
    GL.createCapabilities();

    GLFWVidMode vidMode = glfwGetVideoMode(window);
    glfwSetWindowPos(window, (vidMode.width() / 2) - (width / 2), (vidMode.height() / 2) - (height / 2));

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, width, height, 0, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    if (anti_alias) glEnable(GL_MULTISAMPLE);

    Window.game = game;
    Window.render = new Render();

    AudioPlayer.init();

    start();
}
项目:Lwjgl3-Game-Engine-Programming-Series    文件:Window.java   
public void create(int width, int height)
{
    setWidth(width);
    setHeight(height);

    glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);    
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);  
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);  
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);  

    window = glfwCreateWindow(width, height, "OREON ENGINE Programming Tutorial Series", 0, 0);

    if(window == 0) {
        throw new RuntimeException("Failed to create window");
    }

    ByteBuffer bufferedImage = ImageLoader.loadImageToByteBuffer("./res/logo/oreon_lwjgl_icon32.png");

    GLFWImage image = GLFWImage.malloc();

    image.set(32, 32, bufferedImage);

    GLFWImage.Buffer images = GLFWImage.malloc(1);
       images.put(0, image);

    glfwSetWindowIcon(window, images);

    glfwMakeContextCurrent(window);
    GL.createCapabilities();
    glfwShowWindow(window);
}
项目:TeamProject    文件:Window.java   
/**
   * Initializes the GLFW library, creating a window and any necessary shaders.
   */
  void init(GameState gameState, Main client) {
      if (!glfwInit()) {
          System.err.println("Failed to initialise GLFW");
          System.exit(1);
      }
      glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
      window = glfwCreateWindow(windowWidth, windowHeight, Constants.TITLE, 0, 0);
      if (window == 0) {
          System.err.println("Failed to create window.");
          System.exit(1);
      }

      GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
      int windowXPosition = (videoMode.width() - windowWidth) / 2;
      int windowYPosition = (videoMode.height() - windowHeight) / 2;
      glfwSetWindowPos(window, windowXPosition, windowYPosition);

      glfwShowWindow(window);
      glfwMakeContextCurrent(window);

      GL.createCapabilities();
      cshader = new ShaderProgram("shaders/cshader.vs","shaders/shader.fs");
rshader = new ShaderProgram("shaders/rshader.vs","shaders/shader.fs");
pshader1 = new ShaderProgram("shaders/pshader.vs","shaders/shader.fs");
pshader2 = new ShaderProgram("shaders/pshader2.vs","shaders/shader.fs");
pshader3 = new ShaderProgram("shaders/pshader3.vs","shaders/shader.fs");
starshader = new ShaderProgram("shaders/starshader.vs","shaders/shader.fs");

      registerInputCallbacks(gameState, client);
  }
项目:NovelJ    文件:Test.java   
private void render(){
    GL.createCapabilities();

    gl_init();

    while(!glfwWindowShouldClose(window)){
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        display();

        glfwSwapBuffers(window);
        glfwPollEvents();
    }
}
项目:CommunityEngine-Java    文件:Window.java   
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);
}
项目:zierfisch    文件:Application.java   
private void initContext() {
    glfwMakeContextCurrent(window);

       glfwSwapInterval(1);

    // This line is critical for LWJGL's interoperation with GLFW's
    // OpenGL context, or any context that is managed externally.
    // LWJGL detects the context that is current in the current thread,
    // creates the GLCapabilities instance and makes the OpenGL
    // bindings available for use.
    GL.createCapabilities();
}
项目:TorchEngine    文件:Texture.java   
/**
 * <p>
 * Set the anisotropic filtering level of the texture.
 * </p>
 *
 * @param level The anisotropic filtering level.
 */
public final void setAnisoLevel(float level)
{
    if(GL.getCapabilities().GL_EXT_texture_filter_anisotropic)
    {
        int target = getTarget();

        glBindTexture(target, getNativeId());

        level = MathUtils.clamp(level, 0, glGetFloat(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT));

        if(level > 0)
        {
            // Enable anisotropic filtering
            glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, level);
        }
        else
        {
            // Disable anisotropic filtering
            glTexParameterf(target, GL_TEXTURE_BASE_LEVEL, 0);
            glTexParameterf(target, GL_TEXTURE_MAX_LEVEL, 0);
        }

        glBindTexture(target, 0);
    }
    else
    {
        Logger.logWarning("Anisotropic filtering is not supported on this system");
    }
}
项目:SquareOne    文件:Window.java   
/**
 * Create window and OpenGL context
 * @param title Window title
 * @param width Window width
 * @param height Window height
 * @param resizable Should the window be resizable
 * @param game CoreGame instance
 */
public static void init(String title, int width, int height, boolean resizable, CoreGame game) {
    if (!glfwInit()) {
        System.err.println("Could not initialize window system!");
        System.exit(1);
    }

    if (!resizable)
        glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
    if (anti_alias)
        glfwWindowHint(GLFW_SAMPLES, 4);

    window = glfwCreateWindow(width, height, title, 0, 0);
    if (window == 0) {
        glfwTerminate();
        System.err.println("Could not create window!");
        System.exit(1);
    }

    glfwMakeContextCurrent(window);
    GL.createCapabilities();

    GLFWVidMode vidMode = glfwGetVideoMode(window);
    glfwSetWindowPos(window, (vidMode.width() / 2) - (width / 2), (vidMode.height() / 2) - (height / 2));

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, width, height, 0, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    if (anti_alias) glEnable(GL_MULTISAMPLE);

    Window.game = game;
    Window.render = new Render();

    AudioPlayer.init();

    start();
}
项目:graphicslab    文件:Window.java   
public void startLoop() {
    keycallback = (window, key, scancode, action, mods)  -> {};

    glfwSetKeyCallback(windowHandle, keycallback);

    glfwMakeContextCurrent(windowHandle);
    GL.createCapabilities();

    // Set the clear color
    glClearColor(1.0f, 0.0f, 0.0f, 0.0f);

    double msecsPerFrame = 1000 / 50.0;
    double msecsPerUpdate = 1000 / 30.0;
    double previous = glfwGetTime();
    double steps = 0.0;

    while (!glfwWindowShouldClose(windowHandle)) {
        double loopStart = glfwGetTime();
        double elapsed = loopStart - previous;
        previous = loopStart;
        steps += elapsed;

        input();
        gameState();
        render();

        while (steps >= msecsPerUpdate) {
            gameState();
            steps -= msecsPerUpdate;
        }
        sync(loopStart);


    }

    destroyWindow();
}
项目:lwjgl-utils    文件:Display.java   
/**
 * Destroys the display and GL capabilities.
 */
public void destroy()
{
    glfwDestroyWindow(window);
    glfwTerminate();
    GL.destroy();
}
项目:ether    文件:GLFWWindow.java   
@Override
public IContext acquireContext() {
    contextLock.lock();
    GLFW.glfwMakeContextCurrent(window);
    try {
        GL.getCapabilities();
    } catch (Exception e) {
        GL.createCapabilities(true);            
    }
    // we're not using VAOs but still need to create one
    if (vao == -1)
        vao = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vao);
    return context;
}
项目:playn    文件:SWTGraphics.java   
public SWTGraphics (SWTPlatform splat, final Composite comp) {
  super(splat);
  this.plat = splat;

  boolean isMac = "Mac OS X".equals(System.getProperty("os.name"));
  final Hack hack = isMac ? new SWTMacHack() : new Hack();

  // special scale fiddling on Mac
  scaleChanged(hack.hackScale());

  // create our GLCanvas
  GLData data = new GLData();
  data.doubleBuffer = true;
  canvas = new GLCanvas(comp, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE, data);
  hack.hackCanvas(canvas);
  canvas.setCurrent();
  GL.createCapabilities();

  comp.addListener(SWT.Resize, new Listener() {
    public void handleEvent(Event event) {
      // resize our GLCanvas to fill the window; we do manual layout so that other SWT widgets
      // can be overlaid on top of our GLCanvas
      Rectangle bounds = comp.getBounds();
      comp.setBounds(bounds);
      canvas.setBounds(bounds);
      canvas.setCurrent();
      hack.convertToBacking(canvas, bounds);
      viewportChanged(bounds.width, bounds.height);
    }
  });

  plat.log().info("Setting size " + plat.config.width + "x" + plat.config.height);
  setSize(plat.config.width, plat.config.height, plat.config.fullscreen);
}
项目:Abstract-Java-Game-Library    文件:ShaderTest.java   
@Before
public void setUp() throws Exception {
    window = new Window();
    window.setup();
    GLFW.glfwMakeContextCurrent(window.getWindowHandler());
    GL.createCapabilities();
}
项目:oreon-engine    文件:Texture2D.java   
public void anisotropicFilter(){

    if (GL.getCapabilities().GL_EXT_texture_filter_anisotropic){
        float maxfilterLevel = glGetFloat(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxfilterLevel);
    }
    else{
        System.out.println("anisotropic not supported");
    }
}
项目:oreon-engine    文件:Texture2DArray.java   
public void anisotropicFilter()
{
    if (GL.getCapabilities().GL_EXT_texture_filter_anisotropic){
        float maxfilterLevel = glGetFloat(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT);
        glTexParameterf(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxfilterLevel);
    }
    else{
        System.out.println("anisotropic not supported");
    }
}
项目:joml-lwjgl3-demos    文件:PolygonDrawer2.java   
void loop() {
    GL.createCapabilities();

    glClearColor(0.99f, 0.99f, 0.99f, 1.0f);
    glLineWidth(1.8f);

    long lastTime = System.nanoTime();

    while (!glfwWindowShouldClose(window)) {
        long thisTime = System.nanoTime();
        float dt = (thisTime - lastTime) / 1E9f;
        lastTime = thisTime;

        glViewport(0, 0, fbWidth, fbHeight);
        glClear(GL_COLOR_BUFFER_BIT);

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, width, height, 0, -1, 1);
        glMatrixMode(GL_MODELVIEW);
        transformation
            .identity()
            .translate(width/2, height/2, 0)
            .rotateZ(angle += dt * 0.2f)
            .translate(-width/2, -height/2, 0)
            .invert(transformationInv);
        glLoadMatrixf(transformation.get(matBuffer));

        intersect();
        renderPolygon();

        glfwSwapBuffers(window);
        glfwPollEvents();
    }
}
项目:ldparteditor    文件:OpenGLRenderer.java   
/**
 * Disposes all textures
 */
public void disposeAllTextures() {
    final GLCanvas canvas = c3d.getCanvas();
    if (!canvas.isCurrent()) {
        canvas.setCurrent();
        GL.setCapabilities(c3d.getCapabilities());
    }
    for (Iterator<GTexture> it = textureSet.iterator() ; it.hasNext();) {
        GTexture tex = it.next();
        NLogger.debug(getClass(), "Dispose texture: {0}", tex); //$NON-NLS-1$
        tex.dispose(this);
        it.remove();
    }
}
项目:SilenceEngine    文件:Window.java   
/**
 * <p> This method makes the OpenGL context of this window current on the calling thread. A context can only be made
 * current on a single thread at a time and each thread can have only a single current context at a time.</p>
 *
 * <p> By default, making a context non-current implicitly forces a pipeline flush. On machines that support
 * {@code GL_KHR_context_flush_control}, you can control whether a context performs this flush by setting the
 * {@code GLFW_CONTEXT_RELEASE_BEHAVIOR} window hint.</p>
 */
public void makeCurrent()
{
    glfwMakeContextCurrent(handle);

    if (windowCapabilities == null)
        windowCapabilities = GL.createCapabilities();
    else
        GL.setCapabilities(windowCapabilities);
}
项目:Cubeland    文件:Game.java   
private void init() {
    // glfw error callback
    GLFW.glfwSetErrorCallback(errorCallback);

    // initialize GLFW
    if (!GLFW.glfwInit()) {
        GLFW.glfwTerminate();
        throw new IllegalStateException("Unable to initialize GLFW!");
    }

    // create windowglfwDefaultWindowHints();
    GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 3);
    GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 2);
    GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
    GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GLFW.GLFW_TRUE);
    window = GLFW.glfwCreateWindow(800, 600, "Cubeland", 0, 0);
    GLFW.glfwMakeContextCurrent(window);
    GL.createCapabilities();

    // glfw callbacks
    GLFW.glfwSetWindowCloseCallback(window, windowCloseCallback);
    GLFW.glfwSetKeyCallback(window, keyCallback = GLFWKeyCallback.create((w, key, scancode, action, mods) -> {
        if (w == window)
            createEvent(new KeyInputEvent(key, scancode, action, mods));
    }));

    // load configuration
    config.loadBasicConfig();

    // initialize renderer
    renderer.init();

    // add systems
    systems.add(new SavingSystem());
    systems.add(new InputSystem());
    systems.add(new WorldGeneratorSystem());

    for (System s : systems)
        s.init(this, scene, config);

    // ready
    running = true;
    createEvent(new Event(Event.Type.INIT_EVENT));
}
项目:Mass    文件:Screen.java   
/**
 * Initializes the Screen by settings its callbacks and applying options specified in the
 * ScreenOptions object for this Screen.
 */
public void init() {
    // Set resizeable to false.
    glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);

    if (this.screenOptions.getCompatibleProfile()) {
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
    } else {
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    }

    // Create the window
    id = glfwCreateWindow(width, height, title, NULL, NULL);
    if (id == NULL) {
        glfwTerminate();
        throw new RuntimeException("Failed to create GLFW window");
    }

    // Center window on the screen
    GLFWVidMode vidMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    glfwSetWindowPos(id, (vidMode.width() - width)/2, (vidMode.height() - height)/2);


    // Create OpenGL context
    glfwMakeContextCurrent(id);

    // Enable v-sync
    if (this.getVsync()) {
        glfwSwapInterval(1);
    }

    // Make the window visible
    glfwShowWindow(id);

    GL.createCapabilities();

    // Set key callback
    GLFWKeyCallback keyCallback = new GLFWKeyCallback() {
        @Override
        public void invoke(long window, int key, int scancode, int action, int mods) {
            if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
                glfwSetWindowShouldClose(window, true);
            }
        }
    };
    glfwSetKeyCallback(id, keyCallback);

    // Setting the clear color.
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_STENCIL_TEST);

    if (screenOptions.getShowTriangles()) {
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    }

    // Enable OpenGL blending that gives support for transparencies.
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    if (screenOptions.getCullFace()) {
        glEnable(GL_CULL_FACE);
        glCullFace(GL_BACK);
    }

    // Antialiasing
    if (screenOptions.getAntialiasing()) {
        glfwWindowHint(GLFW_SAMPLES, 4);
    }
}
项目:debug    文件:DebugIT.java   
@Test
public void testNullInNullableParameter() {
    GL.setCapabilities(null);
}
项目:candlelight    文件:Window.java   
protected void createWindow()
{
    // the window will stay hidden after creation
    GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GLFW.GLFW_FALSE);

    // Configure GLFW
    GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 3);
    GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 2);
    GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GLFW.GLFW_TRUE);
    GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE,
            GLFW.GLFW_OPENGL_CORE_PROFILE);

    // Create the window
    this.handle = GLFW.glfwCreateWindow(this.width, this.height, this.title,
            MemoryUtil.NULL, MemoryUtil.NULL);
    if (this.handle == MemoryUtil.NULL)
    {
        throw new RuntimeException("Failed to create the GLFW window");
    }

    //Create the input context
    //this.inputEngine = new InputEngine(this);

    //Setup a size callback.
    GLFW.glfwSetWindowSizeCallback(this.handle, (window, w, h) ->
    {
        int prevW = this.width;
        int prevH = this.height;
        this.width = w;
        this.height = h;
        this.onWindowSizeChanged.notifyListeners(new int[]{
                this.width, this.height, prevW, prevH
        });
    });

    //Setup a position callback
    GLFW.glfwSetWindowPosCallback(this.handle, (window, xpos, ypos) -> {
        int prevX = this.x;
        int prevY = this.y;
        this.x = xpos;
        this.y = ypos;
        this.onWindowPosChanged.notifyListeners(new int[]{
                this.x, this.y, prevX, prevY
        });
    });

    this.makeWindowCentered();

    // Make the OpenGL context current
    GLFW.glfwMakeContextCurrent(this.handle);

    // Enable v-sync
    GLFW.glfwSwapInterval(this.vsync ? 1 : 0);

    // This line is critical for LWJGL's interoperation with GLFW's
    // OpenGL context, or any context that is managed externally.
    // LWJGL detects the context that is current in the current thread,
    // creates the GLCapabilities instance and makes the OpenGL
    // bindings available for use.
    GL.createCapabilities();

    System.out.println("OPENGL " + GL11.glGetString(GL11.GL_VERSION));

    // Set the clear color
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    //Enable depth testing
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    //Set current viewport
    this.view = new View(this);
}
项目:Global-Gam-Jam-2017    文件:Main.java   
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();
            }
        }

    }