Need extern (C) interface even though using Derelict GLFW

Rikki Cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 3 20:44:23 PST 2015


On 4/01/2015 5:34 p.m., WhatMeWorry wrote:
>
> I've been translating C++, OpenGL, and GLUT code into D, Derelict
> OpenGL, and Derelict GLFW using:
>
> import derelict.opengl3.gl3;
> import derelict.glfw3.glfw3;
>
> auto window = glfwCreateWindow(800, 600, "Shaders", null, null);
>
> etc.
>
>
> Things have been going well. I then tried to implement window resizing
> with a callback function and the glfwSetWindowSizeCallback() statement.
>
>
> void windowResizeCallback(GLFWwindow* window, int width, int height)
> {
>      glViewport(0, 0, width, height);
> }
>
> and
>
> glfwSetWindowSizeCallback(window, &windowResizeCallback);
>
>
> however, I kept getting the following compiler error:
> Error    1    Error: function pointer glfwSetWindowSizeCallback
> (GLFWwindow*, extern (C) void function(GLFWwindow*, int, int) nothrow)
> is not callable using argument types (GLFWwindow*, void
> function(GLFWwindow* window, int width, int height))
>
> Well, I was able to get it to compile and work by adding the following
> "decoration"
>
> extern (C) nothrow
> {
>      void windowResizeCallback(GLFWwindow* window, int width, int height)
>      {
>          glViewport(0, 0, width, height);
>      }
> }
>
>
> Now it resizes the screen successfully, but I feel like I've failed by
> using extern (C) nothrow. Shouldn't Derelict GLFW be providing a D
> interface?
>
> Maybe GLFW callback functions can't handled through Derelict GLFW?

No this is correct code.
Derelict projects are just bindings. Which means the c equivalent in D. 
Nothing more nothing less.



More information about the Digitalmars-d-learn mailing list