Example usage for org.lwjgl.opengl GL11 GL_TRUE

List of usage examples for org.lwjgl.opengl GL11 GL_TRUE

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL11 GL_TRUE.

Prototype

int GL_TRUE

To view the source code for org.lwjgl.opengl GL11 GL_TRUE.

Click Source Link

Document

Boolean

Usage

From source file:com.google.gapid.glviewer.gl.Shader.java

License:Apache License

private static int createShader(int type, String source) {
    int shader = GL20.glCreateShader(type);
    GL20.glShaderSource(shader, source);
    GL20.glCompileShader(shader);/*w w w  .jav  a  2  s. c  om*/
    if (GL20.glGetShaderi(shader, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) {
        LOG.log(WARNING,
                "Failed to compile shader:\n" + GL20.glGetShaderInfoLog(shader) + "\n\nSource:\n" + source);
        GL20.glDeleteShader(shader);
        return -1;
    }
    return shader;
}

From source file:com.polygame.engine.core.events.WindowEventHandler.java

License:Open Source License

@Override
public void windowFocus(long window, int focused) {
    if (focused == GL11.GL_TRUE)
        triggerEvent("windowFocused");
    else// ww w. ja v  a 2  s  .com
        triggerEvent("windowDefocused");
}

From source file:com.polygame.engine.core.events.WindowEventHandler.java

License:Open Source License

@Override
public void windowIconify(long window, int iconified) {
    if (iconified == GL11.GL_TRUE)
        triggerEvent("windowIconified");
    else/*from w  w w .  j  a v a  2s .c  om*/
        triggerEvent("windowDeiconofied");
}

From source file:com.polygame.engine.core.events.WindowEventHandler.java

License:Open Source License

@Override
public void cursorEnter(long window, int entered) {
    if (entered == GL11.GL_TRUE)
        triggerEvent("cursorEntered");
    else//from ww  w . j av a  2s  .c  o m
        triggerEvent("cursorLeft");
}

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.
 * //from ww w . j  ava2 s .  com
 * @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.samrj.devil.gl.Shader.java

/**
 * Loads shader sources from the given input stream and then compiles this
 * shader. Buffers the source in native memory.
 * //  w w  w  .j  a v a2 s. c o  m
 * @param in The input stream to load sources from.
 * @return This shader.
 * @throws IOException If an I/O error occurs.
 */
public Shader source(InputStream in) throws IOException {
    if (state != State.NEW)
        throw new IllegalStateException("Shader must be new.");

    //Source to memory
    int sourceLength = in.available();
    Memory sourceBlock = new Memory(sourceLength);
    ByteBuffer sourceBuffer = sourceBlock.buffer;
    for (int i = 0; i < sourceLength; i++)
        sourceBuffer.put((byte) in.read());

    //Pointer to pointer to memory
    long pointer = MemStack.wrapl(sourceBlock.address);

    //Pointer to length of memory
    long length = MemStack.wrapi(sourceLength);

    //Load shader source
    GL20.nglShaderSource(id, 1, pointer, length);

    //Free allocated memory
    MemStack.pop(2);
    sourceBlock.free();

    //Compile
    GL20.glCompileShader(id);

    //Check for errors
    if (GL20.glGetShaderi(id, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) {
        int logLength = GL20.glGetShaderi(id, GL20.GL_INFO_LOG_LENGTH);
        String log = GL20.glGetShaderInfoLog(id, logLength);
        throw new ShaderException(path != null ? path + " " + log : log);
    }

    state = State.COMPILED;
    return this;
}

From source file:com.samrj.devil.gl.ShaderProgram.java

License:Open Source License

private void checkStatus(int type) {
    if (GL20.glGetProgrami(id, type) != GL11.GL_TRUE) {
        int logLength = GL20.glGetProgrami(id, GL20.GL_INFO_LOG_LENGTH);
        String log = GL20.glGetProgramInfoLog(id, logLength);
        throw new ShaderException(log);
    }/*from   w  w  w .j a  v a2s  .c  o  m*/
}

From source file:com.swinggl.elements.GLFrame.java

License:Open Source License

/**
 * Constructor that builds a default fullscrene GLFrame that links graphics data with another GLFrame
 *
 * @param fullscreen         - Sets whether or not the frame is fullscreen
 * @param secondWindowHandle - The other window handle that this GLFrame will be linked to.
 *//*from  w ww  . j  ava 2  s . co m*/
public GLFrame(boolean fullscreen, long secondWindowHandle) {
    Debug.enabled = false;
    Thread.currentThread().setName("SwingGL | render");
    this.fullscreen = fullscreen;
    this.secondWindowHandle = secondWindowHandle;
    glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err));
    if (glfwInit() != GL11.GL_TRUE)
        throw new IllegalStateException("Unable to initialize GLFW");
    // Configure our window
    glfwDefaultWindowHints();
    glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
    glfwWindowHint(GLFW_DECORATED, GL_TRUE);

    // Configure callbacks
    keyCallback = new Keyboard();
    cursorPosCallback = new Mouse.CursorPos();
    mouseButtonCallback = new Mouse.MouseButton();
    scrollCallback = new Mouse.Scroll();
}

From source file:com.timvisee.voxeltex.engine.render.VoxelTexRenderer.java

License:Open Source License

/**
 * Initialize the renderer./*from   w  w w . ja  va2  s  . co  m*/
 */
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!");
}

From source file:com.timvisee.voxeltex.engine.window.VoxelTexWindow.java

License:Open Source License

/**
 * Set whether the window should close./*w  w  w  .jav  a2s .  com*/
 *
 * @param close True to close the window.
 */
public void glSetWindowShouldClose(boolean close) {
    glfwSetWindowShouldClose(this.window, close ? GL11.GL_TRUE : GL11.GL_TRUE);
}