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

How to use DerelictGL in Derelict2

 
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: Wed Mar 25, 2009 1:11 am    Post subject: How to use DerelictGL in Derelict2 Reply with quote

NOTE: Updated for OpenGL 4.0

Until I get some proper documentation into the repo, here's a quick guide on using DerelictGL in Derelict2.

Here's some example source to get you started:

Code:

private
{
   import tango.io.Stdout;
   import derelict.opengl.gl;
   import derelict.sdl.sdl;
   import derelict.util.compat;
}

void main()
{
   DerelictSDL.load();
   DerelictGL.load();
   
   // initialize SDL
   if(SDL_Init(SDL_INIT_VIDEO) < 0)
   {
      throw new Exception("Failed to initialize SDL: " ~ toDString(SDL_GetError()));
   }
   scope(exit)
   {
      if(SDL_Quit !is null)
         SDL_Quit();
   }
   
   // set the minimum desired OpenGL parameters
   SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16);
   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
   SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);
   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
   
   // create the SDL window
   if(SDL_SetVideoMode(800, 600, 0, SDL_OPENGL) == null)
   {
      throw new Exception("Failed to set video mode: " ~ toDString(SDL_GetError()));
   }
   
        // HERE IS WHERE THINGS ARE DIFFERENT
   // load the maximum avaliable version of OpenGL
        // With the addition of OpenGL 3.0 support, the following
        // code will still work, but there is an alternative method (see below)
   DerelictGL.loadExtendedVersions();
   DerelictGL.loadExtensions();
   
   string[] loaded = DerelictGL.loadedExtensionNames;
   string[] notLoaded = DerelictGL.notLoadedExtensionNames;
   
   Stdout("Loaded extensions:").newline;
   foreach(n; loaded)
      Stdout.formatln("\t{}", n);
   
   Stdout("Not loaded extensions:").newline;
   foreach(n; notLoaded)
      Stdout.formatln("\t{}", n);
}


For the most part, the code here is the same as it would be in Derelict 1. The difference is in how OpenGL versions greater than 1.1 and the extensions are loaded.

The function DerelictGL.loadExtendendVersions(GLVersion min = GLVersion.GL11) takes an optional arg that specifies which version of OpenGL you require. If that version is unsupported by the driver (as reported by glGetString(GL_VERSION), a DerelictException will be thrown. If the driver reports it is supported, but any of the functions from that vesion and lower fail to load, a SymbolLoadException will be thrown. An attempt will be made to load any higher versions the driver supports, but no exceptions will be thrown if they fail to load. The default behavior when no args are passed (as in the example above) is the same as passing GLVersion.GL11, i.e., it will attempt to load the highest version available and no exceptions will be thrown on failure.

To determine the highest version available for you to use after calling loadExtendedVersions, you can call DerelictGL.maxVersion.

The extension loading framework is greatly streamlined from Derelict 1. No longer are there separate modules for each extension. They are now contained within two files only: exttypes.d and extfuncs.d. Both modules are publicly imported in glext.d, so you can import just that to use them. You also don't need to import any of these three modules to load the extensions. Previously, extension loaders were registered with static module constructors. You could import only the extension modules you needed, or import them all, including all of the static constructors, with glext. No more.

To load the extensions, you need just the main derelict.opengl.gl module. A single call to DerelictGL.loadExtensions will load every OpenGL extension that Derelict supports. You can then query two methods to see if a function is supported or loaded: DerelictGL.isExtensionSupported(string extName) tests if the driver supports an extension. DerelictGL.isExtensionLoaded(string extName) will tell you whether or not an extension is currently loaded. If this returns false, you can test the return of isExtensionSupported to determine if the extension is loaded because it is unsupported or because it failed.

There are also two new methods which can be useful for debugging or logging (they've helped me find a couple of bugs in the extension loader itself already). DerelictGL.loadedExtensionNames and DerelictGL.notLoadedExtensionNames both return an array of extension name strings. In the case of the former, it is all loaded extensions. In the case of the latter, it is all extensions which are not loaded, appended with "(Unsupported)" if the driver does not support it, or "(Load Failed") if the driver reports it as supported but it failed to load. Currently, there is no mechanism for determining at runtime if DerelictGL has support for an extension. I don't anticipate that there will be either. The documentation will list all supported extensions.

OpenGL 4.0 Update
DerelictGL now includes support for OpenGL 3.0, 3.1, 3,2, 3,3 and 4.0. As part of these additions, I have made some minor changes and additions to the interface.

First, DerelictGL.loadExtendedVersions is now an alias to DerelictGL.loadClassicVersions. The behavior remains the same, but I changed the name to highlight it's functionality. This method will only load OpenGL versions up to 2.1. In order to load versions 3.0 and higher, you will need to call DerelictGL.loadModernVersions.

You will still need to create a context before loading the classic versions (thanks to Windows), and technically you should try to create a 3.0+ context to load the modern versions. However, the modern versions will load fine with a standard context (you'll need a 3.0+ context to use them, though). How you create the context is on you. You can find the relevant Windows API functions in wgl.d and the WGL_ARB extensions in glext.d for Windows. For other platforms, you're on your own. Eventually, Derelict will contain bindings for SFML2 and SDL2(1.3), which both support OpenGL 3.0+ context creation.

In addition to the new GLVersion.GL30/GL31/GL32/GL33/GL40 enum values, there are two more you may find useful: GLVersion.MaxClassic and GLVersion.MaxModern. These indicate the maximum classic and modern versions that Derelict supports. Currently, they are set to GL21 and GL40 respectively.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
ryutenchi



Joined: 09 Dec 2010
Posts: 8

PostPosted: Thu Dec 09, 2010 3:52 pm    Post subject: Reply with quote

So I tried your code, only changing the use of Tango and added a few debug writelns. Compiled fine. DLed the latest 1.2 sdl.dll (1.2.14). It was crashing on the loadModernVersion(GLVersion.GL30), but not on loadExtendedVersion. I'm testing on ATI FirePro V4800 with the latest drivers. Any help? I can test on a Mac book pro and an ubuntu desktop with an ATI 5770 later tonight, but kinda stuck at the moment.

thanks

Update:
Ok added some try tracing and figured out that it's crashing out on line (599) of gl.d where it tries to bind "glMinSampleShading". :
Code:
Opengl DLL crashed out: derelict.util.exception.SymbolLoadException: Failed to load symbol glMinSampleShading from shared library opengl32.dll
Back to top
View user's profile Send private message
aldacron



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

PostPosted: Sun Dec 12, 2010 2:35 am    Post subject: Reply with quote

Thanks. I'll look into it when I get a chance.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
aldacron



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

PostPosted: Sun Dec 12, 2010 2:42 am    Post subject: Reply with quote

Well, actually there's not much I can do to about it. That's an OpenGL 4.0 function, and I don't have drivers that support 4.0. I'm curious to know if anyone else sees this with an Nvidia card as well.
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
Stanley Pancakes



Joined: 26 Dec 2009
Posts: 18

PostPosted: Tue Dec 28, 2010 11:57 pm    Post subject: Reply with quote

Nope, not on Linux with GeForce GTS 450. Though I'm curious about that error message, because I wouldn't expect this function to be in opengl32.dll anyway.
[EDIT: I'll try to dig this up later today at work on Windows with ATI card with 4.0 drivers].

What I've also noticed is that a couple of 3.0 functions don't get loaded by loadModernVersions(): glMapBufferRange and glFlushMappedBufferRange.

They are declared in extfuncs.d and there is a function load_GL_ARB_map_buffer_range() in extloader.d, but it isn't called by the loader.
I would've thought that for extension functions those should get ARB suffix (which they currently don't have), and that the core 3.0 functions without suffix should be loaded by main GL loader via loadModernVersions(). What do you think?
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