www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - OpenGL in D2

reply Siqu <user example.net> writes:
Hi,
I'm trying to figure out how I could get a simple OpenGL/GLUT program working
in DMD2. As an attachment, I've added a C version of what I'd like to do. I'd
compile the C version using:
gcc simple.c -lglut -lGLU -o simple

I've found a few OpenGL projects, like bindings
(http://www.dsource.org/projects/bindings/) and derelict
(http://www.dsource.org/projects/derelict/), but I still can't find any way to
easily use or install them (for D2 on Ubuntu). I'd have thought that, since D
interfaces so well with C, just using C libraries wouldn't require specific
wrapper libraries, but it seems an automated method for converting C headers
to D isn't currently possible?

Anyway, any help would be appreciated,
Thanks.
Feb 21 2011
next sibling parent reply Nrgyzer <nrgyzer gmail.com> writes:
== Auszug aus Siqu (user example.net)'s Artikel
 Hi,
 I'm trying to figure out how I could get a simple OpenGL/GLUT

 in DMD2. As an attachment, I've added a C version of what I'd like

 compile the C version using:
 gcc simple.c -lglut -lGLU -o simple
 I've found a few OpenGL projects, like bindings
 (http://www.dsource.org/projects/bindings/) and derelict
 (http://www.dsource.org/projects/derelict/), but I still can't find

 easily use or install them (for D2 on Ubuntu). I'd have thought

 interfaces so well with C, just using C libraries wouldn't require

 wrapper libraries, but it seems an automated method for converting

 to D isn't currently possible?
 Anyway, any help would be appreciated,
 Thanks.
  << simple.c >>

I'm using derelict, primary on windows, but I've also a running version on Ubuntu. You can download derelict at http://www.dsource.org/projects/derelict/ changeset/525/branches/Derelict2?old_path=%2F&format=zip I think you've already a running version of the dmd-compiler? If yes, you can simply extract the package, open your shell browse to the extracted folder and run "make -flinux.mak DC=dmd" which worked for me on windows and linux (make sure you've installed make and dmd is in your environment-values). On windows you've to create a folder called "lib" before you run the command above - I currently can't say it exactly if it's needed on linux, too. After it compiled, you can copy all the created lib-files to the lib- folder (I think this should be /usr/lib or something like this - run "find / -name 'phobos.lib'" and copy the lib-files to the same directory where phobos.lib is located. Copy the content of the "import"-dir to a location where you've all your binding for D, so that you can simply use "import derelict.sdl.sdl" or similar. When you've installed it correctly, you can use derelict/opengl like described on the derelict site. Note that you have to use 'pragma (lib, "DerelictSDL")' or similar to use the binding. It is also important the you insert 'pragma(lib, "dl")' in you source that you can compile it successfully. I hope this helped :)
Feb 21 2011
parent reply Sequ <user example.net> writes:
Quoted from Nrgyzer:
 On windows you've to create a folder called "lib"
 before you run the command above - I currently
 can't say it exactly if it's needed on linux, too.

 After it compiled, you can copy all the created
 lib-files to the lib-folder

but 'libphobos2.a'. Hopefully that works correctly.
 Copy the content of the "import"-dir to a
 location where you've all your binding for D

source code. I suspect the correct directory is '/usr/include/d/dmd/druntime/import'. I got an SDL example working by then using the command: dmd -L-lDerelictGL -L-lDerelictGLU -L-lDerelictUtil -L-lDerelictSDL test_sdl.d but unfortunately I couldn't get my example working, because it requires GLUT and the derelict library doesn't have that included. I'd actually prefer to use GLUT and also, eventually, other obscure C libraries that I know no-one else would have ported, but I suppose I'll take a look at the links provided in Trass3r's post before asking more about that.
 I hope this helped :)

Quoted from Dmitry Olshansky:
 Sadly your file goes like rubbish for me, is
 that base64 ?

seems my Thunderbird in the Lab can't access the news server from behind all the firewalls - or something). The file is actually just one of the first examples from the OpenGL tutorials.
Feb 23 2011
parent Nrgyzer <nrgyzer gmail.com> writes:
== Auszug aus Sequ (user example.net)'s Artikel
 Quoted from Nrgyzer:
 On windows you've to create a folder called "lib"
 before you run the command above - I currently
 can't say it exactly if it's needed on linux, too.


 After it compiled, you can copy all the created
 lib-files to the lib-folder


 but 'libphobos2.a'. Hopefully that works correctly.
 Copy the content of the "import"-dir to a
 location where you've all your binding for D


 source code. I suspect the correct directory is '/usr/include/d/dmd/

 I got an SDL example working by then using the command:
 dmd -L-lDerelictGL -L-lDerelictGLU -L-lDerelictUtil -L-lDerelictSDL

 but unfortunately I couldn't get my example working, because it

 the derelict library doesn't have that included. I'd actually

 and also, eventually, other obscure C libraries that I know no-one

 ported, but I suppose I'll take a look at the links provided in

 before asking more about that.

As I know, GLUT was also ported (http://www.yage3d.net/host/ derelict.glut.zip). I also tried it with DMD and Derelict - both V1, but I can't get it to work. I think the mistake was on my own, but I didn't spend them much time. The binding is from 2006 (or 2007) and for those I don't suggest you to use it, especially I think it doesn't work with DMD 2 and/or Derelict 2.
 I hope this helped :)

Quoted from Dmitry Olshansky:
 Sadly your file goes like rubbish for me, is
 that base64 ?


 seems my Thunderbird in the Lab can't access the news server from

 firewalls - or something). The file is actually just one of the

 from the OpenGL tutorials.

Feb 23 2011
prev sibling next sibling parent reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 21.02.2011 13:33, Siqu wrote:
 Hi,
 I'm trying to figure out how I could get a simple OpenGL/GLUT program working
 in DMD2. As an attachment, I've added a C version of what I'd like to do. I'd
 compile the C version using:
 gcc simple.c -lglut -lGLU -o simple

 I've found a few OpenGL projects, like bindings
 (http://www.dsource.org/projects/bindings/) and derelict
 (http://www.dsource.org/projects/derelict/), but I still can't find any way to
 easily use or install them (for D2 on Ubuntu). I'd have thought that, since D
 interfaces so well with C, just using C libraries wouldn't require specific
 wrapper libraries, but it seems an automated method for converting C headers
 to D isn't currently possible?

There is htod tool in the digitalmars website, but it's windows only. Also it still leaves much to be desired. IMHO Derelict is so far the best way to OpenGL and such in D, because of the nice way it loads & handles all these weirdness with loading, say, OpenGL extensions. And automatically picking up any suitable shared lib is big win.
 Anyway, any help would be appreciated,
 Thanks.

-- Dmitry Olshansky
Feb 21 2011
parent "Denis Koroskin" <2korden gmail.com> writes:
On Mon, 21 Feb 2011 14:45:51 +0300, Dmitry Olshansky  
<dmitry.olsh gmail.com> wrote:

 On 21.02.2011 13:33, Siqu wrote:
 Hi,
 I'm trying to figure out how I could get a simple OpenGL/GLUT program  
 working
 in DMD2. As an attachment, I've added a C version of what I'd like to  
 do. I'd
 compile the C version using:
 gcc simple.c -lglut -lGLU -o simple

 I've found a few OpenGL projects, like bindings
 (http://www.dsource.org/projects/bindings/) and derelict
 (http://www.dsource.org/projects/derelict/), but I still can't find any  
 way to
 easily use or install them (for D2 on Ubuntu). I'd have thought that,  
 since D
 interfaces so well with C, just using C libraries wouldn't require  
 specific
 wrapper libraries, but it seems an automated method for converting C  
 headers
 to D isn't currently possible?

There is htod tool in the digitalmars website, but it's windows only. Also it still leaves much to be desired. IMHO Derelict is so far the best way to OpenGL and such in D, because of the nice way it loads & handles all these weirdness with loading, say, OpenGL extensions. And automatically picking up any suitable shared lib is big win.
 Anyway, any help would be appreciated,
 Thanks.


All attachments are encoded, but your client should be able to decode it without any issues. Try other software, I recommend Opera's built-in mail client (which features NTTP support).
Feb 21 2011
prev sibling parent Trass3r <un known.com> writes:
 I've found a few OpenGL projects, like bindings
 (http://www.dsource.org/projects/bindings/) and derelict
 (http://www.dsource.org/projects/derelict/), but I still can't find any way to
 easily use or install them (for D2 on Ubuntu).

Use derelict2 from svn and xfBuild. Then you just need to tell dmd where derelict is via -I
 I'd have thought that, since D
 interfaces so well with C, just using C libraries wouldn't require specific
 wrapper libraries, but it seems an automated method for converting C headers
 to D isn't currently possible?

Derelict does a lot more, it hides all the nasty handling of different OpenGL versions that might be installed along with extension loading. To my knowledge there are several tools to convert C headers to D import modules: - htod, which is crappy. Since it's based on dmc, it nearly always complains about header files and the like; it doesn't translate preprocessor conditional compilation to versions or static if and almost always messes something up (const or whatever, can't remember) - SWIG, which I haven't tried yet for that purpose. But I think it will have the same problem with preprocessor conditional compilation. - c2d, don't know how good it works: http://dsource.org/projects/visuald/browser/trunk/c2d - bcd, which is obviously abandoned: http://www.dsource.org/projects/bcd
Feb 21 2011