Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenGL-based 2D Graphics implementation #464

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain mingw-w64-ucrt-x86
- Install the optional libraries for a full build (Unicon will build without them but some features
will be absent).
```
pacman -S mingw-w64-ucrt-x86_64-openssl mingw-w64-ucrt-x86_64-libpng mingw-w64-ucrt-x86_64-libjpeg-turbo
pacman -S mingw-w64-ucrt-x86_64-openssl mingw-w64-ucrt-x86_64-libpng
pacman -S mingw-w64-ucrt-x86_64-libjpeg-turbo mingw-w64-ucrt-x86_64-freetype
```

- Clone the Unicon repository:
Expand All @@ -149,7 +150,7 @@ git clone --config core.autocrlf=input https://github.com/uniconproject/unicon

- Configure Unicon:
```
./configure --build=x86_64-w64-mingw32
./configure --build=x86_64-w64-mingw32 CPPFLAGS=-I/ucrt64/include/freetype2
```
The option `x86_64-w64-mingw32` ensures the build is 64-bit. After the script finishes do:
```
Expand Down
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/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: 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
10 changes: 6 additions & 4 deletions src/h/opengl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

//#define GL2D_DRAWARRAYS 1 /* Punt this off as a TODO item */

#define GL2D_DEBUG

#ifdef GL2D_DEBUG
#define glprintf(s, ...) printf(stderr,s, ##__VA_ARGS__)
#define glprintf(s, ...) fprintf(stderr, "%s:%s:%d: " s, __FILE__, __func__, __LINE__, ##__VA_ARGS__)
#else /* GL2D_DEBUG */
#define glprintf(s, ...)
#endif /* GL2D_DEBUG */
Expand Down Expand Up @@ -111,15 +113,15 @@
#define GL2D_DRAWOP_COPY GL_COPY
#define GL2D_DRAWOP_REVERSE GL_XOR


/*
* Structures
*/

/*
* For a linked list color structure
*/
typedef struct color {
typedef struct color
{
char name[6+MAXCOLORNAME];
unsigned short r, g, b, a;
/* for referencing a mutable color (negative) */
Expand All @@ -128,7 +130,7 @@ typedef struct color {
unsigned long c; /* X11 color handle */
#endif /* XWindows */
struct color *prev, *next;
} *clrp;
} *clrp;

/*
* Object for storing font characters (uses textures)
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
Loading