www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - D, Derelict2, and OpenGL

reply "Chris Pons" <cmpons gmail.com> writes:
I have been reading the book "The D Programming Language" and am 
really enjoying D. However, my current motivation to use D was 
specifically for programming through OpenGL, and I was excited 
when I found out Dereict2 provided support for OpenGL.

My current Gfx card can only support up to OpenGL 3.3, Can 
Derelict2 support up to OpenGL 3.3?

Also, and most importantly, would it be possible for me to follow 
a book such as the "Red Book" to learn about using OpenGL with D?

Does anyone have a recommendation for a book about OpenGL that is 
geared towards people new to OpenGL?
Feb 22 2012
next sibling parent David <d dav1d.de> writes:
Am 22.02.2012 23:36, schrieb Chris Pons:
 I have been reading the book "The D Programming Language" and am really
 enjoying D. However, my current motivation to use D was specifically for
 programming through OpenGL, and I was excited when I found out Dereict2
 provided support for OpenGL.

 My current Gfx card can only support up to OpenGL 3.3, Can Derelict2
 support up to OpenGL 3.3?

 Also, and most importantly, would it be possible for me to follow a book
 such as the "Red Book" to learn about using OpenGL with D?

 Does anyone have a recommendation for a book about OpenGL that is geared
 towards people new to OpenGL?
Hello, Yes Derelict2 supports OpenGL 3(.3), you maybe wanna take a look at Derelict3, but be aware, that's just a binding to the gl3-Header, which means you dont have the deprecated function-set (aka. fixed pipeline, <3.0). You can also follow any OpenGL-programming book you like, you've just to port the examples to D, which isn't that hard (opengl function names stay the same), I did it also. Sometimes it's a bit tricky, but it's really doable (e.g. .sizeof on a dynamic array does not return it's size in memory as you would expect as a C-programmer). I used http://www.arcsynthesis.org/gltut/ to teach myself OpenGL, all in all it's a great book, but the source-code is in my opinion really "ugly" and you can't port all the code (well you can but that will take you very long, since they are using their own mesh-formats and loader), therefor I've written some librarys which may be usefule for you: https://bitbucket.org/dav1d/gljm - gljm loads meshes from 2 common formats (.ply and .obj, blender e.g. can export to them) and a custom json format. https://bitbucket.org/dav1d/gl3n - gl3n which implements vector/matrix/quaternion math. Hope this helps - David
Feb 22 2012
prev sibling parent reply Vijay Nayar <vnayar wgen.net> writes:
I am doing almost exactly what you are doing, and to get more familiar 
with both SDL/OpenGL and D, I used Derelict2.

To get familiar with basic graphics in SDL, I used this C++ tutorial, 
http://www.sdltutorials.com/.  The functions pretty much convert 1-to-1 in 
Derelict2.

If it helps, I also have a small project that is hopefully simple enough 
that it is educational.  https://github.com/vnayar/dsdl

  - Vijay

On Wed, 22 Feb 2012, Chris Pons wrote:

 I have been reading the book "The D Programming Language" and am really 
 enjoying D. However, my current motivation to use D was specifically for 
 programming through OpenGL, and I was excited when I found out Dereict2 
 provided support for OpenGL.

 My current Gfx card can only support up to OpenGL 3.3, Can Derelict2 support 
 up to OpenGL 3.3?

 Also, and most importantly, would it be possible for me to follow a book such 
 as the "Red Book" to learn about using OpenGL with D?

 Does anyone have a recommendation for a book about OpenGL that is geared 
 towards people new to OpenGL?
Feb 22 2012
parent reply "Chris Pons" <cmpons gmail.com> writes:
Hey David and Vijay,

Thank you for the swift replies. It seems like this foray into D 
and OpenGL could be a bit overwhelming considering I would be 
learning D and SDL/OpenGL at the same time. So because of this, 
i'm going to make sure I have a solid base in D to start with.

I am an Intermediate level C++ programmer, and I have used 
SDL/SFML/DirectX so the majority so far in the D programming book 
is very familiar.

I however, do have a newbie Derelict2/OpenGL question. I have a 
basic program that simply spawns a window using SDL which I found 
from one of the SDL/OpenGL tuts on the derelict website.

In order to use DerelictGL and DerelictSDL do I simply need to 
import derelict.opengl.gl and import derelict.sdl.sdl and then 
initialize the modules by typing DerelictSDL.load() , 
DerelictGL.load()?

After this am I free to use SDL/OpenGL functions, like 
SDL_Init(...), SDL_Quit(); etc?
Feb 22 2012
parent reply David <d dav1d.de> writes:
Am 23.02.2012 01:20, schrieb Chris Pons:
 Hey David and Vijay,

 Thank you for the swift replies. It seems like this foray into D and
 OpenGL could be a bit overwhelming considering I would be learning D and
 SDL/OpenGL at the same time. So because of this, i'm going to make sure
 I have a solid base in D to start with.

 I am an Intermediate level C++ programmer, and I have used
 SDL/SFML/DirectX so the majority so far in the D programming book is
 very familiar.

 I however, do have a newbie Derelict2/OpenGL question. I have a basic
 program that simply spawns a window using SDL which I found from one of
 the SDL/OpenGL tuts on the derelict website.

 In order to use DerelictGL and DerelictSDL do I simply need to import
 derelict.opengl.gl and import derelict.sdl.sdl and then initialize the
 modules by typing DerelictSDL.load() , DerelictGL.load()?

 After this am I free to use SDL/OpenGL functions, like SDL_Init(...),
 SDL_Quit(); etc?
No you need also do init opengl after creating the context, here's how I am (was) doing it: ---------- static this() { DerelictSDL.load(); DerelictGL.load(); } void main() { writefln("main"); if(SDL_Init(SDL_INIT_VIDEO)) { writefln("error: SDL_INIT_VIDEO"); return; } else { writefln("no error (SDL_INIT_VIDEO)"); } SDL_WM_SetCaption("titel", "nirgends"); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); //SDL_SetVideoMode(1000, 800, 32, SDL_OPENGL | SDL_RESIZABLE); SDL_SetVideoMode(1000, 800, 32, SDL_OPENGL); DerelictGL.loadModernVersions(GLVersion.GL30); DerelictGL.loadExtendedVersions(); //DerelictGL.loadExtensions(); // rendering goes here } ---------------
Feb 22 2012
parent reply "Chris Pons" <cmpons gmail.com> writes:
Ok, thanks for clearing that up. I am really looking forward to 
seeing what D and Derelict2 can offer. However, I would have 
liked to post this in the Derelict forums because it seems like 
the more appropriate place.

I know that Aldacron is only one man, and I appreciate his hard 
work, but how long does it take to get approved to post on that 
forum?

I read that I had to wait for moderator activation (unless I was 
mistaken) ?

On Thursday, 23 February 2012 at 01:15:17 UTC, David wrote:
 Am 23.02.2012 01:20, schrieb Chris Pons:
 Hey David and Vijay,

 Thank you for the swift replies. It seems like this foray into 
 D and
 OpenGL could be a bit overwhelming considering I would be 
 learning D and
 SDL/OpenGL at the same time. So because of this, i'm going to 
 make sure
 I have a solid base in D to start with.

 I am an Intermediate level C++ programmer, and I have used
 SDL/SFML/DirectX so the majority so far in the D programming 
 book is
 very familiar.

 I however, do have a newbie Derelict2/OpenGL question. I have 
 a basic
 program that simply spawns a window using SDL which I found 
 from one of
 the SDL/OpenGL tuts on the derelict website.

 In order to use DerelictGL and DerelictSDL do I simply need to 
 import
 derelict.opengl.gl and import derelict.sdl.sdl and then 
 initialize the
 modules by typing DerelictSDL.load() , DerelictGL.load()?

 After this am I free to use SDL/OpenGL functions, like 
 SDL_Init(...),
 SDL_Quit(); etc?
No you need also do init opengl after creating the context, here's how I am (was) doing it: ---------- static this() { DerelictSDL.load(); DerelictGL.load(); } void main() { writefln("main"); if(SDL_Init(SDL_INIT_VIDEO)) { writefln("error: SDL_INIT_VIDEO"); return; } else { writefln("no error (SDL_INIT_VIDEO)"); } SDL_WM_SetCaption("titel", "nirgends"); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); //SDL_SetVideoMode(1000, 800, 32, SDL_OPENGL | SDL_RESIZABLE); SDL_SetVideoMode(1000, 800, 32, SDL_OPENGL); DerelictGL.loadModernVersions(GLVersion.GL30); DerelictGL.loadExtendedVersions(); //DerelictGL.loadExtensions(); // rendering goes here } ---------------
Feb 22 2012
parent reply Mike Parker <aldacron gmail.com> writes:
On 2/23/2012 10:29 AM, Chris Pons wrote:
 Ok, thanks for clearing that up. I am really looking forward to seeing
 what D and Derelict2 can offer. However, I would have liked to post this
 in the Derelict forums because it seems like the more appropriate place.

 I know that Aldacron is only one man, and I appreciate his hard work,
 but how long does it take to get approved to post on that forum?

 I read that I had to wait for moderator activation (unless I was
 mistaken) ?
I don't know if you are mistaken or not, but looking at the member list sorted by join date, several new members have registered recently. So if approval *is* required, it probably isn't too long. Did you try to log in? At any, rate, I (Aldacron) have nothing to do with approval of members of the forums as a whole. All I can do is moderate posts specifically in the Derelict forum.
Feb 22 2012
parent reply "Chris Pons" <cmpons gmail.com> writes:
Ok, well it must be something wrong on my end. I have tried 
logging in with no result. I'll try to work it.


 I don't know if you are mistaken or not, but looking at the 
 member list sorted by join date, several new members have 
 registered recently. So if approval *is* required, it probably 
 isn't too long. Did you try to log in?

 At any, rate, I (Aldacron) have nothing to do with approval of 
 members of the forums as a whole. All I can do is moderate 
 posts specifically in the Derelict forum.
Feb 22 2012
parent reply James Miller <james aatch.net> writes:
I find that when learning a complicated system or library, the best
way is to write out the code examples, compile them, then change
things until they break, fix it, then make more changes. Eventually
you end up with the worst code ever known to man and a thorough
understanding of the system at hand. I did it recently when figuring
out that there is more to terminal emulation than just IO redirection
and interpreting Terminal codes.

Most of the time, you'll bang your head against your desk screaming
"why wont you work" until you brain-damage your way into an epiphany,
fix everything, achieve enlightenment, ???, PROFIT!
Feb 23 2012
parent reply "Chris Pons" <cmpons gmail.com> writes:
On Thursday, 23 February 2012 at 19:26:31 UTC, James Miller wrote:
 I find that when learning a complicated system or library, the 
 best
 way is to write out the code examples, compile them, then change
 things until they break, fix it, then make more changes. 
 Eventually
 you end up with the worst code ever known to man and a thorough
 understanding of the system at hand. I did it recently when 
 figuring
 out that there is more to terminal emulation than just IO 
 redirection
 and interpreting Terminal codes.

 Most of the time, you'll bang your head against your desk 
 screaming
 "why wont you work" until you brain-damage your way into an 
 epiphany,
 fix everything, achieve enlightenment, ???, PROFIT!
I have followed this same pattern when I work with the UDK. Although, with that, its more about searching through source code, reading over the foundation I'm building upon and moving from there to try to implement my classes. For me, that method has been the best to learn. Along with some frustration when it doesn't go as planned. Is the documentation up-to-date on this site? So that I can search through and try to learn more about a certain library and how it could help me?
Feb 23 2012
parent reply David <d dav1d.de> writes:
Am 24.02.2012 01:50, schrieb Chris Pons:
 Is the documentation up-to-date on this site? So that I can search
 through and try to learn more about a certain library and how it could
 help me?
Which site? The derelict documentation? There is no real derelict documentation, but you normally dont need it, the only thing you're doing with derelict is initializing and loading a shared library (glfw, sdl, opengl …).
Feb 24 2012
parent reply "Chris Pons" <cmpons gmail.com> writes:
On Friday, 24 February 2012 at 09:22:59 UTC, David wrote:
 Am 24.02.2012 01:50, schrieb Chris Pons:
 Is the documentation up-to-date on this site? So that I can 
 search
 through and try to learn more about a certain library and how 
 it could
 help me?
Which site? The derelict documentation? There is no real derelict documentation, but you normally dont need it, the only thing you're doing with derelict is initializing and loading a shared library (glfw, sdl, opengl …).
Ok, I guess I was not specific enough. I was asking about D documentation. Is it up-to-date?
Feb 24 2012
parent reply "Stephen Jones" <siwenjo gmail.com> writes:
In the same vein, I have getting nothing on the screen when there 
should be rendered a red triangle. The vertex positions are those 
used by McKeeson http://www.arcsynthesis.org/gltut/, being in ndc 
fall within the frustum. The code for setting up vao and shaders 
is:

module ShaderHub;

import std.stdio;
import std.string;
import derelict.opengl3.gl3;

class ShaderHub{
	private bool ok=true;
	private GLuint shad=0, vshad=0, fshad=0;
	private int voff=0;
	private GLuint vbo=0, vao=0;
	const float[] v = [	0.75f, 0.75f, 0.0f, 1.0f,
						0.75f, -0.75f, 0.0f, 1.0f,
						-0.75f, -0.75f, 0.0f, 1.0f];
	
	public this(){
		immutable string vshader = `
#version 330
layout(location = 1) in vec4 pos;
void main(void)
{
     gl_Position = pos;
}
`;

		immutable string fshader = `
#version 330
void main(void)
{
     gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
`;

		shad=glCreateProgram();
		if(shad==0){
			writeln("Error: GL did not assigh main shader program id");
			ok=false;
		}
		
		vshad=glCreateShader(GL_VERTEX_SHADER);
		const char *vptr=toStringz(vshader);
		glShaderSource(vshad, 1, &vptr, null);
		glCompileShader(vshad);	
		int status, len;
		glGetShaderiv(vshad, GL_COMPILE_STATUS, &status);
		if(status==GL_FALSE){
			glGetShaderiv(vshad, GL_INFO_LOG_LENGTH, &len);
			char[] error=new char[len];
			glGetShaderInfoLog(vshad, len, null, cast(char*)error);
			writeln(error);
			ok=false;
		}
		
		fshad=glCreateShader(GL_FRAGMENT_SHADER);
		const char *fptr=toStringz(fshader);
		glShaderSource(fshad, 1, &fptr, null);
		glCompileShader(fshad);	
		glGetShaderiv(vshad, GL_COMPILE_STATUS, &status);
		if(status==GL_FALSE){
			glGetShaderiv(fshad, GL_INFO_LOG_LENGTH, &len);
			char[] error=new char[len];
			glGetShaderInfoLog(fshad, len, null, cast(char*)error);
			writeln(error);
			ok=false;
		}
		
		glAttachShader(shad, vshad);
		glAttachShader(shad, fshad);
		glLinkProgram(shad);
		glGetShaderiv(shad, GL_LINK_STATUS, &status);
		if(status==GL_FALSE){
			glGetShaderiv(shad, GL_INFO_LOG_LENGTH, &len);
			char[] error=new char[len];
			glGetShaderInfoLog(shad, len, null, cast(char*)error);
			writeln(error);
			ok=false;
		}
		
		
		glGenVertexArrays(1, &vao);
		if(vao<1){
			writeln("Error: GL failed to assign vao id");
			ok=false;
		}
		glBindVertexArray(vao);
		
		glGenBuffers(1, &vbo);
		if(vbo<1){
			writeln("Error: GL failed to assign vbo id");
			ok=false;
		}
		glBindBuffer(GL_ARRAY_BUFFER, vbo);
		glBufferData(GL_ARRAY_BUFFER, v.length * GL_FLOAT.sizeof, 
&v[0], GL_STATIC_DRAW);
		glEnableVertexAttribArray(1);
		glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 
cast(void*)voff);	
			
		glBindBuffer(GL_ARRAY_BUFFER, 0);
		glBindVertexArray(0);	
	}
	
	public void draw(){
		glUseProgram(shad);
		
		writeln(glGetAttribLocation(shad, "pos"));//prints 1
		
		glBindVertexArray(vao);	
		glDrawArrays(GL_TRIANGLES, 0, 6);		
		glBindVertexArray(0);
		

		glUseProgram(0);
	}
}

//__________________________________________________________________

the code for setting up openGL3 is:


import std.stdio;
import derelict.sdl2.sdl;
import derelict.opengl3.gl3;

import EventHub;
import ExposeApp;

pragma(lib, "DerelictUtil.lib");
pragma(lib, "DerelictSDL2.lib");
pragma(lib, "DerelictGL3.lib");


class App{
     private ExposeApp funcPtrs;
     private EventHub ehub;
     private SDL_Window *win;
     private SDL_GLContext context;
     private int w=600, h=480, fov=55;
     private bool running=true;

     public this(){
         if(!initSDL()){
             writeln("Error initializing SDL");
             SDL_Quit();
         }
         initGL();

         funcPtrs=new ExposeApp();
         funcPtrs.stop=&stopLoop;
         funcPtrs.grabMouse=&grabMouse;
         funcPtrs.releaseMouse=&releaseMouse;
         ehub=new EventHub(funcPtrs);


         while(running){
             glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

             ehub.tick();

             SDL_GL_SwapWindow(win);
         }


         SDL_GL_DeleteContext(context);
         SDL_DestroyWindow(win);
         SDL_Quit();
     }

     private void stopLoop(){
         running=false;
     }
     private void grabMouse(){
         SDL_ShowCursor(SDL_DISABLE);
         SDL_SetWindowGrab(win, SDL_TRUE);
     }
     private void releaseMouse(){
         SDL_ShowCursor(SDL_ENABLE);
         SDL_SetWindowGrab(win, SDL_FALSE);
     }
     private bool initSDL(){
         if(SDL_Init(SDL_INIT_VIDEO)< 0){
			writefln("Error initializing SDL");
			SDL_Quit();
			return false;
		}
				
		SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
		SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
		SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
		
		win=SDL_CreateWindow("3Doodle", SDL_WINDOWPOS_CENTERED, 
SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_OPENGL | 
SDL_WINDOW_SHOWN);
         if(!win){
             writefln("Error creating SDL window");
			SDL_Quit();
			return false;
         }

         context=SDL_GL_CreateContext(win);
         SDL_GL_SetSwapInterval(1);

         DerelictGL3.reload();

         return true;
     }
     private void initGL(){
         resize(w, h);

         glEnable(GL_DEPTH_TEST);
         glEnable(GL_CULL_FACE);

         glDepthFunc(GL_LEQUAL);

         glClearColor(0.0, 0.0, 0.0, 1.0);
         glClearDepth(1.0);

         glCullFace(GL_BACK);
         glFrontFace(GL_CCW);

     }
     private void resize(int w, int h){
         //this will contain the makings of the projection matrix, 
which we go into next tut
         glViewport(0, 0, w, h);
     }
}


void main(){
     try{
         DerelictSDL2.load();
     }catch(Exception e){
         writeln("Error loading SDL2 lib");
     }
     try{
         DerelictGL3.load();
     }catch(Exception e){
         writeln("Error loading GL3 lib");
     }

     App a=new App();
}


Any help would be great.
Apr 19 2012
parent David <d dav1d.de> writes:
Am 20.04.2012 00:34, schrieb Stephen Jones:
 In the same vein, I have getting nothing on the screen when there should
 be rendered a red triangle. The vertex positions are those used by
 McKeeson http://www.arcsynthesis.org/gltut/, being in ndc fall within
 the frustum. The code for setting up vao and shaders is:

 module ShaderHub;

 import std.stdio;
 import std.string;
 import derelict.opengl3.gl3;

 class ShaderHub{
 private bool ok=true;
 private GLuint shad=0, vshad=0, fshad=0;
 private int voff=0;
 private GLuint vbo=0, vao=0;
 const float[] v = [ 0.75f, 0.75f, 0.0f, 1.0f,
 0.75f, -0.75f, 0.0f, 1.0f,
 -0.75f, -0.75f, 0.0f, 1.0f];

 public this(){
 immutable string vshader = `
 #version 330
 layout(location = 1) in vec4 pos;
 void main(void)
 {
 gl_Position = pos;
 }
 `;

 immutable string fshader = `
 #version 330
 void main(void)
 {
 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
 }
 `;

 shad=glCreateProgram();
 if(shad==0){
 writeln("Error: GL did not assigh main shader program id");
 ok=false;
 }

 vshad=glCreateShader(GL_VERTEX_SHADER);
 const char *vptr=toStringz(vshader);
 glShaderSource(vshad, 1, &vptr, null);
 glCompileShader(vshad);
 int status, len;
 glGetShaderiv(vshad, GL_COMPILE_STATUS, &status);
 if(status==GL_FALSE){
 glGetShaderiv(vshad, GL_INFO_LOG_LENGTH, &len);
 char[] error=new char[len];
 glGetShaderInfoLog(vshad, len, null, cast(char*)error);
 writeln(error);
 ok=false;
 }

 fshad=glCreateShader(GL_FRAGMENT_SHADER);
 const char *fptr=toStringz(fshader);
 glShaderSource(fshad, 1, &fptr, null);
 glCompileShader(fshad);
 glGetShaderiv(vshad, GL_COMPILE_STATUS, &status);
 if(status==GL_FALSE){
 glGetShaderiv(fshad, GL_INFO_LOG_LENGTH, &len);
 char[] error=new char[len];
 glGetShaderInfoLog(fshad, len, null, cast(char*)error);
 writeln(error);
 ok=false;
 }

 glAttachShader(shad, vshad);
 glAttachShader(shad, fshad);
 glLinkProgram(shad);
 glGetShaderiv(shad, GL_LINK_STATUS, &status);
 if(status==GL_FALSE){
 glGetShaderiv(shad, GL_INFO_LOG_LENGTH, &len);
 char[] error=new char[len];
 glGetShaderInfoLog(shad, len, null, cast(char*)error);
 writeln(error);
 ok=false;
 }


 glGenVertexArrays(1, &vao);
 if(vao<1){
 writeln("Error: GL failed to assign vao id");
 ok=false;
 }
 glBindVertexArray(vao);

 glGenBuffers(1, &vbo);
 if(vbo<1){
 writeln("Error: GL failed to assign vbo id");
 ok=false;
 }
 glBindBuffer(GL_ARRAY_BUFFER, vbo);
 glBufferData(GL_ARRAY_BUFFER, v.length * GL_FLOAT.sizeof, &v[0],
 GL_STATIC_DRAW);
 glEnableVertexAttribArray(1);
 glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, cast(void*)voff);

 glBindBuffer(GL_ARRAY_BUFFER, 0);
 glBindVertexArray(0);
 }

 public void draw(){
 glUseProgram(shad);

 writeln(glGetAttribLocation(shad, "pos"));//prints 1

 glBindVertexArray(vao);
 glDrawArrays(GL_TRIANGLES, 0, 6);
 glBindVertexArray(0);


 glUseProgram(0);
 }
 }

 //__________________________________________________________________

 the code for setting up openGL3 is:


 import std.stdio;
 import derelict.sdl2.sdl;
 import derelict.opengl3.gl3;

 import EventHub;
 import ExposeApp;

 pragma(lib, "DerelictUtil.lib");
 pragma(lib, "DerelictSDL2.lib");
 pragma(lib, "DerelictGL3.lib");


 class App{
 private ExposeApp funcPtrs;
 private EventHub ehub;
 private SDL_Window *win;
 private SDL_GLContext context;
 private int w=600, h=480, fov=55;
 private bool running=true;

 public this(){
 if(!initSDL()){
 writeln("Error initializing SDL");
 SDL_Quit();
 }
 initGL();

 funcPtrs=new ExposeApp();
 funcPtrs.stop=&stopLoop;
 funcPtrs.grabMouse=&grabMouse;
 funcPtrs.releaseMouse=&releaseMouse;
 ehub=new EventHub(funcPtrs);


 while(running){
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

 ehub.tick();

 SDL_GL_SwapWindow(win);
 }


 SDL_GL_DeleteContext(context);
 SDL_DestroyWindow(win);
 SDL_Quit();
 }

 private void stopLoop(){
 running=false;
 }
 private void grabMouse(){
 SDL_ShowCursor(SDL_DISABLE);
 SDL_SetWindowGrab(win, SDL_TRUE);
 }
 private void releaseMouse(){
 SDL_ShowCursor(SDL_ENABLE);
 SDL_SetWindowGrab(win, SDL_FALSE);
 }
 private bool initSDL(){
 if(SDL_Init(SDL_INIT_VIDEO)< 0){
 writefln("Error initializing SDL");
 SDL_Quit();
 return false;
 }

 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);

 win=SDL_CreateWindow("3Doodle", SDL_WINDOWPOS_CENTERED,
 SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
 if(!win){
 writefln("Error creating SDL window");
 SDL_Quit();
 return false;
 }

 context=SDL_GL_CreateContext(win);
 SDL_GL_SetSwapInterval(1);

 DerelictGL3.reload();

 return true;
 }
 private void initGL(){
 resize(w, h);

 glEnable(GL_DEPTH_TEST);
 glEnable(GL_CULL_FACE);

 glDepthFunc(GL_LEQUAL);

 glClearColor(0.0, 0.0, 0.0, 1.0);
 glClearDepth(1.0);

 glCullFace(GL_BACK);
 glFrontFace(GL_CCW);

 }
 private void resize(int w, int h){
 //this will contain the makings of the projection matrix, which we go
 into next tut
 glViewport(0, 0, w, h);
 }
 }


 void main(){
 try{
 DerelictSDL2.load();
 }catch(Exception e){
 writeln("Error loading SDL2 lib");
 }
 try{
 DerelictGL3.load();
 }catch(Exception e){
 writeln("Error loading GL3 lib");
 }

 App a=new App();
 }


 Any help would be great.
Question on Stackoverflow: http://stackoverflow.com/questions/10236529/why-doesnt-derelictgl3-draw-anything If you ask here, pls open a new "Thread", appending just confuses people like me.
Apr 20 2012