Ok. So I tried it out and having some issues ;/ got it basically to compile but 2 problems:

1. I have to get dub to include the lib, not a big deal, shouldn't be issue if I can get the right lib in. (not sure if I have to do all that conversion just or not, and glfw has several libs for different VS versions and such... not sure what that's all about).

2. I had to commend out the following code dealing with the keyboard callback:

        // Set the required callback functions
        //glfwSetKeyCallback(window, &key_callback);

gives the error

function app.key_callback (GLFWwindow* window, int key, int scancode, int action, int mode) is not callable using argument types ()

I tried with and without address passing. I can cast though

glfwSetKeyCallback(window, cast(GLFWkeyfun)&key_callback);

works(no errors, at least), and if that's correct, leaves only the lib issue.



alternate thing I tried but gladLoadGL undefined
//(gladLoadGL()); // optionally you can pass a loader to this function //writefln("OpenGL Version %d.%d loaded", GLVersion.major, GLVersion.minor);





import std.stdio;

import glad.gl.all;
import deimos.glfw.glfw3;



// Window dimensions
const GLuint WIDTH = 800, HEIGHT = 600;

void main()
{

        glfwInit();
        // Set all the required options for GLFW
        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
        glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

// Create a GLFWwindow object that we can use for GLFW's functions GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "LearnOpenGL", null, null);
        glfwMakeContextCurrent(window);
        if (window == null)
        {
                writeln("Failed to create GLFW window");
                glfwTerminate();
                return;
        }
        
        // Set the required callback functions
        //glfwSetKeyCallback(window, &key_callback);

//(gladLoadGL()); // optionally you can pass a loader to this function //writefln("OpenGL Version %d.%d loaded", GLVersion.major, GLVersion.minor);

        /*
        if (!gladLoadGLLoader(cast(GLADloadproc) glfwGetProcAddress))
        {
                writeln("Failed to initialize OpenGL context");
                return;
        }*/
        
        // Define the viewport dimensions
        glViewport(0, 0, WIDTH, HEIGHT);
        
        // Game loop
        while (!glfwWindowShouldClose(window))
        {
// Check if any events have been activated (key pressed, mouse moved etc.) and call corresponding response functions
                glfwPollEvents();
                
                // Render
                // Clear the colorbuffer
                glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
                glClear(GL_COLOR_BUFFER_BIT);
                
                // Swap the screen buffers
                glfwSwapBuffers(window);
        }
        
        // Terminates GLFW, clearing any resources allocated by GLFW.
        glfwTerminate();
        return;
}


// Is called whenever a key is pressed/released via GLFW
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
{
        writeln(key);
        if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
                glfwSetWindowShouldClose(window, GL_TRUE);
}

Reply via email to