FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DerelictGLFW3

 
Post new topic   Reply to topic     Forum Index -> Derelict
View previous topic :: View next topic  
Author Message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Mon Jan 30, 2012 8:15 am    Post subject: DerelictGLFW3 Reply with quote

In order to create OpenGL 3.x+ contexts, it's useful to have a binding in Derelict to a library that can do so. To that end, I've implemented a binding to GLFW3, but not for Derelict 2. This will be a compliment to the DerelictGL3 that I announced earlier.

Sample code:
Code:

import std.stdio : writeln, writefln;
import derelict.opengl3.gl3;
import derelict.glfw3.glfw3;

pragma(lib, "lib\\DerelictUtil.lib");
pragma(lib, "lib\\DerelictGL3.lib");
pragma(lib, "lib\\DerelictGLFW3.lib");

void main()
{
    DerelictGL3.load();
    DerelictGLFW3.load();

    if(!glfwInit())
        throw new Exception("glfwInit failure: " ~ to!string(glfwErrorString(glfwGetError())));
    scope(exit) glfwTerminate();

    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

    auto window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Hello DerelictGLFW3", null);
    if(!window)
        throw new Exception("Failed to create window.");

    DerelictGL3.reload();

    writefln("OpenGL version string: %s", to!string(glGetString(GL_VERSION)));
    writefln("OpenGL renderer string: %s", to!string(glGetString(GL_RENDERER)));
    writefln("OpenGL vendor string: %s", to!string(glGetString(GL_VENDOR)));

    int count;
    glGetIntegerv(GL_NUM_EXTENSIONS, &count);
    for(int i=0; i<count; ++i)
        writeln(to!string(glGetStringi(GL_EXTENSIONS, i)));
}


Two things to do now before putting this up on github. I want to make sure all ARB extensions are implemented and I need to get some preliminary documentation set up. I've moved away from the makefile build system for a proprietary build script:

Code:

cd $Derelict/build
rdmd derelict.d


At a minimum, I want to get both this and the new DerelictGL3 interface documented before I release it all to the world. After that, I'll turn my attention back to tying off Derelict 2.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
nocide



Joined: 03 Nov 2009
Posts: 19

PostPosted: Sat Mar 10, 2012 12:07 pm    Post subject: Reply with quote

I'v tried to compile and run this example with GLFW 2.7.3,
but I get a runtime Exception: Failed to load symbol glfwGetVersionString.
Also just uncomment this function just give's me the next exception: Failed to load symbol glfwGetError.
I also can't find this function prototypes in the glfw.h headerfile.

Which version of GLFW do you provide with this binding?
Back to top
View user's profile Send private message
JNewt



Joined: 05 Jun 2008
Posts: 69

PostPosted: Sat Mar 10, 2012 3:09 pm    Post subject: A little guide for building on Linux Reply with quote

OK, after a bit of work, I've got things running on Linux. Here's a little guide to point out some of the pitfalls.

1) Get Derelict3 from github. cd into Derelict3/build and run
Code:
rdmd derelict.d


2) Get GLFW3. Your distro probably ships with 2.x, but the Derelict3 bindings are for GLFW3, so you'll likely need to build from source:
Code:
git clone git://glfw.git.sourceforge.net/gitroot/glfw/glfw
cd glfw
cmake .
make
sudo make install


3) In your code, import Derelict and use pragmas to tell the linker what libs you need:
Code:
import derelict.opengl3.gl3,
      derelict.glfw3.glfw3;

pragma(lib, "DerelictGL3");
pragma(lib, "DerelictGLFW3");
pragma(lib, "DerelictUtil");
pragma(lib, "dl");

Note that the pragma order is important! I was getting linker errors until I remember how ld works.

4) Work from aldacron's example to write your code.

5) Sample makefile:
Code:

#Adjust these paths to your situation
DERELICT = -I../Derelict3/import -L-L../Derelict3/lib

all:
   dmd test.d $(DERELICT)
Back to top
View user's profile Send private message
JNewt



Joined: 05 Jun 2008
Posts: 69

PostPosted: Sat Mar 10, 2012 3:21 pm    Post subject: Reply with quote

EDIT: Whoops, I needed a:
Code:
glfwWaitEvents();


Input doesn't seem to working on Linux. Here's my code:
Code:
bool running = true;
   while (running)
   {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
           glfwSwapBuffers();

      running = glfwIsWindow(win) && glfwGetKey( win, GLFW_KEY_ESCAPE ) != GLFW_PRESS;
   }

This runs regardless of pressing Escape or clicking the window's close button.[/code]
Back to top
View user's profile Send private message
nocide



Joined: 03 Nov 2009
Posts: 19

PostPosted: Sun Mar 11, 2012 4:43 am    Post subject: Reply with quote

It works now!

I also looked into the svn-trunk, which seems to be the 2.7.x line.
But the GLFW3 line seems to be in git only.

many thanks!
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Sun Mar 11, 2012 11:05 pm    Post subject: Reply with quote

nocide wrote:
It works now!

I also looked into the svn-trunk, which seems to be the 2.7.x line.
But the GLFW3 line seems to be in git only.


Right, GLFW3 is the unstable, development version. It was a good time for them to move away from svn. The stable version is the 2.7.x series. There used to be a Derelict binding for 2.x, but we cut it loose (for reasons I no longer remember). The reason I wanted to bind GLFW3 is for access to OpenGL 3.x, which the GLFW 2.x series doesn't support.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
JNewt



Joined: 05 Jun 2008
Posts: 69

PostPosted: Tue Mar 13, 2012 2:25 pm    Post subject: Reply with quote

Is there an API reference for GLFW3? The best I've been able to find is the header file, which isn't particularly helpful as to the meanings of the various parameters.
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Wed Mar 14, 2012 1:12 am    Post subject: Reply with quote

In the docs directory of the source distribution, you'll find the LaTeX files that are used to generate the documentation, along with a readme that tells you how to do so. If that's too much of a hassle (as it is for me), then you can open up glfwrm.tex in a text editor. Using the editor's find function, you'll be able to find the documentation for the functions you are interested in. It's all mixed in with the LaTeX markup, but still legible.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
dav1d



Joined: 12 Sep 2011
Posts: 40

PostPosted: Fri Apr 06, 2012 3:46 pm    Post subject: Reply with quote

There is _no_ documentation for GLFW3 yet (according to the maintainer in #glfw on freenode).
Back to top
View user's profile Send private message
JNewt



Joined: 05 Jun 2008
Posts: 69

PostPosted: Thu May 03, 2012 4:37 pm    Post subject: Reply with quote

Yeah, I noticed that the TeX files didn't quite line up with the headers; glfwOpenWindow stands out as a prime example.
Back to top
View user's profile Send private message
ParticlePeter



Joined: 19 Nov 2011
Posts: 49
Location: Germany

PostPosted: Mon May 28, 2012 5:48 am    Post subject: Reply with quote

Hi,

I was following JNewt code to set up glfw on windows and faced some issues, details are in this thread: http://www.dsource.org/forums/viewtopic.php?p=28504#28504
It might be better to set it up this way:
Code:

void main()  {
   // GLFW Setup Code

   scope( exit )  glfwTerminate() ;
     
   while ( true )  {

      glfwPollEvents() ;
      if ( !glfwIsWindow( window ) || glfwGetKey( window , GLFW_KEY_ESCAPE ) == GLFW_PRESS )
         break ;

      // GL Draw Code
      ...
   }

   writeln( "Clean Exit !" ) ;  // REACHED
}

_________________
Cheers, searching for the Pivot of my Soul, PP
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Derelict All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group