contrapunctus
contrapunctus

Reputation: 41

OpenGL glfwInit() automatic executing?

So I'm watching this tutorial series on LWJGL3 and when OpenGL is supposed to be initialized in the init function then it doesn't execute the function itself.

So here it checks if glfwInit() executes and if it doesn't it prints an out error code. But how does the glfwInit() actually executes?

I don't call it anywhere, so how ?

public void init() {

    if(glfwInit() != GL_TRUE){
        System.err.println("Failed to initilaize OpenGL");
    }

} 

Full code below

import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.*;
import java.nio.ByteBuffer;
import org.lwjgl.glfw.GLFWvidmode;

public class Driver implements Runnable {

    private Thread thread = new Thread();
    private boolean running = false;

    public Driver() {

    }

    private synchronized void start() {
        thread.start();
        running = true;
    }

    private synchronized void stop() {
        try {
            thread.join();
            running = false;
        } catch(InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void run() {
        init();
        while (running) {

            System.out.println("The game is running...");

            render();
            update();
        }
    }

    public void update() {

    }

    public void render() {

    }

    public void init() {

        if (glfwInit() != GL_TRUE) {
            System.err.println("Failed to initilaize OpenGL");
        }
    }

    public static void main(String[] args) {
        Driver game = new Driver();
        game.start();
        game.run();
    }

}

Upvotes: 1

Views: 404

Answers (1)

yiding
yiding

Reputation: 3592

glfwInit() this calls the function.

glfwInit() != GL_TRUE this checks the function returned true, not whether it executed or not, it is executed.

Upvotes: 2

Related Questions