2013-07-28 22:08:34 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Helper functions that ultimately draw stuff with gl.
|
|
|
|
//
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
|
|
|
//-----------------------------------------------------------------------------
|
2015-11-05 19:39:27 +00:00
|
|
|
#include <zlib.h>
|
2008-04-11 11:13:47 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
namespace SolveSpace {
|
|
|
|
|
2016-02-05 09:28:29 +00:00
|
|
|
// A vector font.
|
|
|
|
#include "generated/vectorfont.table.h"
|
2008-04-11 11:13:47 +00:00
|
|
|
|
2010-04-26 07:52:49 +00:00
|
|
|
// A bitmap font.
|
2015-11-04 07:24:59 +00:00
|
|
|
#include "generated/bitmapfont.table.h"
|
2010-04-26 07:52:49 +00:00
|
|
|
|
2008-04-19 11:09:47 +00:00
|
|
|
static bool ColorLocked;
|
2008-06-17 19:12:25 +00:00
|
|
|
static bool DepthOffsetLocked;
|
2008-04-19 11:09:47 +00:00
|
|
|
|
2016-02-05 09:28:29 +00:00
|
|
|
static const VectorGlyph &GetVectorGlyph(char32_t chr) {
|
|
|
|
int first = 0;
|
|
|
|
int last = sizeof(VectorFont) / sizeof(VectorGlyph);
|
|
|
|
while(first <= last) {
|
|
|
|
int mid = (first + last) / 2;
|
|
|
|
char32_t midChr = VectorFont[mid].character;
|
|
|
|
if(midChr > chr) {
|
|
|
|
last = mid - 1; // and first stays the same
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(midChr < chr) {
|
|
|
|
first = mid + 1; // and last stays the same
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return VectorFont[mid];
|
|
|
|
}
|
|
|
|
return GetVectorGlyph(0xfffd); // replacement character
|
|
|
|
}
|
2008-04-30 08:14:32 +00:00
|
|
|
|
2016-02-05 09:28:29 +00:00
|
|
|
#define FONT_SCALE(h) ((h)/75.0)
|
|
|
|
double ssglStrWidth(const std::string &str, double h)
|
|
|
|
{
|
|
|
|
int width = 0;
|
2016-02-14 20:13:40 +00:00
|
|
|
for(char32_t chr : ReadUTF8(str)) {
|
2016-02-05 09:28:29 +00:00
|
|
|
const VectorGlyph &glyph = GetVectorGlyph(chr);
|
|
|
|
if(glyph.baseCharacter != 0) {
|
|
|
|
const VectorGlyph &baseGlyph = GetVectorGlyph(glyph.baseCharacter);
|
|
|
|
width += max(glyph.width, baseGlyph.width);
|
|
|
|
} else {
|
|
|
|
width += glyph.width;
|
|
|
|
}
|
2008-04-30 08:14:32 +00:00
|
|
|
}
|
2016-02-05 09:28:29 +00:00
|
|
|
return width * FONT_SCALE(h) / SS.GW.scale;
|
2008-05-07 08:19:37 +00:00
|
|
|
}
|
2013-10-22 04:45:06 +00:00
|
|
|
double ssglStrHeight(double h)
|
2010-05-03 05:04:42 +00:00
|
|
|
{
|
2016-02-05 09:28:29 +00:00
|
|
|
// The characters have height ~90, as they appear in the table.
|
|
|
|
return 90.0 * FONT_SCALE(h) / SS.GW.scale;
|
2008-04-30 08:14:32 +00:00
|
|
|
}
|
2016-02-05 09:28:29 +00:00
|
|
|
void ssglWriteTextRefCenter(const std::string &str, double h, Vector t, Vector u, Vector v,
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglLineFn *fn, void *fndata)
|
2008-04-30 08:14:32 +00:00
|
|
|
{
|
2009-07-03 20:55:57 +00:00
|
|
|
u = u.WithMagnitude(1);
|
|
|
|
v = v.WithMagnitude(1);
|
|
|
|
|
2009-09-24 15:52:48 +00:00
|
|
|
double scale = FONT_SCALE(h)/SS.GW.scale;
|
2013-10-22 04:45:06 +00:00
|
|
|
double fh = ssglStrHeight(h);
|
|
|
|
double fw = ssglStrWidth(str, h);
|
2009-07-03 20:55:57 +00:00
|
|
|
|
|
|
|
t = t.Plus(u.ScaledBy(-fw/2));
|
|
|
|
t = t.Plus(v.ScaledBy(-fh/2));
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
// Undo the (+5, +5) offset that ssglWriteText applies.
|
2009-07-03 20:55:57 +00:00
|
|
|
t = t.Plus(u.ScaledBy(-5*scale));
|
|
|
|
t = t.Plus(v.ScaledBy(-5*scale));
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglWriteText(str, h, t, u, v, fn, fndata);
|
2008-04-30 08:14:32 +00:00
|
|
|
}
|
|
|
|
|
2015-03-22 13:39:12 +00:00
|
|
|
void ssglLineWidth(GLfloat width) {
|
|
|
|
// Intel GPUs with Mesa on *nix render thin lines poorly.
|
|
|
|
static bool workaroundChecked, workaroundEnabled;
|
|
|
|
if(!workaroundChecked) {
|
|
|
|
// ssglLineWidth can be called before GL is initialized
|
|
|
|
if(glGetString(GL_VENDOR)) {
|
|
|
|
workaroundChecked = true;
|
|
|
|
if(!strcmp((char*)glGetString(GL_VENDOR), "Intel Open Source Technology Center"))
|
|
|
|
workaroundEnabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-12 05:26:08 +00:00
|
|
|
if(workaroundEnabled && width < 1.6f)
|
|
|
|
width = 1.6f;
|
2015-03-22 13:39:12 +00:00
|
|
|
|
|
|
|
glLineWidth(width);
|
|
|
|
}
|
|
|
|
|
2009-07-03 20:55:57 +00:00
|
|
|
static void LineDrawCallback(void *fndata, Vector a, Vector b)
|
2008-04-11 11:13:47 +00:00
|
|
|
{
|
2015-03-22 13:39:12 +00:00
|
|
|
ssglLineWidth(1);
|
2009-07-03 20:55:57 +00:00
|
|
|
glBegin(GL_LINES);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(a);
|
|
|
|
ssglVertex3v(b);
|
2009-07-03 20:55:57 +00:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2016-02-05 09:28:29 +00:00
|
|
|
int ssglDrawCharacter(const VectorGlyph &glyph, Vector t, Vector o, Vector u, Vector v,
|
|
|
|
double scale, ssglLineFn *fn, void *fndata) {
|
|
|
|
int width = glyph.width;
|
|
|
|
|
|
|
|
if(glyph.baseCharacter != 0) {
|
|
|
|
const VectorGlyph &baseGlyph = GetVectorGlyph(glyph.baseCharacter);
|
|
|
|
int baseWidth = ssglDrawCharacter(baseGlyph, t, o, u, v, scale, fn, fndata);
|
|
|
|
width = max(glyph.width, baseWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
const int8_t *data = glyph.data;
|
|
|
|
bool pen_up = true;
|
|
|
|
Vector prevp;
|
|
|
|
while(true) {
|
|
|
|
int8_t x = *data++;
|
|
|
|
int8_t y = *data++;
|
|
|
|
|
|
|
|
if(x == PEN_UP && y == PEN_UP) {
|
|
|
|
if(pen_up) break;
|
|
|
|
pen_up = true;
|
|
|
|
} else {
|
|
|
|
Vector p = t;
|
|
|
|
p = p.Plus(u.ScaledBy((o.x + x) * scale));
|
|
|
|
p = p.Plus(v.ScaledBy((o.y + y) * scale));
|
|
|
|
if(!pen_up) fn(fndata, prevp, p);
|
|
|
|
prevp = p;
|
|
|
|
pen_up = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ssglWriteText(const std::string &str, double h, Vector t, Vector u, Vector v,
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglLineFn *fn, void *fndata)
|
2009-07-03 20:55:57 +00:00
|
|
|
{
|
|
|
|
if(!fn) fn = LineDrawCallback;
|
|
|
|
u = u.WithMagnitude(1);
|
|
|
|
v = v.WithMagnitude(1);
|
|
|
|
|
2016-02-05 09:28:29 +00:00
|
|
|
double scale = FONT_SCALE(h) / SS.GW.scale;
|
|
|
|
Vector o = { 5.0, 5.0 };
|
2016-02-14 20:13:40 +00:00
|
|
|
for(char32_t chr : ReadUTF8(str)) {
|
2016-02-05 09:28:29 +00:00
|
|
|
const VectorGlyph &glyph = GetVectorGlyph(chr);
|
|
|
|
o.x += ssglDrawCharacter(glyph, t, o, u, v, scale, fn, fndata);
|
2008-04-11 11:13:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
void ssglVertex3v(Vector u)
|
2008-04-11 11:13:47 +00:00
|
|
|
{
|
|
|
|
glVertex3f((GLfloat)u.x, (GLfloat)u.y, (GLfloat)u.z);
|
|
|
|
}
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
void ssglAxisAlignedQuad(double l, double r, double t, double b, bool lone)
|
2010-05-03 05:04:42 +00:00
|
|
|
{
|
2013-09-09 20:05:33 +00:00
|
|
|
if(lone) glBegin(GL_QUADS);
|
2010-05-03 05:04:42 +00:00
|
|
|
glVertex2d(l, t);
|
|
|
|
glVertex2d(l, b);
|
|
|
|
glVertex2d(r, b);
|
|
|
|
glVertex2d(r, t);
|
2013-09-09 20:05:33 +00:00
|
|
|
if(lone) glEnd();
|
2010-05-03 05:04:42 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
void ssglAxisAlignedLineLoop(double l, double r, double t, double b)
|
2010-05-03 05:04:42 +00:00
|
|
|
{
|
|
|
|
glBegin(GL_LINE_LOOP);
|
|
|
|
glVertex2d(l, t);
|
|
|
|
glVertex2d(l, b);
|
|
|
|
glVertex2d(r, b);
|
|
|
|
glVertex2d(r, t);
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2009-09-24 15:52:48 +00:00
|
|
|
static void FatLineEndcap(Vector p, Vector u, Vector v)
|
|
|
|
{
|
|
|
|
// A table of cos and sin of (pi*i/10 + pi/2), as i goes from 0 to 10
|
|
|
|
static const double Circle[11][2] = {
|
|
|
|
{ 0.0000, 1.0000 },
|
|
|
|
{ -0.3090, 0.9511 },
|
|
|
|
{ -0.5878, 0.8090 },
|
|
|
|
{ -0.8090, 0.5878 },
|
|
|
|
{ -0.9511, 0.3090 },
|
|
|
|
{ -1.0000, 0.0000 },
|
|
|
|
{ -0.9511, -0.3090 },
|
|
|
|
{ -0.8090, -0.5878 },
|
|
|
|
{ -0.5878, -0.8090 },
|
|
|
|
{ -0.3090, -0.9511 },
|
|
|
|
{ 0.0000, -1.0000 },
|
|
|
|
};
|
|
|
|
glBegin(GL_TRIANGLE_FAN);
|
|
|
|
for(int i = 0; i <= 10; i++) {
|
|
|
|
double c = Circle[i][0], s = Circle[i][1];
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(p.Plus(u.ScaledBy(c)).Plus(v.ScaledBy(s)));
|
2009-09-24 15:52:48 +00:00
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
void ssglFatLine(Vector a, Vector b, double width)
|
2010-05-03 05:04:42 +00:00
|
|
|
{
|
2009-09-24 15:52:48 +00:00
|
|
|
// The half-width of the line we're drawing.
|
|
|
|
double hw = width / 2;
|
|
|
|
Vector ab = b.Minus(a);
|
|
|
|
Vector gn = (SS.GW.projRight).Cross(SS.GW.projUp);
|
|
|
|
Vector abn = (ab.Cross(gn)).WithMagnitude(1);
|
|
|
|
abn = abn.Minus(gn.ScaledBy(gn.Dot(abn)));
|
|
|
|
// So now abn is normal to the projection of ab into the screen, so the
|
|
|
|
// line will always have constant thickness as the view is rotated.
|
|
|
|
|
|
|
|
abn = abn.WithMagnitude(hw);
|
|
|
|
ab = gn.Cross(abn);
|
|
|
|
ab = ab. WithMagnitude(hw);
|
|
|
|
|
|
|
|
// The body of a line is a quad
|
|
|
|
glBegin(GL_QUADS);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(a.Minus(abn));
|
|
|
|
ssglVertex3v(b.Minus(abn));
|
|
|
|
ssglVertex3v(b.Plus (abn));
|
|
|
|
ssglVertex3v(a.Plus (abn));
|
2009-09-24 15:52:48 +00:00
|
|
|
glEnd();
|
|
|
|
// And the line has two semi-circular end caps.
|
|
|
|
FatLineEndcap(a, ab, abn);
|
|
|
|
FatLineEndcap(b, ab.ScaledBy(-1), abn);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-10 11:54:39 +00:00
|
|
|
void ssglLockColorTo(RgbaColor rgb)
|
2008-04-19 11:09:47 +00:00
|
|
|
{
|
2009-09-17 07:32:36 +00:00
|
|
|
ColorLocked = false;
|
Replaced RGB-color integers with dedicated data structure
RGB colors were represented using a uint32_t with the red, green and blue
values stuffed into the lower three octets (i.e. 0x00BBGGRR), like
Microsoft's COLORREF. This approach did not lend itself to type safety,
however, so this change replaces it with an RgbColor class that provides
the same infomation plus a handful of useful methods to work with it. (Note
that sizeof(RgbColor) == sizeof(uint32_t), so this change should not lead
to memory bloat.)
Some of the new methods/fields replace what were previously macro calls;
e.g. RED(c) is now c.red, REDf(c) is now c.redF(). The .Equals() method is
now used instead of == to compare colors.
RGB colors still need to be represented as packed integers in file I/O and
preferences, so the methods .FromPackedInt() and .ToPackedInt() are
provided. Also implemented are Cnf{Freeze,Thaw}Color(), type-safe wrappers
around Cnf{Freeze,Thaw}Int() that facilitate I/O with preferences.
(Cnf{Freeze,Thaw}Color() are defined outside of the system-dependent code
to minimize the footprint of the latter; because the same can be done with
Cnf{Freeze,Thaw}Bool(), those are also moved out of the system code with
this commit.)
Color integers were being OR'ed with 0x80000000 in some places for two
distinct purposes: One, to indicate use of a default color in
glxFillMesh(); this has been replaced by use of the .UseDefault() method.
Two, to indicate to TextWindow::Printf() that the format argument of a
"%Bp"/"%Fp" specifier is an RGB color rather than a color "code" from
TextWindow::bgColors[] or TextWindow::fgColors[] (as the specifier can
accept either); instead, we define a new flag "z" (as in "%Bz" or "%Fz") to
indicate an RGBcolor pointer, leaving "%Bp"/"%Fp" to indicate a color code
exclusively.
(This also allows TextWindow::meta[][].bg to be a char instead of an int,
partly compensating for the new .bgRgb field added immediately after.)
In array declarations, RGB colors could previously be specified as 0 (often
in a terminating element). As that no longer works, we define NULL_COLOR,
which serves much the same purpose for RgbColor variables as NULL serves
for pointers.
2013-10-16 20:00:58 +00:00
|
|
|
glColor3d(rgb.redF(), rgb.greenF(), rgb.blueF());
|
2008-04-19 11:09:47 +00:00
|
|
|
ColorLocked = true;
|
|
|
|
}
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
void ssglUnlockColor(void)
|
2008-04-19 11:09:47 +00:00
|
|
|
{
|
2009-09-17 07:32:36 +00:00
|
|
|
ColorLocked = false;
|
2008-04-19 11:09:47 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 11:54:39 +00:00
|
|
|
void ssglColorRGB(RgbaColor rgb)
|
2008-04-19 11:09:47 +00:00
|
|
|
{
|
2009-09-17 07:32:36 +00:00
|
|
|
// Is there a bug in some graphics drivers where this is not equivalent
|
|
|
|
// to glColor3d? There seems to be...
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglColorRGBa(rgb, 1.0);
|
2008-04-25 07:04:09 +00:00
|
|
|
}
|
|
|
|
|
2015-07-10 11:54:39 +00:00
|
|
|
void ssglColorRGBa(RgbaColor rgb, double a)
|
2008-04-25 07:04:09 +00:00
|
|
|
{
|
Replaced RGB-color integers with dedicated data structure
RGB colors were represented using a uint32_t with the red, green and blue
values stuffed into the lower three octets (i.e. 0x00BBGGRR), like
Microsoft's COLORREF. This approach did not lend itself to type safety,
however, so this change replaces it with an RgbColor class that provides
the same infomation plus a handful of useful methods to work with it. (Note
that sizeof(RgbColor) == sizeof(uint32_t), so this change should not lead
to memory bloat.)
Some of the new methods/fields replace what were previously macro calls;
e.g. RED(c) is now c.red, REDf(c) is now c.redF(). The .Equals() method is
now used instead of == to compare colors.
RGB colors still need to be represented as packed integers in file I/O and
preferences, so the methods .FromPackedInt() and .ToPackedInt() are
provided. Also implemented are Cnf{Freeze,Thaw}Color(), type-safe wrappers
around Cnf{Freeze,Thaw}Int() that facilitate I/O with preferences.
(Cnf{Freeze,Thaw}Color() are defined outside of the system-dependent code
to minimize the footprint of the latter; because the same can be done with
Cnf{Freeze,Thaw}Bool(), those are also moved out of the system code with
this commit.)
Color integers were being OR'ed with 0x80000000 in some places for two
distinct purposes: One, to indicate use of a default color in
glxFillMesh(); this has been replaced by use of the .UseDefault() method.
Two, to indicate to TextWindow::Printf() that the format argument of a
"%Bp"/"%Fp" specifier is an RGB color rather than a color "code" from
TextWindow::bgColors[] or TextWindow::fgColors[] (as the specifier can
accept either); instead, we define a new flag "z" (as in "%Bz" or "%Fz") to
indicate an RGBcolor pointer, leaving "%Bp"/"%Fp" to indicate a color code
exclusively.
(This also allows TextWindow::meta[][].bg to be a char instead of an int,
partly compensating for the new .bgRgb field added immediately after.)
In array declarations, RGB colors could previously be specified as 0 (often
in a terminating element). As that no longer works, we define NULL_COLOR,
which serves much the same purpose for RgbColor variables as NULL serves
for pointers.
2013-10-16 20:00:58 +00:00
|
|
|
if(!ColorLocked) glColor4d(rgb.redF(), rgb.greenF(), rgb.blueF(), a);
|
2008-04-25 07:04:09 +00:00
|
|
|
}
|
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
static void Stipple(bool forSel)
|
2008-06-02 05:38:12 +00:00
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
static bool Init;
|
2008-06-02 05:38:12 +00:00
|
|
|
const int BYTES = (32*32)/8;
|
|
|
|
static GLubyte HoverMask[BYTES];
|
|
|
|
static GLubyte SelMask[BYTES];
|
|
|
|
if(!Init) {
|
|
|
|
int x, y;
|
|
|
|
for(x = 0; x < 32; x++) {
|
|
|
|
for(y = 0; y < 32; y++) {
|
|
|
|
int i = y*4 + x/8, b = x % 8;
|
|
|
|
int ym = y % 4, xm = x % 4;
|
|
|
|
for(int k = 0; k < 2; k++) {
|
|
|
|
if(xm >= 1 && xm <= 2 && ym >= 1 && ym <= 2) {
|
|
|
|
(k == 0 ? SelMask : HoverMask)[i] |= (0x80 >> b);
|
|
|
|
}
|
|
|
|
ym = (ym + 2) % 4; xm = (xm + 2) % 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
Init = true;
|
2008-06-02 05:38:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glEnable(GL_POLYGON_STIPPLE);
|
|
|
|
if(forSel) {
|
|
|
|
glPolygonStipple(SelMask);
|
|
|
|
} else {
|
|
|
|
glPolygonStipple(HoverMask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-10 11:54:39 +00:00
|
|
|
static void StippleTriangle(STriangle *tr, bool s, RgbaColor rgb)
|
2008-06-02 05:38:12 +00:00
|
|
|
{
|
|
|
|
glEnd();
|
|
|
|
glDisable(GL_LIGHTING);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglColorRGB(rgb);
|
2008-06-02 05:38:12 +00:00
|
|
|
Stipple(s);
|
|
|
|
glBegin(GL_TRIANGLES);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(tr->a);
|
|
|
|
ssglVertex3v(tr->b);
|
|
|
|
ssglVertex3v(tr->c);
|
2008-06-02 05:38:12 +00:00
|
|
|
glEnd();
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glDisable(GL_POLYGON_STIPPLE);
|
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
}
|
|
|
|
|
2015-07-10 11:54:39 +00:00
|
|
|
void ssglFillMesh(bool useSpecColor, RgbaColor specColor,
|
2015-03-26 10:30:12 +00:00
|
|
|
SMesh *m, uint32_t h, uint32_t s1, uint32_t s2)
|
2008-05-23 10:05:07 +00:00
|
|
|
{
|
2015-07-10 11:54:39 +00:00
|
|
|
RgbaColor rgbHovered = Style::Color(Style::HOVERED),
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
rgbSelected = Style::Color(Style::SELECTED);
|
2009-09-17 07:32:36 +00:00
|
|
|
|
2008-05-23 10:05:07 +00:00
|
|
|
glEnable(GL_NORMALIZE);
|
2015-03-26 10:30:12 +00:00
|
|
|
bool hasMaterial = false;
|
2015-07-10 11:54:39 +00:00
|
|
|
RgbaColor prevColor;
|
2008-05-23 10:05:07 +00:00
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
for(int i = 0; i < m->l.n; i++) {
|
|
|
|
STriangle *tr = &(m->l.elem[i]);
|
|
|
|
|
2015-07-10 11:54:39 +00:00
|
|
|
RgbaColor color;
|
2015-03-26 10:30:12 +00:00
|
|
|
if(useSpecColor) {
|
2008-06-02 03:31:37 +00:00
|
|
|
color = specColor;
|
2015-03-26 10:30:12 +00:00
|
|
|
} else {
|
|
|
|
color = tr->meta.color;
|
2008-06-02 03:31:37 +00:00
|
|
|
}
|
2015-03-26 10:30:12 +00:00
|
|
|
if(!hasMaterial || !color.Equals(prevColor)) {
|
|
|
|
GLfloat mpf[] = { color.redF(), color.greenF(), color.blueF(), color.alphaF() };
|
2008-05-30 06:09:41 +00:00
|
|
|
glEnd();
|
|
|
|
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mpf);
|
|
|
|
prevColor = color;
|
2015-03-26 10:30:12 +00:00
|
|
|
hasMaterial = true;
|
2008-05-30 06:09:41 +00:00
|
|
|
glBegin(GL_TRIANGLES);
|
|
|
|
}
|
|
|
|
|
2013-10-19 05:36:45 +00:00
|
|
|
if(tr->an.EqualsExactly(Vector::From(0, 0, 0))) {
|
2009-01-19 10:37:10 +00:00
|
|
|
// Compute the normal from the vertices
|
|
|
|
Vector n = tr->Normal();
|
|
|
|
glNormal3d(n.x, n.y, n.z);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(tr->a);
|
|
|
|
ssglVertex3v(tr->b);
|
|
|
|
ssglVertex3v(tr->c);
|
2009-01-19 10:37:10 +00:00
|
|
|
} else {
|
|
|
|
// Use the exact normals that are specified
|
|
|
|
glNormal3d((tr->an).x, (tr->an).y, (tr->an).z);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(tr->a);
|
2009-01-19 10:37:10 +00:00
|
|
|
|
|
|
|
glNormal3d((tr->bn).x, (tr->bn).y, (tr->bn).z);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(tr->b);
|
2009-01-19 10:37:10 +00:00
|
|
|
|
|
|
|
glNormal3d((tr->cn).x, (tr->cn).y, (tr->cn).z);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(tr->c);
|
2009-01-19 10:37:10 +00:00
|
|
|
}
|
2008-06-02 05:38:12 +00:00
|
|
|
|
2015-03-29 00:30:52 +00:00
|
|
|
if((s1 != 0 && tr->meta.face == s1) ||
|
2008-06-02 05:38:12 +00:00
|
|
|
(s2 != 0 && tr->meta.face == s2))
|
|
|
|
{
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
StippleTriangle(tr, true, rgbSelected);
|
2008-06-02 05:38:12 +00:00
|
|
|
}
|
|
|
|
if(h != 0 && tr->meta.face == h) {
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
StippleTriangle(tr, false, rgbHovered);
|
2008-06-02 05:38:12 +00:00
|
|
|
}
|
2008-05-23 10:05:07 +00:00
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
static void SSGL_CALLBACK Vertex(Vector *p)
|
2010-05-03 05:04:42 +00:00
|
|
|
{
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(*p);
|
2008-04-25 07:04:09 +00:00
|
|
|
}
|
2013-10-22 04:45:06 +00:00
|
|
|
void ssglFillPolygon(SPolygon *p)
|
2008-05-22 10:28:28 +00:00
|
|
|
{
|
|
|
|
GLUtesselator *gt = gluNewTess();
|
2013-10-22 04:45:06 +00:00
|
|
|
gluTessCallback(gt, GLU_TESS_BEGIN, (ssglCallbackFptr *)glBegin);
|
|
|
|
gluTessCallback(gt, GLU_TESS_END, (ssglCallbackFptr *)glEnd);
|
|
|
|
gluTessCallback(gt, GLU_TESS_VERTEX, (ssglCallbackFptr *)Vertex);
|
2008-05-22 10:28:28 +00:00
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglTesselatePolygon(gt, p);
|
2008-05-22 10:28:28 +00:00
|
|
|
|
|
|
|
gluDeleteTess(gt);
|
|
|
|
}
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
static void SSGL_CALLBACK Combine(double coords[3], void *vertexData[4],
|
|
|
|
float weight[4], void **outData)
|
2008-04-25 10:11:29 +00:00
|
|
|
{
|
|
|
|
Vector *n = (Vector *)AllocTemporary(sizeof(Vector));
|
|
|
|
n->x = coords[0];
|
|
|
|
n->y = coords[1];
|
|
|
|
n->z = coords[2];
|
|
|
|
|
|
|
|
*outData = n;
|
|
|
|
}
|
2013-10-22 04:45:06 +00:00
|
|
|
void ssglTesselatePolygon(GLUtesselator *gt, SPolygon *p)
|
2008-04-25 07:04:09 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
gluTessCallback(gt, GLU_TESS_COMBINE, (ssglCallbackFptr *)Combine);
|
2008-04-25 07:04:09 +00:00
|
|
|
gluTessProperty(gt, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);
|
|
|
|
|
2008-05-05 09:47:23 +00:00
|
|
|
Vector normal = p->normal;
|
2008-05-02 10:54:22 +00:00
|
|
|
glNormal3d(normal.x, normal.y, normal.z);
|
2008-05-05 09:47:23 +00:00
|
|
|
gluTessNormal(gt, normal.x, normal.y, normal.z);
|
2008-05-02 10:54:22 +00:00
|
|
|
|
2008-04-25 07:04:09 +00:00
|
|
|
gluTessBeginPolygon(gt, NULL);
|
|
|
|
for(i = 0; i < p->l.n; i++) {
|
|
|
|
SContour *sc = &(p->l.elem[i]);
|
|
|
|
gluTessBeginContour(gt);
|
|
|
|
for(j = 0; j < (sc->l.n-1); j++) {
|
|
|
|
SPoint *sp = &(sc->l.elem[j]);
|
|
|
|
double ap[3];
|
|
|
|
ap[0] = sp->p.x;
|
|
|
|
ap[1] = sp->p.y;
|
|
|
|
ap[2] = sp->p.z;
|
|
|
|
gluTessVertex(gt, ap, &(sp->p));
|
|
|
|
}
|
|
|
|
gluTessEndContour(gt);
|
2008-04-19 11:09:47 +00:00
|
|
|
}
|
2008-04-25 07:04:09 +00:00
|
|
|
gluTessEndPolygon(gt);
|
2008-04-19 11:09:47 +00:00
|
|
|
}
|
2008-04-25 07:04:09 +00:00
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
void ssglDebugPolygon(SPolygon *p)
|
2008-05-19 09:23:49 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
2015-03-22 13:39:12 +00:00
|
|
|
ssglLineWidth(2);
|
2008-05-19 09:23:49 +00:00
|
|
|
glPointSize(7);
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
for(i = 0; i < p->l.n; i++) {
|
|
|
|
SContour *sc = &(p->l.elem[i]);
|
|
|
|
for(j = 0; j < (sc->l.n-1); j++) {
|
|
|
|
Vector a = (sc->l.elem[j]).p;
|
|
|
|
Vector b = (sc->l.elem[j+1]).p;
|
|
|
|
|
2013-12-02 06:25:09 +00:00
|
|
|
ssglLockColorTo(RGBi(0, 0, 255));
|
2008-05-19 09:23:49 +00:00
|
|
|
Vector d = (a.Minus(b)).WithMagnitude(-0);
|
|
|
|
glBegin(GL_LINES);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(a.Plus(d));
|
|
|
|
ssglVertex3v(b.Minus(d));
|
2008-05-19 09:23:49 +00:00
|
|
|
glEnd();
|
2013-12-02 06:25:09 +00:00
|
|
|
ssglLockColorTo(RGBi(255, 0, 0));
|
2008-05-19 09:23:49 +00:00
|
|
|
glBegin(GL_POINTS);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(a.Plus(d));
|
|
|
|
ssglVertex3v(b.Minus(d));
|
2008-05-19 09:23:49 +00:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
void ssglDrawEdges(SEdgeList *el, bool endpointsToo)
|
2008-05-19 09:23:49 +00:00
|
|
|
{
|
2009-01-25 09:19:59 +00:00
|
|
|
SEdge *se;
|
2008-07-06 07:56:24 +00:00
|
|
|
glBegin(GL_LINES);
|
2009-01-25 09:19:59 +00:00
|
|
|
for(se = el->l.First(); se; se = el->l.NextAfter(se)) {
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(se->a);
|
|
|
|
ssglVertex3v(se->b);
|
2009-04-19 05:53:16 +00:00
|
|
|
}
|
|
|
|
glEnd();
|
2009-05-24 11:37:07 +00:00
|
|
|
|
|
|
|
if(endpointsToo) {
|
|
|
|
glPointSize(12);
|
|
|
|
glBegin(GL_POINTS);
|
|
|
|
for(se = el->l.First(); se; se = el->l.NextAfter(se)) {
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(se->a);
|
|
|
|
ssglVertex3v(se->b);
|
2009-05-24 11:37:07 +00:00
|
|
|
}
|
|
|
|
glEnd();
|
2008-05-19 09:23:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
void ssglDebugMesh(SMesh *m)
|
2008-05-22 10:28:28 +00:00
|
|
|
{
|
|
|
|
int i;
|
2015-03-22 13:39:12 +00:00
|
|
|
ssglLineWidth(1);
|
2008-05-22 10:28:28 +00:00
|
|
|
glPointSize(7);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglDepthRangeOffset(1);
|
|
|
|
ssglUnlockColor();
|
2008-06-23 08:48:19 +00:00
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
2013-12-02 06:25:09 +00:00
|
|
|
ssglColorRGBa(RGBi(0, 255, 0), 1.0);
|
2008-06-23 08:48:19 +00:00
|
|
|
glBegin(GL_TRIANGLES);
|
2008-05-22 10:28:28 +00:00
|
|
|
for(i = 0; i < m->l.n; i++) {
|
|
|
|
STriangle *t = &(m->l.elem[i]);
|
|
|
|
if(t->tag) continue;
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(t->a);
|
|
|
|
ssglVertex3v(t->b);
|
|
|
|
ssglVertex3v(t->c);
|
2008-05-22 10:28:28 +00:00
|
|
|
}
|
2008-06-23 08:48:19 +00:00
|
|
|
glEnd();
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglDepthRangeOffset(0);
|
2008-06-23 08:48:19 +00:00
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
2008-05-22 10:28:28 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
void ssglMarkPolygonNormal(SPolygon *p)
|
2008-05-19 09:23:49 +00:00
|
|
|
{
|
2008-06-01 08:45:11 +00:00
|
|
|
Vector tail = Vector::From(0, 0, 0);
|
2008-05-05 09:47:23 +00:00
|
|
|
int i, j, cnt = 0;
|
|
|
|
// Choose some reasonable center point.
|
|
|
|
for(i = 0; i < p->l.n; i++) {
|
|
|
|
SContour *sc = &(p->l.elem[i]);
|
|
|
|
for(j = 0; j < (sc->l.n-1); j++) {
|
|
|
|
SPoint *sp = &(sc->l.elem[j]);
|
|
|
|
tail = tail.Plus(sp->p);
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(cnt == 0) return;
|
|
|
|
tail = tail.ScaledBy(1.0/cnt);
|
|
|
|
|
|
|
|
Vector gn = SS.GW.projRight.Cross(SS.GW.projUp);
|
|
|
|
Vector tip = tail.Plus((p->normal).WithMagnitude(40/SS.GW.scale));
|
|
|
|
Vector arrow = (p->normal).WithMagnitude(15/SS.GW.scale);
|
|
|
|
|
|
|
|
glColor3d(1, 1, 0);
|
|
|
|
glBegin(GL_LINES);
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglVertex3v(tail);
|
|
|
|
ssglVertex3v(tip);
|
|
|
|
ssglVertex3v(tip);
|
|
|
|
ssglVertex3v(tip.Minus(arrow.RotatedAbout(gn, 0.6)));
|
|
|
|
ssglVertex3v(tip);
|
|
|
|
ssglVertex3v(tip.Minus(arrow.RotatedAbout(gn, -0.6)));
|
2008-05-05 09:47:23 +00:00
|
|
|
glEnd();
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
}
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
void ssglDepthRangeOffset(int units)
|
2010-05-03 05:04:42 +00:00
|
|
|
{
|
2008-06-17 19:12:25 +00:00
|
|
|
if(!DepthOffsetLocked) {
|
|
|
|
// The size of this step depends on the resolution of the Z buffer; for
|
|
|
|
// a 16-bit buffer, this should be fine.
|
|
|
|
double d = units/60000.0;
|
|
|
|
glDepthRange(0.1-d, 1-d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
void ssglDepthRangeLockToFront(bool yes)
|
2010-05-03 05:04:42 +00:00
|
|
|
{
|
2008-06-17 19:12:25 +00:00
|
|
|
if(yes) {
|
|
|
|
DepthOffsetLocked = true;
|
|
|
|
glDepthRange(0, 0);
|
|
|
|
} else {
|
|
|
|
DepthOffsetLocked = false;
|
2013-10-22 04:45:06 +00:00
|
|
|
ssglDepthRangeOffset(0);
|
2008-06-17 19:12:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-05 19:39:27 +00:00
|
|
|
const int BitmapFontChunkSize = 64 * 64;
|
|
|
|
static bool BitmapFontChunkInitialized[0x10000 / BitmapFontChunkSize];
|
|
|
|
static int BitmapFontCurrentChunk = -1;
|
2010-05-09 01:20:02 +00:00
|
|
|
|
2015-11-05 19:39:27 +00:00
|
|
|
static void CreateBitmapFontChunk(const uint8_t *source, size_t sourceLength,
|
|
|
|
int textureIndex)
|
|
|
|
{
|
|
|
|
// Place the font in our texture in a two-dimensional grid.
|
|
|
|
// The maximum texture size that is reasonably supported is 1024x1024.
|
|
|
|
const size_t fontTextureSize = BitmapFontChunkSize*16*16;
|
|
|
|
uint8_t *fontTexture = (uint8_t *)malloc(fontTextureSize),
|
|
|
|
*mappedTexture = (uint8_t *)malloc(fontTextureSize);
|
|
|
|
|
|
|
|
z_stream stream;
|
|
|
|
stream.zalloc = Z_NULL;
|
|
|
|
stream.zfree = Z_NULL;
|
|
|
|
stream.opaque = Z_NULL;
|
|
|
|
if(inflateInit(&stream) != Z_OK)
|
|
|
|
oops();
|
|
|
|
|
|
|
|
stream.next_in = (Bytef *)source;
|
|
|
|
stream.avail_in = sourceLength;
|
|
|
|
stream.next_out = fontTexture;
|
|
|
|
stream.avail_out = fontTextureSize;
|
|
|
|
if(inflate(&stream, Z_NO_FLUSH) != Z_STREAM_END)
|
|
|
|
oops();
|
|
|
|
if(stream.avail_out != 0)
|
|
|
|
oops();
|
|
|
|
|
|
|
|
inflateEnd(&stream);
|
|
|
|
|
|
|
|
for(int a = 0; a < BitmapFontChunkSize; a++) {
|
|
|
|
int row = a / 64, col = a % 64;
|
|
|
|
|
|
|
|
for(int i = 0; i < 16; i++) {
|
|
|
|
memcpy(mappedTexture + row*64*16*16 + col*16 + i*64*16,
|
|
|
|
fontTexture + a*16*16 + i*16,
|
2010-05-09 01:20:02 +00:00
|
|
|
16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-05 19:39:27 +00:00
|
|
|
free(fontTexture);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, textureIndex);
|
2010-04-26 07:52:49 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA,
|
2015-11-05 19:39:27 +00:00
|
|
|
16*64, 64*16,
|
2010-04-26 07:52:49 +00:00
|
|
|
0,
|
|
|
|
GL_ALPHA, GL_UNSIGNED_BYTE,
|
2015-11-05 19:39:27 +00:00
|
|
|
mappedTexture);
|
|
|
|
|
|
|
|
free(mappedTexture);
|
2010-04-26 07:52:49 +00:00
|
|
|
}
|
|
|
|
|
2015-11-05 19:39:27 +00:00
|
|
|
static void SwitchToBitmapFontChunkFor(char32_t chr)
|
|
|
|
{
|
|
|
|
int plane = chr / BitmapFontChunkSize,
|
|
|
|
textureIndex = TEXTURE_BITMAP_FONT + plane;
|
|
|
|
|
|
|
|
if(BitmapFontCurrentChunk != textureIndex) {
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
if(!BitmapFontChunkInitialized[plane]) {
|
|
|
|
CreateBitmapFontChunk(CompressedFontTexture[plane].data,
|
|
|
|
CompressedFontTexture[plane].length,
|
|
|
|
textureIndex);
|
|
|
|
BitmapFontChunkInitialized[plane] = true;
|
|
|
|
} else {
|
|
|
|
glBindTexture(GL_TEXTURE_2D, textureIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
BitmapFontCurrentChunk = textureIndex;
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ssglInitializeBitmapFont()
|
|
|
|
{
|
|
|
|
memset(BitmapFontChunkInitialized, 0, sizeof(BitmapFontChunkInitialized));
|
|
|
|
BitmapFontCurrentChunk = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ssglBitmapCharWidth(char32_t chr) {
|
|
|
|
if(!CodepointProperties[chr].exists)
|
|
|
|
oops();
|
|
|
|
return CodepointProperties[chr].isWide ? 2 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ssglBitmapCharQuad(char32_t chr, double x, double y)
|
2010-05-03 05:04:42 +00:00
|
|
|
{
|
2010-05-09 01:20:02 +00:00
|
|
|
int w, h;
|
|
|
|
|
2015-11-05 19:39:27 +00:00
|
|
|
h = 16;
|
|
|
|
if(chr >= 0xe000 && chr <= 0xefff) {
|
2010-05-09 01:20:02 +00:00
|
|
|
// Special character, like a checkbox or a radio button
|
2015-11-05 19:39:27 +00:00
|
|
|
w = 16;
|
2010-05-09 18:25:23 +00:00
|
|
|
x -= 3;
|
2015-11-05 19:39:27 +00:00
|
|
|
} else if(CodepointProperties[chr].isWide) {
|
|
|
|
// Wide (usually CJK or reserved) character
|
|
|
|
w = 16;
|
2010-05-09 01:20:02 +00:00
|
|
|
} else {
|
2015-11-05 19:39:27 +00:00
|
|
|
// Normal character
|
|
|
|
w = 8;
|
2010-05-09 01:20:02 +00:00
|
|
|
}
|
|
|
|
|
2015-11-05 19:39:27 +00:00
|
|
|
if(chr != ' ' && chr != 0) {
|
|
|
|
int n = chr % BitmapFontChunkSize;
|
|
|
|
int row = n / 64, col = n % 64;
|
|
|
|
double s0 = col/64.0,
|
|
|
|
s1 = (col+1)/64.0,
|
2010-05-09 01:20:02 +00:00
|
|
|
t0 = row/64.0,
|
|
|
|
t1 = t0 + (w/16.0)/64;
|
2010-04-26 07:52:49 +00:00
|
|
|
|
2015-11-05 19:39:27 +00:00
|
|
|
SwitchToBitmapFontChunkFor(chr);
|
|
|
|
|
2010-04-26 07:52:49 +00:00
|
|
|
glTexCoord2d(s1, t0);
|
|
|
|
glVertex2d(x, y);
|
|
|
|
|
|
|
|
glTexCoord2d(s1, t1);
|
|
|
|
glVertex2d(x + w, y);
|
|
|
|
|
|
|
|
glTexCoord2d(s0, t1);
|
|
|
|
glVertex2d(x + w, y - h);
|
|
|
|
|
|
|
|
glTexCoord2d(s0, t0);
|
|
|
|
glVertex2d(x, y - h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-14 20:13:40 +00:00
|
|
|
void ssglBitmapText(const std::string &str, Vector p)
|
2010-05-03 05:04:42 +00:00
|
|
|
{
|
2010-04-26 07:52:49 +00:00
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glBegin(GL_QUADS);
|
2016-02-14 20:13:40 +00:00
|
|
|
for(char32_t chr : ReadUTF8(str)) {
|
2015-11-05 19:39:27 +00:00
|
|
|
ssglBitmapCharQuad(chr, p.x, p.y);
|
|
|
|
p.x += 8 * ssglBitmapCharWidth(chr);
|
2010-04-26 07:52:49 +00:00
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
|
2013-10-22 04:45:06 +00:00
|
|
|
void ssglDrawPixelsWithTexture(uint8_t *data, int w, int h)
|
2010-05-03 05:04:42 +00:00
|
|
|
{
|
|
|
|
#define MAX_DIM 32
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
static uint8_t Texture[MAX_DIM*MAX_DIM*3];
|
2010-05-03 05:04:42 +00:00
|
|
|
int i, j;
|
|
|
|
if(w > MAX_DIM || h > MAX_DIM) oops();
|
|
|
|
|
|
|
|
for(i = 0; i < w; i++) {
|
|
|
|
for(j = 0; j < h; j++) {
|
|
|
|
Texture[(j*MAX_DIM + i)*3 + 0] = data[(j*w + i)*3 + 0];
|
|
|
|
Texture[(j*MAX_DIM + i)*3 + 1] = data[(j*w + i)*3 + 1];
|
|
|
|
Texture[(j*MAX_DIM + i)*3 + 2] = data[(j*w + i)*3 + 2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, TEXTURE_DRAW_PIXELS);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
|
|
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
|
|
|
|
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, MAX_DIM, MAX_DIM, 0,
|
|
|
|
GL_RGB, GL_UNSIGNED_BYTE, Texture);
|
|
|
|
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glTexCoord2d(0, 0);
|
|
|
|
glVertex2d(0, h);
|
|
|
|
|
|
|
|
glTexCoord2d(((double)w)/MAX_DIM, 0);
|
|
|
|
glVertex2d(w, h);
|
|
|
|
|
|
|
|
glTexCoord2d(((double)w)/MAX_DIM, ((double)h)/MAX_DIM);
|
|
|
|
glVertex2d(w, 0);
|
|
|
|
|
|
|
|
glTexCoord2d(0, ((double)h)/MAX_DIM);
|
|
|
|
glVertex2d(0, 0);
|
|
|
|
glEnd();
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
};
|