+ struct dd_function_table functions;
+
+ if (!rgbFlag) {
+ fprintf(stderr, "Mesa Warning: color index mode not supported\n");
+ }
+
+ // Allocate auxiliary data object
+ MesaDriver * md = new MesaDriver();
+
+ // examine option flags and create gl_context struct
+ GLvisual * visual = _mesa_create_visual( rgbFlag,
+ dblFlag,
+ stereoFlag,
+ red, green, blue, alpha,
+ index,
+ depth,
+ stencil,
+ accum, accum, accum, accum,
+ 1
+ );
+
+ // Initialize device driver function table
+ _mesa_init_driver_functions(&functions);
+
+ functions.GetString = md->GetString;
+ functions.UpdateState = md->UpdateState;
+ functions.GetBufferSize = md->GetBufferSize;
+ functions.Clear = md->Clear;
+ functions.ClearIndex = md->ClearIndex;
+ functions.ClearColor = md->ClearColor;
+ functions.Error = md->Error;
+
+ // create core context
+ GLcontext *ctx = _mesa_create_context(visual, NULL, &functions, md);
+ if (! ctx) {
+ _mesa_destroy_visual(visual);
+ delete md;
+ return;
+ }
+ _mesa_enable_sw_extensions(ctx);
+ _mesa_enable_1_3_extensions(ctx);
+ _mesa_enable_1_4_extensions(ctx);
+ _mesa_enable_1_5_extensions(ctx);
+
+
+ // create core framebuffer
+ GLframebuffer * buffer = _mesa_create_framebuffer(visual,
+ depth > 0 ? GL_TRUE : GL_FALSE,
+ stencil > 0 ? GL_TRUE: GL_FALSE,
+ accum > 0 ? GL_TRUE : GL_FALSE,
+ alphaFlag
+ );
+
+ /* Initialize the software rasterizer and helper modules.
+ */
+ _swrast_CreateContext(ctx);
+ _ac_CreateContext(ctx);
+ _tnl_CreateContext(ctx);
+ _swsetup_CreateContext(ctx);
+ _swsetup_Wakeup(ctx);
+
+ md->Init(this, ctx, visual, buffer );
+
+ // Hook aux data into BGLView object
+ m_gc = md;
+
+ // some stupid applications (Quake2) don't even think about calling LockGL()
+ // before using glGetString and friends... so make sure there is at least a
+ // valid context.
+ if (!_mesa_get_current_context()) {
+ LockGL();
+ // not needed, we don't have a looper yet: UnlockLooper();
+ }