root/branches/Derelict2/dgl.d

Revision 623, 3.9 kB (checked in by aldacron, 2 weeks ago)

[Derelict2 - DerelictGL]
* parsing of the extension string was handled improperly all this time. Now fixed.

Line 
1 module dgl;
2
3 version(Windows)
4 {
5     pragma(lib, "lib\\DerelictGL.lib");
6     pragma(lib, "lib\\DerelictGLU.lib");
7     pragma(lib, "lib\\DerelictSDL.lib");
8     pragma(lib, "lib\\DerelictUtil.lib");
9 }
10 else
11 {
12     pragma(lib, "dl");
13     pragma(lib, "lib/libDerelictGL.a");
14     pragma(lib, "lib/libDerelictGLU.a");
15     pragma(lib, "lib/libDerelictSDL.a");
16     pragma(lib, "lib/libDerelictUtil.a");
17 }
18
19 import derelict.sdl.sdl;
20 //import derelict.sdl.image;
21 //import derelict.sdl.mixer;
22 //import derelict.sdl.net;
23 //import derelict.sdl.ttf;
24 import derelict.opengl.gl;
25 import derelict.opengl.glu;
26 import derelict.util.compat;
27 version (Tango) {}
28 else
29 import std.stdio;
30
31 version(D_Version2) {}
32 else version (Tango)
33 {
34     import tango.io.Stdout;
35 }
36 else
37 {
38     alias writefln writeln;
39 }
40
41 void println (A...)(A args)
42 {
43     version (Tango)
44     {
45         static const string fmt = "{}{}{}{}{}{}{}{}"
46                                   "{}{}{}{}{}{}{}{}"
47                                   "{}{}{}{}{}{}{}{}";
48
49         static assert (A.length <= fmt.length / 2, "too many arguments");
50
51         Stdout.formatln(fmt[0 .. args.length * 2], args);
52     }
53
54     else
55         writeln(args);
56 }
57
58 void dumpver(string sdlLib, CSDLVERPTR ver)
59 {
60     println(sdlLib, " version: ", ver.major, '.', ver.minor, '.', ver.patch);
61 }
62
63 void main()
64 {
65     DerelictSDL.load();
66     DerelictGL.load();
67     DerelictGLU.load();
68 //  DerelictSDLImage.load();
69 //  DerelictSDLMixer.load();
70 //  DerelictSDLNet.load();
71 //  DerelictSDLttf.load();
72
73     if(SDL_Init(SDL_INIT_VIDEO) < 0)
74     {
75         throw new Exception("Couldn't init SDL: " ~ toDString(SDL_GetError()));
76     }
77     scope(exit)
78     {
79         if(SDL_Quit !is null)
80             SDL_Quit();
81     }
82
83     SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
84     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
85     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
86
87     if(SDL_SetVideoMode(1024, 768, 0, SDL_OPENGL) == null)
88     {
89         throw new Exception("Failed to set video mode: " ~ toDString(SDL_GetError()));
90     }
91
92     CSDLVERPTR sdlver = SDL_Linked_Version();
93     dumpver("SDL", sdlver);
94 /*
95     sdlver = IMG_Linked_Version();
96     dumpver("SDL_image", sdlver);
97
98     sdlver = Mix_Linked_Version();
99     dumpver("SDL_mixer", sdlver);
100
101     sdlver = SDLNet_Linked_Version();
102     dumpver("SDL_net", sdlver);
103
104     sdlver = TTF_Linked_Version();
105     dumpver("SDL_ttf", sdlver);
106 */
107     GLVersion ver = DerelictGL.loadClassicVersions(GLVersion.GL21);
108     ver = DerelictGL.loadModernVersions(GLVersion.GL30);
109     println("Max GL version = ", DerelictGL.versionToString(ver));
110
111     string glver = toDString(glGetString(GL_VERSION));
112     println("GL version string = ", glver);
113
114     string gluver = toDString(gluGetString(GLU_VERSION));
115     println("GLU version string = ", gluver);
116
117     DerelictGL.loadExtensions();
118
119     println("Loaded OpenGL Extensions:");
120     string[] extlist = DerelictGL.loadedExtensionNames;
121     foreach(s; extlist)
122         println("\t", s);
123
124     println("Not Loaded OpenGL Extensions:");
125     extlist = DerelictGL.notLoadedExtensionNames;
126     foreach(s; extlist)
127         println("\t", s);
128
129     println("GL Extension String: ", toDString(glGetString(GL_EXTENSIONS)), "]");
130
131     glClearColor(0.0, 0.0, 1.0, 1.0);
132
133     bool running = true;
134
135     while(running)
136     {
137         SDL_Event event;
138         while(SDL_PollEvent(&event))
139         {
140             switch(event.type)
141             {
142                 case SDL_KEYDOWN:
143                     if(SDLK_ESCAPE == event.key.keysym.sym)
144                     {
145                         running = false;
146                     }
147                     break;
148                 case SDL_QUIT:
149                     running = false;
150                     break;
151                 default:
152                     break;
153
154             }
155         }
156         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
157         SDL_GL_SwapBuffers();
158         SDL_Delay(1);
159     }
160 }
Note: See TracBrowser for help on using the browser.