Skip to content

Commit

Permalink
OpenGL-based 2D Graphics implementation
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 27, 2024
1 parent 7163279 commit 61e7fa4
Show file tree
Hide file tree
Showing 22 changed files with 2,918 additions and 765 deletions.
2 changes: 1 addition & 1 deletion src/common/uconsole.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ FILE *OpenConsole()
*/
if ((hp = alclist(0, MinListSlots)) == NULL) return NULL;

ConsoleBinding = wopen(ConsoleTitle, hp, attrs, 3, &eindx,0);
ConsoleBinding = wopen(ConsoleTitle, hp, attrs, 3, &eindx,0,0);
if ( !(ConsoleFlags & StdInRedirect ))
k_input.fd.fp = ConsoleBinding;
if ( !(ConsoleFlags & StdOutRedirect ))
Expand Down
1 change: 1 addition & 0 deletions src/h/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ Deliberate Syntax Error

#if HAVE_LIBGL
#define Graphics3D 1
#define GraphicsGL 1
#else /* HAVE_LIBGL */
#if HAVE_FTGL
#undef HAVE_FTGL
Expand Down
4 changes: 4 additions & 0 deletions src/h/feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@
Feature(1, "_3D_GRAPHICS", "3D graphics")
#endif /* Graphics */

#ifdef GraphicsGL
Feature(1, "_GL_GRAPHICS", "OpenGL graphics")
#endif /* GraphicsGL */

#ifdef XWindows
Feature(1, "_X_WINDOW_SYSTEM", "X Windows")
#endif /* XWindows */
Expand Down
140 changes: 101 additions & 39 deletions src/h/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "../h/mswin.h"
#endif /* MSWindows */

#if Graphics3D
#if Graphics3D || GraphicsGL
#if HAVE_LIBGL
#include "../h/opengl.h"
#else /* HAVE_LIBGL */
Expand Down Expand Up @@ -80,7 +80,7 @@
#define GL3D_ENDMARK REDRAW_ENDMARK
#define GL3D_MESHMODE REDRAW_MESHMODE

#endif /* Graphics3D */
#endif /* Graphics3D || GraphicsGL */

#ifndef MAXXOBJS
#define MAXXOBJS 256
Expand Down Expand Up @@ -250,13 +250,20 @@ typedef struct _wfont {
#endif /* HAVE_XFT */
#endif /* XWindows */
#ifdef MSWindows
char * name; /* name for WAttrib and fontsearch */
char *name; /* name for WAttrib and fontsearch */
HFONT font;
LONG ascent;
LONG descent;
LONG charwidth;
LONG height;
#endif /* MSWindows */
#ifdef GraphicsGL
#if HAVE_LIBFREETYPE
FT_Library library;
FT_Face face;
#endif /* HAVE_LIBFREETYPE */
struct fontsymbol chars[256];
#endif /* GraphicsGL */
} wfont, *wfp;

/*
Expand Down Expand Up @@ -289,6 +296,9 @@ struct imgdata { /* image loaded from a file */

struct imgmem {
int x, y, width, height;
#ifdef GraphicsGL
unsigned short *pixmap;
#endif /* GraphicsGL */
#ifdef XWindows
XImage *im;
#endif /* XWindows */
Expand Down Expand Up @@ -341,7 +351,8 @@ typedef struct _wtexture {
*/
typedef struct _wdisplay {
int refcount;
int serial; /* serial # */
int serial; /* serial # */
int numFonts;

#ifdef MSWindows
char name[MAXDISPLAYNAME];
Expand All @@ -352,26 +363,40 @@ typedef struct _wdisplay {
Display * display;
GC icongc;
Colormap cmap;
#ifdef GraphicsGL
int nConfigs;
GLXFBConfig *configs;
XVisualInfo *vis;
GLXContext sharedCtx; /* shared context for texture sharing */
GLXContext currCtx; /* keeps track of current context */
#endif /* GraphicsGL */
#ifdef HAVE_XFT
XFontStruct *xfont;
#endif /* HAVE_XFT */
#ifdef Graphics3D
XVisualInfo *vis;
#endif /* Graphics3D */
Cursor cursors[NUMCURSORSYMS];
int numColors; /* allocated color info */
int sizColors; /* # elements of alloc. color array */
int numColors; /* allocated color info */
int sizColors; /* # elements of alloc. color array */
struct wcolor *colors;
int screen;
int numFonts;
wfp fonts;
int buckets[16384]; /* hash table for quicker lookups */
int buckets[16384]; /* hash table for quicker lookups */
#endif /* XWindows */
#ifdef GraphicsGL
unsigned int stdPatTexIds[16]; /* array of std pattern texture ids */
unsigned int *texIds;
unsigned int numTexIds;
unsigned int maxTexIds;
wfp glfonts; /* For OpenGL & X11 to live happily together */
int numMclrs;
int muteIdCount;
struct color *mclrs;
#endif /* GraphicsGL */
#ifdef Graphics3D
int ntextures; /* # textures actually used */
int nalced; /* number allocated */
wtp stex;
int maxstex;

int ntextures; /* # textures actually used */
int nalced; /* number allocated */
wtp stex;
int maxstex;
#endif /* Graphics3D */
double gamma;
struct _wdisplay *previous, *next;
Expand All @@ -397,13 +422,24 @@ typedef struct _wcontext {
double gamma; /* gamma correction value */
int bits; /* context bits */

#ifdef GraphicsGL
struct color glfg, glbg;
int reverse;
double alpha;
int linestyle;
int linewidth;
int leading; /* inter-line leading */
#endif /* GraphicsGL */

wdp display;
#ifdef XWindows
GC gc; /* X graphics context */
GC gc; /* X graphics context */
int fg, bg;
#ifndef GraphicsGL
int linestyle;
int linewidth;
int leading; /* inter-line leading */
#endif /* GraphicsGL */
#endif /* XWindows */
#ifdef MSWindows
LOGPEN pen;
Expand All @@ -414,22 +450,16 @@ typedef struct _wcontext {
HBITMAP pattern;
SysColor fg, bg;
char *fgname, *bgname;
#ifdef GraphicsGL
int bkmode;
#else /* GraphicsGL */
int leading, bkmode;
#endif /* GraphicsGL */
#endif /* MSWindows*/

#ifdef Graphics3D

#if HAVE_LIBGL
#ifdef XWindows
GLXContext ctx; /* context for "gl" windows */
#endif /* XWindows */
#ifdef MSWindows
HGLRC ctx;
#endif /* MSWindows */
#endif /* HAVE_LIBGL */

int dim; /* # of coordinates per vertex */
int is_3D; /* flag for 3D windows */
int rendermode; /* flag for 3D windows */
char buffermode; /* 3D buffering flag */
char meshmode; /* fillpolygon mesh mode */

Expand All @@ -445,23 +475,17 @@ typedef struct _wcontext {
int selectionnamelistsize; /* current available size */
int app_use_selection3D; /* the application uses 3D selection */

double eyeupx, eyeupy, eyeupz; /* eye up vector */
double eyedirx, eyediry, eyedirz; /* eye direction vector */
double eyeposx, eyeposy, eyeposz; /* eye position */

double fov; /* field of view angle */

struct b_realarray *normals; /* vertex normals data */

int normode; /* normals on, off or auto */
int numnormals; /* # of normals used */
int numnormals; /* # of normals used */

int autogen; /* flag to automatically generate texture coordinate */
int texmode; /* textures on or off */
int texmode; /* textures on or off */
int numtexcoords; /* # of texture coordinates used */
struct b_realarray *texcoords; /* texture coordinates */
struct b_realarray *texcoords; /* texture coordinates */

int curtexture; /* subscript of current texture */
int curtexture; /* subscript of current texture */
#endif /* Graphics3D */
} wcontext, *wcp;

Expand Down Expand Up @@ -511,6 +535,10 @@ typedef struct _wstate {
#ifdef Graphics3D
int type;
int texindex;
double eyeupx, eyeupy, eyeupz; /* eye up vector */
double eyedirx, eyediry, eyedirz; /* eye direction vector */
double eyeposx, eyeposy, eyeposz; /* eye position */
double fov; /* field of view angle */
#endif /* Graphics3D */

int inputmask; /* user input mask */
Expand Down Expand Up @@ -538,7 +566,31 @@ typedef struct _wstate {
struct descrip filep, listp; /* icon values for this window */
struct wbind_list *children;
struct _wbinding *parent;
wdp display;
wdp display;

#ifdef GraphicsGL
#ifdef XWindows
GLXContext ctx; /* context for "gl" windows */
GLXPbuffer pbuf; /* offscreen render surface */
#endif /* XWindows */
#ifdef MSWindows
HGLRC ctx;
#endif /* MSWindows */

struct _wcontext wcrender, wcdef; /* render & default/init contexts */
int lastwcserial; /* remembers the last context used */
unsigned char updateRC; /* render context flag, default:0 */
unsigned char initAttrs; /* initialize attribs falg, default:0 */
unsigned char resize; /* window resize flag */
unsigned char is_gl; /* flag for coexisting with Xlib */
unsigned char dx_flag, dy_flag;
unsigned char stencil_mask; /* bitmask for stencil buffer */
int rendermode; /* 2D/3D rendering attrib */
int projection; /* viewing volume projection attrib */
double camwidth; /* viewing volume cam width attrib */
#endif /* GraphicsGL */


#ifdef XWindows
Window win; /* X window */
Pixmap pix; /* current screen state */
Expand Down Expand Up @@ -584,6 +636,12 @@ typedef struct _wstate {
int is_3D; /* flag for 3D windows */
struct descrip funclist; /* descriptor to hold list of 3d functions */
#endif /* Graphics3D */
#ifdef GraphicsGL
struct descrip funclist2d; /* descriptor to hold list of 2d functions */
unsigned char redraw_flag;
unsigned char busy_flag;
unsigned char buffermode;
#endif /* GraphicsGL */
int no; /* new field added for child windows */
} wstate, *wsp;

Expand Down Expand Up @@ -707,7 +765,11 @@ struct wbind_list {
#define A_GLVERSION 86
#define A_GLVENDOR 87
#define A_GLRENDERER 88
#define A_ALPHA 89
#define A_RENDERMODE 90
#define A_PROJECTION 91
#define A_CAMWIDTH 92

#define NUMATTRIBS 88
#define NUMATTRIBS 92

#define XICONSLEEP 20 /* milliseconds */
11 changes: 9 additions & 2 deletions src/h/grttin.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,13 @@ typedef int va_list, siptr;
typedef int XRectangle, XPoint, XSegment, XArc, SysColor, LinearColor;
typedef int LONG, SHORT;

#ifdef GraphicsGL
#ifdef HAVE_LIBFREETYPE
typedef int FT_Library, FT_Face, FT_CharMap, FT_GlyphSlot, FT_Bitmap;
typedef int FT_Matrix, FT_Vector;
#endif /* HAVE_LIBFREETYPE */
#endif /* GraphicsGL */

#ifdef XWindows
typedef int Atom, Time, XSelectionEvent, XErrorEvent, XErrorHandler;
typedef int XGCValues, XColor, XFontStruct, XWindowAttributes, XEvent;
Expand Down Expand Up @@ -546,7 +553,7 @@ typedef int LOGPEN, LOGBRUSH, LPVOID, MCI_PLAY_PARMS, MCIDEVICEID;
*/
#begdef EnsureWindow3D(w)
{
if (w->context->is_3D == 0) {
if (w->context->rendermode == UGL2D) {
if (warg == 0)
runerr(150, kywd_xwin[XKey_Window]);
else
Expand Down Expand Up @@ -593,7 +600,7 @@ typedef int LOGPEN, LOGBRUSH, LPVOID, MCI_PLAY_PARMS, MCIDEVICEID;
typedef int GLdouble, GLint, GLfloat, GLsizei, Status, GLboolean, GLenum;
typedef int XWindowChanges, XStandardColormap, XMappingEvent, _GLUfuncptr;
typedef int GLXContext, GLUquadricObj, GLUtesselator, GLubyte, GLuint;
typedef int GLXFBConfig, GLXWindow;
typedef int GLXFBConfig, GLXWindow, GLXPixmap, GLXPbuffer;
#ifdef MSWindows
typedef int HGLRC, PIXELFORMATDESCRIPTOR;
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/h/rmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
#define Fs_Pty 040000000 /* pty */
#endif

#ifdef GraphicsGL
#define Fs_WinGL2D 0100000000 /* for OpenGL 2D window */
#endif /* GraphicsGL */

/*
* Thread status flags in status field of coexpr blocks.
Expand Down
Loading

0 comments on commit 61e7fa4

Please sign in to comment.