Skip to content

Commit

Permalink
Allow GL graphics without FreeType
Browse files Browse the repository at this point in the history
Signed-off-by: Jafar Al-Gharaibeh <[email protected]>
  • Loading branch information
Jafaral committed May 25, 2024
1 parent d8a7c82 commit 2d14818
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 81 deletions.
1 change: 1 addition & 0 deletions src/h/auto.in
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
/* Define to 1 if you lib freetype */
#undef HAVE_LIBFREETYPE


/* Define to 1 if you lib ftgl */
#undef HAVE_LIBFTGL

Expand Down
1 change: 0 additions & 1 deletion src/h/rproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,6 @@ int checkOpenConsole( FILE *w, char *s );
/*
* Windowing functions (platform-specific)
*/
wcp gl_alc_context(wbp w);
wdp gl_alc_display(char *s);
wdp gl_alc_display_font(wdp wd);
wsp gl_alc_winstate();
Expand Down
11 changes: 0 additions & 11 deletions src/runtime/rmswin.ri
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,6 @@ FILE *wopen(char *name, struct b_list *lp, dptr attr, int n, int *err_index, int
* some attributes of the display and window are used in the context
*/

#ifdef GraphicsGL
if (is_gl) {
if ((wc = w->context = gl_alc_context(w)) == NULL) {
*err_index = -2;
free_binding(w);
set_errortext(145);
return NULL;
}
}
else
#endif /* GraphicsGL */
if ((wc = w->context = alc_context(w)) == NULL) {
*err_index = -2;
free_binding(w);
Expand Down
52 changes: 10 additions & 42 deletions src/runtime/ropengl2d.ri
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,13 @@ int init_2dcanvas(wbp w)
*/
if (glIsEnabled(GL_STENCIL_TEST) == GL_FALSE)
glEnable(GL_STENCIL_TEST);
setpattern2d(w, NULL);

/*
* FIXME: setpattern2d() seems to casue issues with 3D windows
* Disbale for now
*/
if (!ws->is_3D)
setpattern2d(w, NULL);

/*
* Clipping
Expand Down Expand Up @@ -1402,18 +1408,12 @@ int init_2dcontext(wcp wc)
/* default fg is black */
SetColor(wc->glfg, 0, 0, 0, 65535, 0);
sprintf(wc->glfg.name,"black");
#ifdef XWindows
wc->glfg.c = wd->colors[0].c;
wd->colors[0].refcount++;
#endif /* XWindows */


/* default bg is white */
SetColor(wc->glbg, 65535, 65535, 65535, 65535, 0);
sprintf(wc->glbg.name,"white");
#ifdef XWindows
wc->glbg.c = wd->colors[1].c;
wd->colors[1].refcount++;
#endif /* XWindows */


wc->rgbmode = 2;
wc->gamma = wd->gamma;
Expand All @@ -1429,16 +1429,6 @@ int init_2dcontext(wcp wc)
glprintf("fonts not allocated\n");
wc->font = NULL;
wc->leading = 0;
wc->font = (wfp)alloc(sizeof (struct _wfont));
wc->font->name = salloc("fixed");
wc->font->font = CreateFont(16,0,0,0,FW_NORMAL,0,0,0,
((MAXBYTESPERCHAR==1)?ANSI_CHARSET:DEFAULT_CHARSET),
OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN,
NULL);

wc->font->charwidth = 8; /* looks like a bug */
wc->leading = 16;
}

/* drawing */
Expand Down Expand Up @@ -7319,7 +7309,7 @@ wcp gl_clone_context(wbp w)
wcp wc, rv;

wc = w->context;
Protect(rv = gl_alc_context(w), return NULL);
Protect(rv = alc_context(w), return NULL);

copy_2dcontext(rv, wc);
copy_3dcontext(wc, rv);
Expand Down Expand Up @@ -7495,28 +7485,6 @@ int gl_wputc(int ci, wbp w)
*******************************************************/




/*
* allocate a context. Can't be called until w has a display and window.
*/
wcp gl_alc_context(wbp w)
{
wcp wc;

wc = alc_context(w); /* platform-specific init */
if (!wc) return NULL;

/* set defaults here */
init_2dcontext(wc);
init_3dcontext(wc);

return wc;
}




/*
* allocate a display on machine s
*/
Expand Down
7 changes: 1 addition & 6 deletions src/runtime/rwindow.r
Original file line number Diff line number Diff line change
Expand Up @@ -5469,12 +5469,7 @@ char child_window_generic(wbp w, wbp wp, int child_window)
ws = w->window;
ws->display = wd;
CLRTITLEBAR(ws);
#ifdef GraphicsGL
if (w->window->is_gl) {
Protect(w->context = gl_alc_context(w), { free_binding(w); return 0; });
}
else
#endif /* GraphicsGL */

Protect(w->context = alc_context(w), { free_binding(w); return 0; });

wc = w->context;
Expand Down
35 changes: 24 additions & 11 deletions src/runtime/rxrsc.ri
Original file line number Diff line number Diff line change
Expand Up @@ -1209,25 +1209,38 @@ wcp alc_context(wbp w)
wc->serial = ++context_serial;
wc->display = wd;
wd->refcount++;
wc->font = NULL;

#ifdef OpenGL2D
if (!w->window->is_gl)
#endif /* OpenGL2D */
#ifdef GraphicsGL
if (w->window->is_gl) {
init_2dcontext(wc);
init_3dcontext(wc);
wc->glfg.c = wd->colors[0].c;
wd->colors[0].refcount++;
wc->glbg.c = wd->colors[1].c;
wd->colors[1].refcount++;
} else
#endif /* GraphicsGL */
{
wd->colors[0].refcount++;
wc->fg = 0;
wd->colors[1].refcount++;
wc->bg = 1;
wc->font = wd->fonts;
wc->leading = wd->fonts->height;
wc->drawop = GXcopy;
wc->rgbmode = 2;
wc->gamma = wd->gamma;
wc->clipx = wc->clipy = 0;
wc->clipw = wc->cliph = -1;
wc->linewidth = 1;
wc->drawop = GXcopy;
wc->fg = 0;
wc->bg = 1;
wc->rgbmode = 2;
}




/* Ensure we have fonts, even with GLand no FreeType, so alway fall back to the old ways */
if (!wc->font) {
wc->font = wd->fonts;
wc->leading = wd->fonts->height;
}

GRFX_LINK(wc, wcntxts);
return wc;
}
Expand Down
10 changes: 0 additions & 10 deletions src/runtime/rxwin.ri
Original file line number Diff line number Diff line change
Expand Up @@ -1262,16 +1262,6 @@ FILE *wopen(char *name, struct b_list *lp, dptr attr, int n, int *err_index, int
* some attributes of the display and window are used in the context
*/

#ifdef GraphicsGL
if (is_gl) {
if ((wc = w->context = gl_alc_context(w)) == NULL) {
*err_index = -2;
free_binding(w);
return NULL;
}
}
else
#endif /* GraphicsGL */
if ((wc = w->context = alc_context(w)) == NULL) {
*err_index = -2;
free_binding(w);
Expand Down

0 comments on commit 2d14818

Please sign in to comment.