View previous topic :: View next topic |
Author |
Message |
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Mon Jan 30, 2012 8:15 am Post subject: DerelictGLFW3 |
|
|
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 |
|
|
nocide
Joined: 03 Nov 2009 Posts: 19
|
Posted: Sat Mar 10, 2012 12:07 pm Post subject: |
|
|
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 |
|
|
JNewt
Joined: 05 Jun 2008 Posts: 69
|
Posted: Sat Mar 10, 2012 3:09 pm Post subject: A little guide for building on Linux |
|
|
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
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 |
|
|
JNewt
Joined: 05 Jun 2008 Posts: 69
|
Posted: Sat Mar 10, 2012 3:21 pm Post subject: |
|
|
EDIT: Whoops, I needed a:
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 |
|
|
nocide
Joined: 03 Nov 2009 Posts: 19
|
Posted: Sun Mar 11, 2012 4:43 am Post subject: |
|
|
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 |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Sun Mar 11, 2012 11:05 pm Post subject: |
|
|
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 |
|
|
JNewt
Joined: 05 Jun 2008 Posts: 69
|
Posted: Tue Mar 13, 2012 2:25 pm Post subject: |
|
|
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 |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Wed Mar 14, 2012 1:12 am Post subject: |
|
|
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 |
|
|
dav1d
Joined: 12 Sep 2011 Posts: 40
|
Posted: Fri Apr 06, 2012 3:46 pm Post subject: |
|
|
There is _no_ documentation for GLFW3 yet (according to the maintainer in #glfw on freenode). |
|
Back to top |
|
|
JNewt
Joined: 05 Jun 2008 Posts: 69
|
Posted: Thu May 03, 2012 4:37 pm Post subject: |
|
|
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 |
|
|
ParticlePeter
Joined: 19 Nov 2011 Posts: 49 Location: Germany
|
Posted: Mon May 28, 2012 5:48 am Post subject: |
|
|
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 |
|
|
|