Revision: 75538
http://sourceforge.net/p/brlcad/code/75538
Author: starseeker
Date: 2020-04-22 15:20:50 +0000 (Wed, 22 Apr 2020)
Log Message:
-----------
This gets wgl building with MSVC - untested.
Modified Paths:
--------------
brlcad/branches/dm-fb-merge/src/libdm/wgl/dm-wgl.c
brlcad/branches/dm-fb-merge/src/libdm/wgl/if_wgl.c
Modified: brlcad/branches/dm-fb-merge/src/libdm/wgl/dm-wgl.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/wgl/dm-wgl.c 2020-04-22 15:12:27 UTC
(rev 75537)
+++ brlcad/branches/dm-fb-merge/src/libdm/wgl/dm-wgl.c 2020-04-22 15:20:50 UTC
(rev 75538)
@@ -366,297 +366,8 @@
return BRLCAD_OK;
}
-/*
- * Fire up the display manager, and the display processor.
- *
- */
-struct dm *
-wgl_open(void *vinterp, int argc, char *argv[])
-{
- static int count = 0;
- GLfloat backgnd[4];
- int make_square = -1;
- struct bu_vls str = BU_VLS_INIT_ZERO;
- struct bu_vls init_proc_vls = BU_VLS_INIT_ZERO;
- struct modifiable_ogl_vars *mvars = NULL;
- struct dm *dmp = NULL;
- Tcl_Interp *interp = (Tcl_Interp *)vinterp;
- Tk_Window tkwin;
- HWND hwnd;
- HDC hdc;
- int gotvisual;
- if ((tkwin = Tk_MainWindow(interp)) == NULL) {
- return DM_NULL;
- }
- BU_ALLOC(dmp, struct dm);
- BU_ALLOC(dmp->i, struct dm_impl);
-
- *dmpi->i = *dm_wgl_impl; /* struct copy */
- dmp->i->dm_interp = interp;
- dmp->i->dm_light = 1;
-
- BU_ALLOC(dmp->i->dm_vars.pub_vars, struct dm_wglvars);
- BU_ALLOC(dmp->i->dm_vars.priv_vars, struct wgl_vars);
-
- dmp->i->dm_get_internal(dmp);
- mvars = (struct modifiable_ogl_vars *)dmp->i->m_vars;
-
- dmp->i->dm_vp = &default_viewscale;
-
- bu_vls_init(&dmp->i->dm_pathName);
- bu_vls_init(&dmp->i->dm_tkName);
- bu_vls_init(&dmp->i->dm_dName);
-
- dm_processOptions(dmp, &init_proc_vls, --argc, ++argv);
-
- if (bu_vls_strlen(&dmp->i->dm_pathName) == 0)
- bu_vls_printf(&dmp->i->dm_pathName, ".dm_wgl%d", count);
- ++count;
-
- if (bu_vls_strlen(&dmp->i->dm_dName) == 0) {
- char *dp;
-
- dp = getenv("DISPLAY");
- if (dp)
- bu_vls_strcpy(&dmp->i->dm_dName, dp);
- else
- bu_vls_strcpy(&dmp->i->dm_dName, ":0.0");
- }
- if (bu_vls_strlen(&init_proc_vls) == 0)
- bu_vls_strcpy(&init_proc_vls, "bind_dm");
-
- /* initialize dm specific variables */
- ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->devmotionnotify =
LASTEvent;
- ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->devbuttonpress =
LASTEvent;
- ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->devbuttonrelease =
LASTEvent;
- dmp->i->dm_aspect = 1.0;
-
- /* initialize modifiable variables */
- mvars->rgb = 1;
- mvars->doublebuffer = 1;
- mvars->fastfog = 1;
- mvars->fogdensity = 1.0;
- mvars->lighting_on = dmp->i->dm_light;
- mvars->zbuffer_on = dmp->i->dm_zbuffer;
- mvars->zclipping_on = dmp->i->dm_zclip;
- mvars->debug = dmp->i->dm_debugLevel;
- mvars->bound = dmp->i->dm_bound;
- mvars->boundFlag = dmp->i->dm_boundFlag;
-
- /* this is important so that wgl_configureWin knows to set the font */
- ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->fontstruct = NULL;
-
- if (dmp->i->dm_width == 0) {
- dmp->i->dm_width = GetSystemMetrics(SM_CXSCREEN) - 30;
- ++make_square;
- }
- if (dmp->i->dm_height == 0) {
- dmp->i->dm_height = GetSystemMetrics(SM_CYSCREEN) - 30;
- ++make_square;
- }
-
- if (make_square > 0) {
- /* Make window square */
- if (dmp->i->dm_height <
- dmp->i->dm_width)
- dmp->i->dm_width =
- dmp->i->dm_height;
- else
- dmp->i->dm_height =
- dmp->i->dm_width;
- }
-
- if (dmp->i->dm_top) {
- /* Make xtkwin a toplevel window */
- Tcl_DString ds;
-
- Tcl_DStringInit(&ds);
- Tcl_DStringAppend(&ds, "toplevel ", -1);
- Tcl_DStringAppend(&ds, bu_vls_addr(&dmp->i->dm_pathName), -1);
- Tcl_DStringAppend(&ds, "; wm deiconify ", -1);
- Tcl_DStringAppend(&ds, bu_vls_addr(&dmp->i->dm_pathName), -1);
- if (Tcl_Eval(interp, Tcl_DStringValue(&ds)) != BRLCAD_OK) {
- Tcl_DStringFree(&ds);
- return DM_NULL;
- }
- ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin =
- Tk_NameToWindow(interp, bu_vls_addr(&dmp->i->dm_pathName), tkwin);
- Tcl_DStringFree(&ds);
- ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->top = ((struct
dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin;
- }
- else {
- char *cp;
-
- cp = strrchr(bu_vls_addr(&dmp->i->dm_pathName), (int)'.');
- if (cp == bu_vls_addr(&dmp->i->dm_pathName)) {
- ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->top = tkwin;
- }
- else {
- struct bu_vls top_vls = BU_VLS_INIT_ZERO;
-
- bu_vls_strncpy(&top_vls, (const char
*)bu_vls_addr(&dmp->i->dm_pathName), cp - bu_vls_addr(&dmp->i->dm_pathName));
-
- ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->top =
- Tk_NameToWindow(interp, bu_vls_addr(&top_vls), tkwin);
- bu_vls_free(&top_vls);
- }
-
- /* Make xtkwin an embedded window */
- ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin =
- Tk_CreateWindow(interp, ((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->top,
- cp + 1, (char *)NULL);
- }
-
- if (((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin == NULL) {
- bu_log("open_gl: Failed to open %s\n",
bu_vls_addr(&dmp->i->dm_pathName));
- bu_vls_free(&init_proc_vls);
- (void)wgl_close(dmp);
- return DM_NULL;
- }
-
- bu_vls_printf(&dmp->i->dm_tkName, "%s",
- (char *)Tk_Name(((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->xtkwin));
-
- bu_vls_printf(&str, "_init_dm %s %s\n",
- bu_vls_addr(&init_proc_vls),
- bu_vls_addr(&dmp->i->dm_pathName));
-
- if (Tcl_Eval(interp, bu_vls_addr(&str)) == BRLCAD_ERROR) {
- bu_log("open_wgl: _init_dm failed\n");
- bu_vls_free(&init_proc_vls);
- bu_vls_free(&str);
- (void)wgl_close(dmp);
- return DM_NULL;
- }
-
- bu_vls_free(&init_proc_vls);
- bu_vls_free(&str);
-
- ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->dpy =
- Tk_Display(((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->top);
-
- /* make sure there really is a display before proceeding. */
- if (!((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->dpy) {
- (void)wgl_close(dmp);
- return DM_NULL;
- }
-
- Tk_GeometryRequest(((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin,
- dmp->i->dm_width,
- dmp->i->dm_height);
-
- Tk_MakeWindowExist(((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->xtkwin);
-
- ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->win =
- Tk_WindowId(((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin);
- dmp->i->dm_id = ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->win;
-
- hwnd = TkWinGetHWND(((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->win);
- hdc = GetDC(hwnd);
- ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->hdc = hdc;
-
- gotvisual = wgl_choose_visual(dmp, ((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->xtkwin);
- if (!gotvisual) {
- bu_log("wgl_open: Can't get an appropriate visual.\n");
- (void)wgl_close(dmp);
- return DM_NULL;
- }
-
- ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->depth = mvars->depth;
-
- /* open GLX context */
- if ((((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->glxc =
- wglCreateContext(((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->hdc)) == NULL) {
- bu_log("wgl_open: couldn't create glXContext.\n");
- (void)wgl_close(dmp);
- return DM_NULL;
- }
-
- if (!wglMakeCurrent(((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->hdc,
- ((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->glxc)) {
- bu_log("wgl_open: couldn't make context current\n");
- (void)wgl_close(dmp);
- return DM_NULL;
- }
-
- /* display list (fontOffset + char) will display a given ASCII char */
- if ((((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->fontOffset =
glGenLists(128)) == 0) {
- bu_log("wgl_open: couldn't make display lists for font.\n");
- (void)wgl_close(dmp);
- return DM_NULL;
- }
-
- /* This is the applications display list offset */
- dmp->i->dm_displaylist = ((struct wgl_vars
*)dmp->i->dm_vars.priv_vars)->fontOffset + 128;
-
- wgl_setBGColor(dmp, 0, 0, 0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- if (mvars->doublebuffer)
- glDrawBuffer(GL_BACK);
- else
- glDrawBuffer(GL_FRONT);
-
- /* do viewport, ortho commands and initialize font */
- (void)wgl_configureWin_guts(dmp, 1);
-
- /* Lines will be solid when stippling disabled, dashed when enabled*/
- glLineStipple(1, 0xCF33);
- glDisable(GL_LINE_STIPPLE);
-
- backgnd[0] = backgnd[1] = backgnd[2] = backgnd[3] = 0.0;
- glFogi(GL_FOG_MODE, GL_LINEAR);
- glFogf(GL_FOG_START, 0.0);
- glFogf(GL_FOG_END, 2.0);
- glFogfv(GL_FOG_COLOR, backgnd);
-
- /*XXX Need to do something about VIEWFACTOR */
- glFogf(GL_FOG_DENSITY, VIEWFACTOR);
-
- /* Initialize matrices */
- /* Leave it in model_view mode normally */
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-xlim_view, xlim_view, -ylim_view, ylim_view, 0.0, 2.0);
- glGetDoublev(GL_PROJECTION_MATRIX, ((struct wgl_vars
*)dmp->i->dm_vars.priv_vars)->faceplate_mat);
- glPushMatrix();
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glPushMatrix();
- glLoadIdentity();
- ((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->face_flag = 1; /*
faceplate matrix is on top of stack */
-
- wgl_setZBuffer(dmp, dmp->i->dm_zbuffer);
- wgl_setLight(dmp, dmp->i->dm_light);
-
- if (!wglMakeCurrent((HDC)NULL, (HGLRC)NULL)) {
- LPVOID buf;
-
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- GetLastError(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR)&buf,
- 0,
- NULL);
- bu_log("wgl_drawBegin: Couldn't release the current context.\n");
- bu_log("wgl_drawBegin: %s", buf);
- LocalFree(buf);
-
- return DM_NULL;
- }
-
- Tk_MapWindow(((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin);
-
- Tk_CreateEventHandler(((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->xtkwin, VisibilityChangeMask, WGLEventProc,
(ClientData)dmp);
-
- return dmp;
-}
-
/*
* Gracefully release the display.
*/
@@ -2009,8 +1720,7 @@
HIDDEN int
wgl_getDisplayImage(struct dm *dmp, unsigned char **image)
{
- if (dmp->i->dm_type == DM_TYPE_WGL || dmp->i->dm_type == DM_TYPE_OGL) {
- unsigned char *idata;
+ unsigned char *idata;
int width;
int height;
@@ -2024,11 +1734,7 @@
glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, idata);
*image = idata;
flip_display_image_vertically(*image, width, height);
- } else {
- bu_log("ogl_getDisplayImage: Display type not set as OGL or WGL\n");
- return BRLCAD_ERROR;
- }
-
+
return BRLCAD_OK; /* caller will need to bu_free(idata, "image data"); */
}
@@ -2563,6 +2269,9 @@
};
}
+/* Forward declare for dm_wgl_impl */
+struct dm *wgl_open(void *vinterp, int argc, char *argv[]);
+
struct dm_impl dm_wgl_impl = {
wgl_open,
wgl_close,
@@ -2655,7 +2364,301 @@
0 /* Tcl interpreter */
};
+/*
+ * Fire up the display manager, and the display processor.
+ *
+ * Note: with Visual C++ the dm_wgl_impl struct copy below
+ * doesn't get set up unless we first define the struct,
+ * then define the function.
+ *
+ */
+struct dm *
+ wgl_open(void *vinterp, int argc, char *argv[])
+{
+ static int count = 0;
+ GLfloat backgnd[4];
+ int make_square = -1;
+ struct bu_vls str = BU_VLS_INIT_ZERO;
+ struct bu_vls init_proc_vls = BU_VLS_INIT_ZERO;
+ struct modifiable_ogl_vars *mvars = NULL;
+ struct dm *dmp = NULL;
+ Tcl_Interp *interp = (Tcl_Interp *)vinterp;
+ Tk_Window tkwin;
+ HWND hwnd;
+ HDC hdc;
+ int gotvisual;
+ if ((tkwin = Tk_MainWindow(interp)) == NULL) {
+ return DM_NULL;
+ }
+
+ BU_ALLOC(dmp, struct dm);
+ BU_ALLOC(dmp->i, struct dm_impl);
+
+ *dmp->i = dm_wgl_impl; /* struct copy */
+ dmp->i->dm_interp = interp;
+ dmp->i->dm_light = 1;
+
+ BU_ALLOC(dmp->i->dm_vars.pub_vars, struct dm_wglvars);
+ BU_ALLOC(dmp->i->dm_vars.priv_vars, struct wgl_vars);
+
+ dmp->i->dm_get_internal(dmp);
+ mvars = (struct modifiable_ogl_vars *)dmp->i->m_vars;
+
+ dmp->i->dm_vp = &default_viewscale;
+
+ bu_vls_init(&dmp->i->dm_pathName);
+ bu_vls_init(&dmp->i->dm_tkName);
+ bu_vls_init(&dmp->i->dm_dName);
+
+ dm_processOptions(dmp, &init_proc_vls, --argc, ++argv);
+
+ if (bu_vls_strlen(&dmp->i->dm_pathName) == 0)
+ bu_vls_printf(&dmp->i->dm_pathName, ".dm_wgl%d", count);
+ ++count;
+
+ if (bu_vls_strlen(&dmp->i->dm_dName) == 0) {
+ char *dp;
+
+ dp = getenv("DISPLAY");
+ if (dp)
+ bu_vls_strcpy(&dmp->i->dm_dName, dp);
+ else
+ bu_vls_strcpy(&dmp->i->dm_dName, ":0.0");
+ }
+ if (bu_vls_strlen(&init_proc_vls) == 0)
+ bu_vls_strcpy(&init_proc_vls, "bind_dm");
+
+ /* initialize dm specific variables */
+ ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->devmotionnotify =
LASTEvent;
+ ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->devbuttonpress =
LASTEvent;
+ ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->devbuttonrelease =
LASTEvent;
+ dmp->i->dm_aspect = 1.0;
+
+ /* initialize modifiable variables */
+ mvars->rgb = 1;
+ mvars->doublebuffer = 1;
+ mvars->fastfog = 1;
+ mvars->fogdensity = 1.0;
+ mvars->lighting_on = dmp->i->dm_light;
+ mvars->zbuffer_on = dmp->i->dm_zbuffer;
+ mvars->zclipping_on = dmp->i->dm_zclip;
+ mvars->debug = dmp->i->dm_debugLevel;
+ mvars->bound = dmp->i->dm_bound;
+ mvars->boundFlag = dmp->i->dm_boundFlag;
+
+ /* this is important so that wgl_configureWin knows to set the font */
+ ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->fontstruct = NULL;
+
+ if (dmp->i->dm_width == 0) {
+ dmp->i->dm_width = GetSystemMetrics(SM_CXSCREEN) - 30;
+ ++make_square;
+ }
+ if (dmp->i->dm_height == 0) {
+ dmp->i->dm_height = GetSystemMetrics(SM_CYSCREEN) - 30;
+ ++make_square;
+ }
+
+ if (make_square > 0) {
+ /* Make window square */
+ if (dmp->i->dm_height <
+ dmp->i->dm_width)
+ dmp->i->dm_width =
+ dmp->i->dm_height;
+ else
+ dmp->i->dm_height =
+ dmp->i->dm_width;
+ }
+
+ if (dmp->i->dm_top) {
+ /* Make xtkwin a toplevel window */
+ Tcl_DString ds;
+
+ Tcl_DStringInit(&ds);
+ Tcl_DStringAppend(&ds, "toplevel ", -1);
+ Tcl_DStringAppend(&ds, bu_vls_addr(&dmp->i->dm_pathName), -1);
+ Tcl_DStringAppend(&ds, "; wm deiconify ", -1);
+ Tcl_DStringAppend(&ds, bu_vls_addr(&dmp->i->dm_pathName), -1);
+ if (Tcl_Eval(interp, Tcl_DStringValue(&ds)) != BRLCAD_OK) {
+ Tcl_DStringFree(&ds);
+ return DM_NULL;
+ }
+ ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin =
+ Tk_NameToWindow(interp,
bu_vls_addr(&dmp->i->dm_pathName), tkwin);
+ Tcl_DStringFree(&ds);
+ ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->top = ((struct
dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin;
+ }
+ else {
+ char *cp;
+
+ cp = strrchr(bu_vls_addr(&dmp->i->dm_pathName), (int)'.');
+ if (cp == bu_vls_addr(&dmp->i->dm_pathName)) {
+ ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->top =
tkwin;
+ }
+ else {
+ struct bu_vls top_vls = BU_VLS_INIT_ZERO;
+
+ bu_vls_strncpy(&top_vls, (const char
*)bu_vls_addr(&dmp->i->dm_pathName), cp - bu_vls_addr(&dmp->i->dm_pathName));
+
+ ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->top =
+ Tk_NameToWindow(interp, bu_vls_addr(&top_vls),
tkwin);
+ bu_vls_free(&top_vls);
+ }
+
+ /* Make xtkwin an embedded window */
+ ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin =
+ Tk_CreateWindow(interp, ((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->top,
+ cp + 1, (char *)NULL);
+ }
+
+ if (((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin == NULL) {
+ bu_log("open_gl: Failed to open %s\n",
bu_vls_addr(&dmp->i->dm_pathName));
+ bu_vls_free(&init_proc_vls);
+ (void)wgl_close(dmp);
+ return DM_NULL;
+ }
+
+ bu_vls_printf(&dmp->i->dm_tkName, "%s",
+ (char *)Tk_Name(((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->xtkwin));
+
+ bu_vls_printf(&str, "_init_dm %s %s\n",
+ bu_vls_addr(&init_proc_vls),
+ bu_vls_addr(&dmp->i->dm_pathName));
+
+ if (Tcl_Eval(interp, bu_vls_addr(&str)) == BRLCAD_ERROR) {
+ bu_log("open_wgl: _init_dm failed\n");
+ bu_vls_free(&init_proc_vls);
+ bu_vls_free(&str);
+ (void)wgl_close(dmp);
+ return DM_NULL;
+ }
+
+ bu_vls_free(&init_proc_vls);
+ bu_vls_free(&str);
+
+ ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->dpy =
+ Tk_Display(((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->top);
+
+ /* make sure there really is a display before proceeding. */
+ if (!((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->dpy) {
+ (void)wgl_close(dmp);
+ return DM_NULL;
+ }
+
+ Tk_GeometryRequest(((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->xtkwin,
+ dmp->i->dm_width,
+ dmp->i->dm_height);
+
+ Tk_MakeWindowExist(((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->xtkwin);
+
+ ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->win =
+ Tk_WindowId(((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->xtkwin);
+ dmp->i->dm_id = ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->win;
+
+ hwnd = TkWinGetHWND(((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->win);
+ hdc = GetDC(hwnd);
+ ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->hdc = hdc;
+
+ gotvisual = wgl_choose_visual(dmp, ((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->xtkwin);
+ if (!gotvisual) {
+ bu_log("wgl_open: Can't get an appropriate visual.\n");
+ (void)wgl_close(dmp);
+ return DM_NULL;
+ }
+
+ ((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->depth = mvars->depth;
+
+ /* open GLX context */
+ if ((((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->glxc =
+ wglCreateContext(((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->hdc)) == NULL) {
+ bu_log("wgl_open: couldn't create glXContext.\n");
+ (void)wgl_close(dmp);
+ return DM_NULL;
+ }
+
+ if (!wglMakeCurrent(((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->hdc,
+ ((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->glxc)) {
+ bu_log("wgl_open: couldn't make context current\n");
+ (void)wgl_close(dmp);
+ return DM_NULL;
+ }
+
+ /* display list (fontOffset + char) will display a given ASCII char */
+ if ((((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->fontOffset =
glGenLists(128)) == 0) {
+ bu_log("wgl_open: couldn't make display lists for font.\n");
+ (void)wgl_close(dmp);
+ return DM_NULL;
+ }
+
+ /* This is the applications display list offset */
+ dmp->i->dm_displaylist = ((struct wgl_vars
*)dmp->i->dm_vars.priv_vars)->fontOffset + 128;
+
+ wgl_setBGColor(dmp, 0, 0, 0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ if (mvars->doublebuffer)
+ glDrawBuffer(GL_BACK);
+ else
+ glDrawBuffer(GL_FRONT);
+
+ /* do viewport, ortho commands and initialize font */
+ (void)wgl_configureWin_guts(dmp, 1);
+
+ /* Lines will be solid when stippling disabled, dashed when enabled*/
+ glLineStipple(1, 0xCF33);
+ glDisable(GL_LINE_STIPPLE);
+
+ backgnd[0] = backgnd[1] = backgnd[2] = backgnd[3] = 0.0;
+ glFogi(GL_FOG_MODE, GL_LINEAR);
+ glFogf(GL_FOG_START, 0.0);
+ glFogf(GL_FOG_END, 2.0);
+ glFogfv(GL_FOG_COLOR, backgnd);
+
+ /*XXX Need to do something about VIEWFACTOR */
+ glFogf(GL_FOG_DENSITY, VIEWFACTOR);
+
+ /* Initialize matrices */
+ /* Leave it in model_view mode normally */
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-xlim_view, xlim_view, -ylim_view, ylim_view, 0.0, 2.0);
+ glGetDoublev(GL_PROJECTION_MATRIX, ((struct wgl_vars
*)dmp->i->dm_vars.priv_vars)->faceplate_mat);
+ glPushMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glPushMatrix();
+ glLoadIdentity();
+ ((struct wgl_vars *)dmp->i->dm_vars.priv_vars)->face_flag = 1; /*
faceplate matrix is on top of stack */
+
+ wgl_setZBuffer(dmp, dmp->i->dm_zbuffer);
+ wgl_setLight(dmp, dmp->i->dm_light);
+
+ if (!wglMakeCurrent((HDC)NULL, (HGLRC)NULL)) {
+ LPVOID buf;
+
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ GetLastError(),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR)&buf,
+ 0,
+ NULL);
+ bu_log("wgl_drawBegin: Couldn't release the current
context.\n");
+ bu_log("wgl_drawBegin: %s", buf);
+ LocalFree(buf);
+
+ return DM_NULL;
+ }
+
+ Tk_MapWindow(((struct dm_wglvars *)dmp->i->dm_vars.pub_vars)->xtkwin);
+
+ Tk_CreateEventHandler(((struct dm_wglvars
*)dmp->i->dm_vars.pub_vars)->xtkwin, VisibilityChangeMask, WGLEventProc,
(ClientData)dmp);
+
+ return dmp;
+}
+
struct dm dm_wgl = { &dm_wgl_impl };
#ifdef DM_PLUGIN
Modified: brlcad/branches/dm-fb-merge/src/libdm/wgl/if_wgl.c
===================================================================
--- brlcad/branches/dm-fb-merge/src/libdm/wgl/if_wgl.c 2020-04-22 15:12:27 UTC
(rev 75537)
+++ brlcad/branches/dm-fb-merge/src/libdm/wgl/if_wgl.c 2020-04-22 15:20:50 UTC
(rev 75538)
@@ -71,7 +71,6 @@
HIDDEN int wgl_getmem(struct fb *ifp);
HIDDEN void backbuffer_to_screen(struct fb *ifp, int one_y);
HIDDEN void wgl_cminit(struct fb *ifp);
-HIDDEN int wgl_choose_visual(struct fb *ifp);
HIDDEN int is_linear_cmap(struct fb *ifp);
HIDDEN int wgl_nwindows = 0; /* number of open windows */
@@ -460,8 +459,77 @@
return 1;
}
+/*
+ * Select an appropriate visual, and set flags.
+ *
+ * The user requires support for:
+ * -OpenGL rendering in RGBA mode
+ *
+ * The user may desire support for:
+ * -a single-buffered OpenGL context
+ * -a double-buffered OpenGL context
+ * -hardware colormapping (DirectColor)
+ *
+ * We first try to satisfy all requirements and desires. If that
+ * fails, we remove the desires one at a time until we succeed or
+ * until only requirements are left. If at any stage more than one
+ * visual meets the current criteria, the visual with the greatest
+ * depth is chosen.
+ *
+ * The following flags are set:
+ * WIN(ifp)->mi_doublebuffer
+ * WGL(ifp)->soft_cmap_flag
+ *
+ * Return 0 on failure.
+ */
+static int
+wgl_choose_visual(struct fb *ifp)
+{
+ int iPixelFormat;
+ PIXELFORMATDESCRIPTOR pfd;
+ BOOL good;
-HIDDEN int
+ iPixelFormat = GetPixelFormat(WGL(ifp)->hdc);
+ pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
+ pfd.nVersion = 1;
+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER | PFD_TYPE_RGBA | PFD_STEREO;
+ pfd.iPixelType = PFD_TYPE_RGBA;
+ pfd.cColorBits = 24;
+ pfd.cRedBits = 0;
+ pfd.cRedShift = 0;
+ pfd.cGreenBits = 0;
+ pfd.cGreenShift = 0;
+ pfd.cBlueBits = 0;
+ pfd.cBlueShift = 0;
+ pfd.cAlphaBits = 0;
+ pfd.cAlphaShift = 0;
+ pfd.cAccumBits = 0;
+ pfd.cAccumRedBits = 0;
+ pfd.cAccumGreenBits = 0;
+ pfd.cAccumBlueBits = 0;
+ pfd.cAccumAlphaBits = 0;
+ pfd.cDepthBits = 32;
+ pfd.cStencilBits = 0;
+ pfd.cAuxBuffers = 0;
+ pfd.iLayerType = PFD_MAIN_PLANE;
+ pfd.bReserved = 0;
+ pfd.dwLayerMask = 0;
+ pfd.dwVisibleMask = 0;
+ pfd.dwDamageMask = 0;
+
+ iPixelFormat = ChoosePixelFormat(WGL(ifp)->hdc, &pfd);
+ good = SetPixelFormat(WGL(ifp)->hdc, iPixelFormat, &pfd);
+
+ WIN(ifp)->mi_doublebuffer = 1;
+ WGL(ifp)->soft_cmap_flag = 1;
+
+ if (good)
+ return 1;
+ return 0;
+}
+
+
+static int
wgl_open(struct fb *ifp, const char *file, int width, int height)
{
static char title[128];
@@ -825,7 +893,7 @@
}
-HIDDEN int
+static int
wgl_close(struct fb *ifp)
{
@@ -1867,76 +1935,8 @@
}
-/*
- * Select an appropriate visual, and set flags.
- *
- * The user requires support for:
- * -OpenGL rendering in RGBA mode
- *
- * The user may desire support for:
- * -a single-buffered OpenGL context
- * -a double-buffered OpenGL context
- * -hardware colormapping (DirectColor)
- *
- * We first try to satisfy all requirements and desires. If that
- * fails, we remove the desires one at a time until we succeed or
- * until only requirements are left. If at any stage more than one
- * visual meets the current criteria, the visual with the greatest
- * depth is chosen.
- *
- * The following flags are set:
- * WIN(ifp)->mi_doublebuffer
- * WGL(ifp)->soft_cmap_flag
- *
- * Return 0 on failure.
- */
-HIDDEN int
-wgl_choose_visual(struct fb *ifp)
-{
- int iPixelFormat;
- PIXELFORMATDESCRIPTOR pfd;
- BOOL good;
- iPixelFormat = GetPixelFormat(WGL(ifp)->hdc);
- pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
- pfd.nVersion = 1;
- pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER
| PFD_TYPE_RGBA | PFD_STEREO;
- pfd.iPixelType = PFD_TYPE_RGBA;
- pfd.cColorBits = 24;
- pfd.cRedBits = 0;
- pfd.cRedShift = 0;
- pfd.cGreenBits = 0;
- pfd.cGreenShift = 0;
- pfd.cBlueBits = 0;
- pfd.cBlueShift = 0;
- pfd.cAlphaBits = 0;
- pfd.cAlphaShift = 0;
- pfd.cAccumBits = 0;
- pfd.cAccumRedBits = 0;
- pfd.cAccumGreenBits = 0;
- pfd.cAccumBlueBits = 0;
- pfd.cAccumAlphaBits = 0;
- pfd.cDepthBits = 32;
- pfd.cStencilBits = 0;
- pfd.cAuxBuffers = 0;
- pfd.iLayerType = PFD_MAIN_PLANE;
- pfd.bReserved = 0;
- pfd.dwLayerMask = 0;
- pfd.dwVisibleMask = 0;
- pfd.dwDamageMask = 0;
- iPixelFormat = ChoosePixelFormat(WGL(ifp)->hdc, &pfd);
- good = SetPixelFormat(WGL(ifp)->hdc, iPixelFormat, &pfd);
-
- WIN(ifp)->mi_doublebuffer = 1;
- WGL(ifp)->soft_cmap_flag = 1;
-
- if (good)
- return 1;
- return 0;
-}
-
-
int
wgl_refresh(struct fb *ifp,
int x,
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits