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.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowController.java

License:Apache License

/** Sharecontext is for texture sharing with multiple windows (1 Texture for all windows for example). <br>
 * <br>/* ww  w  . j a va2 s  . co m*/
 * 
 * If parent context is destroyed you will need to reload the texture because it will be black. <br>
 * You can change the parent context with {@link Lwjgl3WindowController#changeParentWindow(long)} */
public Lwjgl3WindowController(boolean shareContext) {
    Lwjgl3NativesLoader.load();

    if (glfwInit() != GL11.GL_TRUE)
        throw new IllegalStateException("Unable to initialize GLFW");

    glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err));
    windows = new Array<Lwjgl3Application>();
    queueWindows = new Array<Lwjgl3Application>();

    this.shareContext = shareContext;

    runnable = new Runnable() {

        @Override
        public void run() {

            while (running) {

                executeWindowRunnablesAndWait();
                executeWindowRunnables();
                if (jumpLoop)
                    continue;
                for (int i = 0; i < windows.size; i++) {
                    final Lwjgl3Application app = windows.get(i);

                    if (app.running) {

                        if (app.init)
                            app.loop(true);
                    } else {
                        app.setGlobals();
                        app.disposeListener();
                        windows.removeIndex(i);
                        i--;

                        Runnable run = new Runnable() {

                            @Override
                            public void run() {
                                app.dispose();
                            }
                        };
                        postMainRunnable(run);

                        glfwPostEmptyEvent();
                    }
                }

                if (targetFPS != 0) {
                    if (targetFPS == -1)
                        Lwjgl3Application.sleep(100);
                    else
                        Sync.sync(targetFPS);
                }

            }
        }
    };

    windowThread = new Thread(runnable, "Lwjgl3WindowController");
}

From source file:com.dinasgames.engine.LWJGL.java

public static void init() {

    glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err));

    // Initialize GLFW. Most GLFW functions will not work before doing this.
    if (glfwInit() != GL11.GL_TRUE) {
        throw new IllegalStateException("Unable to initialize GLFW");
    }// w w  w .  jav  a 2 s.  co m

}

From source file:com.dinasgames.engine.window.Window.java

public Window() throws RuntimeException {

    // Setup some hints
    glfwDefaultWindowHints();/*from   ww  w  .  j a  v a2  s  . com*/
    glfwWindowHint(GLFW_VISIBLE, GL11.GL_FALSE); // <<< Window won't be visible when created
    glfwWindowHint(GLFW_RESIZABLE, GL11.GL_FALSE); // <<< Window won't be resizable when created
    glfwWindowHint(GLFW_FOCUSED, GL11.GL_TRUE); // <<< The window will have focus when created.

    // Attempt to create the window
    mHandle = glfwCreateWindow(640, 480, "Hello World!", NULL, NULL);
    if (mHandle == NULL) {
        throw new RuntimeException("Failed to create the GLFW window");
    }

    // Get the resolution of the primary monitor
    ByteBuffer videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());

    // Center our window
    glfwSetWindowPos(mHandle, (GLFWvidmode.width(videoMode) - 640) / 2,
            (GLFWvidmode.height(videoMode) - 480) / 2);

    // Make the OpenGL context current
    glfwMakeContextCurrent(mHandle);

    // Enable v-sync
    glfwSwapInterval(0);

    // Make the window visible
    glfwShowWindow(mHandle);

    GL.setContext(GLContext.createFromCurrent());

    //        GL11.glMatrixMode(GL11.GL_PROJECTION);
    //        GL11.glViewport(0, 0, 640, 480);
    //        GL11.glMatrixMode(GL11.GL_MODELVIEW);

    initialize();

    // TODO:

    // Window damage
    // glfwSetWindowRefreshCallback(m_handle, window_refresh_callback);
    //        void window_refresh_callback(GLFWwindow* window)
    //        {
    //            draw_editor_ui(window);
    //            glfwSwapBuffers(window);
    //        }

    // Fullscreen
    //        GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", glfwGetPrimaryMonitor(), NULL);

    // Window maximised
    //const GLFWvidmode* mode = glfwGetVideoMode(monitor);
    //glfwWindowHint(GLFW_RED_BITS, mode->redBits);
    //glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
    //glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
    //glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
    //GLFWwindow* window = glfwCreateWindow(mode->width, mode->height, "My Title", monitor, NULL);

    // Window close event
    // glfwSetWindowCloseCallback(window, window_close_callback);
    //void window_close_callback(GLFWwindow* window)
    //{
    //    if (!time_to_close)
    //        glfwSetWindowShouldClose(window, GL_FALSE);
    //}

    //GL11.glMatrixMode(GL11.GL_PROJECTION);
    //GL11.glLoadIdentity();

    //GL11.glMatrixMode(GL11.GL_MODELVIEW);

}

From source file:com.dinasgames.engine.window.Window.java

/**
 * Returns whether the window should be closed. i.e. the window has been asked to close by the operating system.
 * @return //from   w w w  . ja v a2s .c o m
 */
public boolean shouldClose() {
    return (glfwWindowShouldClose(mHandle) == GL11.GL_TRUE);
}

From source file:com.drazisil.opengl3demo.OpenGL3Demo.java

License:Apache License

private void initOpenGl() {
    System.out.println("Hello LWJGL " + Sys.getVersion() + "!");

    // create and set the glfw error callback
    setupErrorCallback();//from   www  .  jav a  2 s  . c o m

    // Initialize GLFW. Most GLFW functions will not work before doing this.
    if (glfwInit() != GL11.GL_TRUE)
        throw new IllegalStateException("Unable to initialize GLFW");

    // create the window
    window = glfwCreateWindow(WIDTH, HEIGHT, title, 0, 0);

    // Check if window was created
    if (window == 0) {
        glfwTerminate();
        exit(-1);
    }

    // Get the resolution of the primary monitor
    ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());

    // Center our window
    glfwSetWindowPos(window, (GLFWvidmode.width(vidmode) - WIDTH) / 2,
            (GLFWvidmode.height(vidmode) - HEIGHT) / 2);

    // Created and set the glfw key callback
    setupKeyCallback();

    // make context current
    glfwMakeContextCurrent(window);

    // It is required to have an active OpenGL context
    GLContext.createFromCurrent();

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

    vertexArrays = glGenVertexArrays();
    glBindVertexArray(vertexArrays);

    colorBufferObject = glGenBuffers();
}

From source file:com.github.reisnera.gameboylfb.App.java

License:GNU General Public License

public App() {
    // Set up error callback
    glfwSetErrorCallback(errorCallback = errorCallbackPrint(System.err));

    if (glfwInit() != GL11.GL_TRUE) {
        throw new IllegalStateException("Unable to initialize GLFW");
    }//from w  w  w . j  a v  a  2 s. c  om
    glfwDefaultWindowHints();
    glfwWindowHint(GLFW_VISIBLE, GL11.GL_FALSE); // the window will stay hidden after creation
    glfwWindowHint(GLFW_RESIZABLE, GL11.GL_FALSE);

    window = glfwCreateWindow(WIDTH, HEIGHT, "gameboylfb", MemoryUtil.NULL, MemoryUtil.NULL);
    if (window == MemoryUtil.NULL) {
        throw new RuntimeException("Failed to create the GLFW window");
    }

    // Setup a key callback. It will be called every time a key is pressed, repeated or released.
    // It needs a window handle before it can be set
    glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() {
        @Override
        public void invoke(long window, int key, int scancode, int action, int mods) {
            if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE)
                glfwSetWindowShouldClose(window, GL11.GL_TRUE); // We will detect this in our rendering loop
        }
    });

    // Get the resolution of the primary monitor
    ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
    // Center our window
    glfwSetWindowPos(window, (GLFWvidmode.width(vidmode) - WIDTH) / 2,
            (GLFWvidmode.height(vidmode) - HEIGHT) / 2);

    // Make the OpenGL context current
    glfwMakeContextCurrent(window);
    // Enable v-sync
    glfwSwapInterval(1);

    // Make the window visible
    glfwShowWindow(window);
    //GL.createCapabilities(true); // Load LWJGL's current context without deprecated functions
    GLContext.createFromCurrent(); // use this line instead with the 3.0.0a build

    // Clear buffer to Game Boy off-state display color
    GL11.glClearColor(0.605f, 0.734f, 0.059f, 1.0f);
}

From source file:com.github.reisnera.gameboylfb.App.java

License:GNU General Public License

/**
 * @return Returns 0 if everything ran fine, otherwise returns 1 if the program should exit
 *///from  w w  w  .  j a  va  2s . c  om
public int tick() {
    if (glfwWindowShouldClose(window) == GL11.GL_TRUE) {
        glfwTerminate();
        errorCallback.release();
        // TODO: Notify someone that this should close in another way?
        return 1;
    } else {
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); // clear the framebuffer
        glfwSwapBuffers(window); // swap the color buffers

        // Poll for window events. The key callback above will only be
        // invoked during this call.
        glfwPollEvents();
        return 0;
    }
}

From source file:com.github.ryancwilliams.WJ3dPL.graphics.GLUtils.ShaderProgram.java

License:Apache License

/**
 * Creates a new shader program with the provided vertex and fragment 
 * shader source code.//  w  ww.  ja  va 2  s  .c om
 * The provided attributes are linked to this program.
 * @param vertexShaderSource the source code of the vertex shader.
 * @param fragmentShaderSource the source code of the fragment shader.
 * @param attributes The Vertex Attributes to bind to this shader program.
 * @throws LWJGLException If their is a issue compiling the shaders or 
 * creating or binding the program.  
 */
public ShaderProgram(String vertexShaderSource, String fragmentShaderSource, List<VertexAttribute> attributes)
        throws LWJGLException {
    //Check if any of the sourcecode paramaters are null
    if (fragmentShaderSource == null || fragmentShaderSource == null) {
        //If any of the sourcecode paramaters were null
        //throw a exception
        throw new IllegalArgumentException("Shader source may not be null");
    }
    //Check if shaders are not supported
    if (!ShaderProgram.isSupported()) {
        //If shaders are not supported
        //throw a exception
        throw new LWJGLException("Shaders are not supported on this device");
    }

    //Compile the shaders
    int vertexShader = ShaderProgram.compileShader(GL20.GL_VERTEX_SHADER, vertexShaderSource);
    int fragmentShader = ShaderProgram.compileShader(GL20.GL_FRAGMENT_SHADER, fragmentShaderSource);

    //Create the program
    this.program = GL20.glCreateProgram();

    //Bind the attrib locations
    //Check if attributes were provided
    if (attributes != null) {
        //For each attribute
        for (VertexAttribute attribute : attributes) {
            //Check if the attribute is not null
            if (attribute != null) {
                //bind the attribute
                GL20.glBindAttribLocation(this.program, attribute.index, attribute.name);
            }
        }
    }

    //Attach the shaders
    GL20.glAttachShader(this.program, vertexShader);
    GL20.glAttachShader(this.program, fragmentShader);

    //Link the program
    GL20.glLinkProgram(this.program);

    //Get if the program link was good
    boolean programLink = GL20.glGetProgrami(this.program, GL20.GL_LINK_STATUS) == GL11.GL_TRUE;

    //Get the log
    String infoLog = GL20.glGetProgramInfoLog(this.program,
            GL20.glGetProgrami(this.program, GL20.GL_INFO_LOG_LENGTH));

    //Log the log if a log is present
    if (infoLog != null && infoLog.trim().length() != 0) {
        Logger.getLogger(ShaderProgram.class.getName()).log(Level.FINEST, infoLog);
    }

    //Check if program link is bad
    if (programLink == false) {
        throw new LWJGLException("Failure in linking program. Error log:\n" + infoLog);
    }

    //detach and delete the shaders which are no longer needed
    GL20.glDetachShader(this.program, vertexShader);
    GL20.glDetachShader(this.program, fragmentShader);
    GL20.glDeleteShader(vertexShader);
    GL20.glDeleteShader(fragmentShader);
}

From source file:com.github.ryancwilliams.WJ3dPL.graphics.GLUtils.ShaderProgram.java

License:Apache License

/**
 * Compiles a shader from the provided source and returns its OpenGL handle.
 * @param type the shader type to use when compiling.
 * @param source the source to compile./*from  ww w .j  a  va 2  s .c  om*/
 * @return the OpenGL handle for this shader.
 * @throws LWJGLException if compilation was unsuccessful
 */
public static int compileShader(int type, String source) throws LWJGLException {
    //Create the shader ponter varable
    int shader;
    //Create the shader
    shader = GL20.glCreateShader(type);

    //load the source
    GL20.glShaderSource(shader, source);
    //compile the source
    GL20.glCompileShader(shader);

    //Get if the compile was good
    boolean compile = GL20.glGetShaderi(shader, GL20.GL_COMPILE_STATUS) == GL11.GL_TRUE;

    //Get the log
    String infoLog = GL20.glGetShaderInfoLog(shader, GL20.glGetShaderi(shader, GL20.GL_INFO_LOG_LENGTH));

    //Log the log if a log is present
    if (infoLog != null && infoLog.trim().length() != 0) {
        Logger.getLogger(ShaderProgram.class.getName()).log(Level.FINEST, infoLog);
    }

    //Check if the compiling was unsuccessful
    if (compile == false) {
        //throw a exception if unsuccessful
        throw new LWJGLException(
                "Failure in compiling " + ShaderProgram.typeToString(type) + ". Error log:\n" + infoLog);
    }

    //Return the OpenGL pointer for the shader
    return shader;
}

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

License:Apache License

private boolean link() {
    GL20.glLinkProgram(handle);//from  w w  w .j a  va  2 s  .  c o m
    if (GL20.glGetProgrami(handle, GL20.GL_LINK_STATUS) != GL11.GL_TRUE) {
        LOG.log(WARNING, "Failed to link program:\n" + GL20.glGetProgramInfoLog(handle));
        return false;
    }
    return true;
}