code:
#ifndef __libfixmath_fix16_h__
#define __libfixmath_fix16_h__

#include "compat.h"

#ifdef __cplusplus
extern "C"
{
#endif

/* These options may let the optimizer to remove some calls to the functions.
 * Refer to http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
 */
#ifndef FIXMATH_FUNC_ATTRS
# ifdef __GNUC__
#   if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6)
#     define FIXMATH_FUNC_ATTRS __attribute__((leaf, nothrow, const))
#   else
#     define FIXMATH_FUNC_ATTRS __attribute__((nothrow, const))
#   endif
# else
#   define FIXMATH_FUNC_ATTRS
# endif
#endif

#include <stdint.h>

typedef int32_t fix16_t;

static CONSTEXPR const fix16_t FIX16_MAX      = 0x7FFFFFFF; /*!< the maximum value of fix16_t */
static CONSTEXPR const fix16_t FIX16_MIN      = 0x80000000; /*!< the minimum value of fix16_t */
static CONSTEXPR const fix16_t FIX16_OVERFLOW = 0x80000000; /*!< the value used to indicate overflows */

static CONSTEXPR const fix16_t fix16_one  = 0x00010000;       /*!< fix16_t value of 1 */
static CONSTEXPR const fix16_t fix16_half = 0x00008000;       /*!< fix16_t value of 0.5 */
static CONSTEXPR const float   flt_f161r  = 1.f / 0x00010000;  /*!< reciprocal of fix16_one as a float */

/* Conversion functions between fix16_t and float/integer.
 * These are inlined to allow compiler to optimize away constant numbers
 */
static FORCE_INLINE CONSTEXPR int    fix16_to_int(fix16_t a)   { return (a + (a >= 0 ? fix16_half : -fix16_half)) / fix16_one; }
static FORCE_INLINE CONSTEXPR float  fix16_to_float(fix16_t a) { return (float)a * flt_f161r; }
static FORCE_INLINE CONSTEXPR double fix16_to_dbl(fix16_t a)   { return (double)a * flt_f161r; }

static FORCE_INLINE CONSTEXPR fix16_t fix16_from_int(int a)     { return a * fix16_one; }
static FORCE_INLINE CONSTEXPR fix16_t fix16_from_float(float a) { return (fix16_t)(a * fix16_one + (a >= 0 ? 0.5f : -0.5f)); }
static FORCE_INLINE CONSTEXPR fix16_t fix16_from_dbl(double a)  { return (fix16_t)(a * fix16_one + (a >= 0 ? 0.5 : -0.5)); }

/* Macro for defining fix16_t constant values.
   The functions above can't be used from e.g. global variable initializers,
   and their names are quite long also. This macro is useful for constants
   springled alongside code, e.g. F16(1.234).

   Note that the argument is evaluated multiple times, and also otherwise
   you should only use this for constant values. For runtime-conversions,
   use the functions above.
*/
#define F16(x) ((fix16_t)(((x) >= 0) ? ((x) * 65536.0 + 0.5) : ((x) * 65536.0 - 0.5)))

static FORCE_INLINE fix16_t fix16_abs(fix16_t const x)   { return abs(x); }
static FORCE_INLINE CONSTEXPR fix16_t fix16_floor(fix16_t const x) { return (x & 0xFFFF0000UL); }
static FORCE_INLINE CONSTEXPR fix16_t fix16_ceil(fix16_t const x)  { return (x & 0xFFFF0000UL) + ((x & 0x0000FFFFUL) ? fix16_one : 0); }
static FORCE_INLINE fix16_t fix16_min(fix16_t const x, fix16_t const y) { return min(x, y); }
static FORCE_INLINE fix16_t fix16_max(fix16_t const x, fix16_t const y) { return max(x, y); }
static FORCE_INLINE fix16_t fix16_clamp(fix16_t const x, fix16_t const lo, fix16_t const hi) { return clamp(x, lo, hi); }

/* Subtraction and addition with overflow detection. */
extern fix16_t fix16_add(fix16_t a, fix16_t b) FIXMATH_FUNC_ATTRS;
extern fix16_t fix16_sub(fix16_t a, fix16_t b) FIXMATH_FUNC_ATTRS;

/* Saturating arithmetic */
extern fix16_t fix16_sadd(fix16_t a, fix16_t b) FIXMATH_FUNC_ATTRS;
extern fix16_t fix16_ssub(fix16_t a, fix16_t b) FIXMATH_FUNC_ATTRS;

/*! Multiplies the two given fix16_t's and returns the result.
*/
extern fix16_t fix16_mul(fix16_t inArg0, fix16_t inArg1) FIXMATH_FUNC_ATTRS;

/*! Divides the first given fix16_t by the second and returns the result.
*/
extern fix16_t fix16_div(fix16_t a, fix16_t b) FIXMATH_FUNC_ATTRS;

/*! Performs a saturated multiplication (overflow-protected) of the two given fix16_t's and returns the result.
*/
extern fix16_t fix16_smul(fix16_t inArg0, fix16_t inArg1) FIXMATH_FUNC_ATTRS;

/*! Performs a saturated division (overflow-protected) of the first fix16_t by the second and returns the result.
*/
extern fix16_t fix16_sdiv(fix16_t inArg0, fix16_t inArg1) FIXMATH_FUNC_ATTRS;

/*! Divides the first given fix16_t by the second and returns the remainder.
*/
static FORCE_INLINE fix16_t fix16_mod(fix16_t x, fix16_t y) { return x %= y; }

/*! Performs a fast multiplication of the two given fix16_t's with truncation, and returns the result.
*/
static FORCE_INLINE fix16_t fix16_fast_trunc_mul(fix16_t x, fix16_t y) { return ((int64_t)x * y) >> 16; }

/*! Performs a fast multiplication of an int by a fix16_t with truncation, and returns an int.
*/
static FORCE_INLINE int fix16_fast_trunc_mul_int_by_fix16(int x, fix16_t y) { return ((int64_t)x * y) >> 16; }

/*! Returns the linear interpolation: (inArg0 * (1 - inFract)) + (inArg1 * inFract)
*/
extern fix16_t fix16_lerp8(fix16_t inArg0, fix16_t inArg1, uint8_t inFract) FIXMATH_FUNC_ATTRS;
extern fix16_t fix16_lerp16(fix16_t inArg0, fix16_t inArg1, uint16_t inFract) FIXMATH_FUNC_ATTRS;
extern fix16_t fix16_lerp32(fix16_t inArg0, fix16_t inArg1, uint32_t inFract) FIXMATH_FUNC_ATTRS;

static CONSTEXPR const fix16_t fix16_rad_to_deg_mult = 3754936;
static FORCE_INLINE fix16_t fix16_rad_to_deg(fix16_t radians) { return fix16_mul(radians, fix16_rad_to_deg_mult); }

static CONSTEXPR const fix16_t fix16_deg_to_rad_mult = 1144;
static FORCE_INLINE fix16_t fix16_deg_to_rad(fix16_t degrees) { return fix16_mul(degrees, fix16_deg_to_rad_mult); }

/*! Returns the square of the given fix16_t.
*/
static inline fix16_t fix16_sq(fix16_t x) { return fix16_mul(x, x); }

/*! Convert fix16_t value to a string.
 * Required buffer length for largest values is 13 bytes.
 */
extern void fix16_to_str(fix16_t value, char *buf, int decimals);

/*! Convert string to a fix16_t value
 * Ignores spaces at beginning and end. Returns fix16_overflow if
 * value is too large or there were garbage characters.
 */
extern fix16_t fix16_from_str(const char *buf);

#ifdef __cplusplus
}
#include "pragmas.h"
#include "fix16.hpp"
#endif

#endif

repo_name: orochi/nblood

license: mit


code:
#ifndef __libfixmath_fix16_hpp__
#define __libfixmath_fix16_hpp__

#include "fix16.h"

class Fix16 {
    public:
        fix16_t m_value;

        Fix16() { m_value = 0; }
        Fix16(const Fix16 & inValue) { m_value = inValue.m_value; }
        Fix16(const fix16_t inValue) { m_value = inValue; }
        Fix16(const float   inValue) { m_value = fix16_from_float(inValue); }
        Fix16(const double  inValue) { m_value = fix16_from_dbl(inValue); }
        Fix16(const int16_t inValue) { m_value = fix16_from_int(inValue); }

        operator fix16_t() const { return m_value; }
        operator double()  const { return fix16_to_dbl(m_value); }
        operator float()   const { return fix16_to_float(m_value); }
        operator int16_t() const { return fix16_to_int(m_value); }

        Fix16 &operator=(const Fix16 & rhs) { m_value = rhs.m_value; return *this; }
        Fix16 &operator=(const fix16_t rhs) { m_value = rhs; return *this; }
        Fix16 &operator=(const double  rhs) { m_value = fix16_from_dbl(rhs); return *this; }
        Fix16 &operator=(const float   rhs) { m_value = fix16_from_float(rhs); return *this; }
        Fix16 &operator=(const int16_t rhs) { m_value = fix16_from_int(rhs); return *this; }

        Fix16 &operator+=(const Fix16 & rhs) { m_value += rhs.m_value; return *this; }
        Fix16 &operator+=(const fix16_t rhs) { m_value += rhs; return *this; }
        Fix16 &operator+=(const double  rhs) { m_value += fix16_from_dbl(rhs); return *this; }
        Fix16 &operator+=(const float   rhs) { m_value += fix16_from_float(rhs); return *this; }
        Fix16 &operator+=(const int16_t rhs) { m_value += fix16_from_int(rhs); return *this; }

        Fix16 &operator-=(const Fix16 & rhs) { m_value -= rhs.m_value; return *this; }
        Fix16 &operator-=(const fix16_t rhs) { m_value -= rhs; return *this; }
        Fix16 &operator-=(const double  rhs) { m_value -= fix16_from_dbl(rhs); return *this; }
        Fix16 &operator-=(const float   rhs) { m_value -= fix16_from_float(rhs); return *this; }
        Fix16 &operator-=(const int16_t rhs) { m_value -= fix16_from_int(rhs); return *this; }

        Fix16 &operator*=(const Fix16 & rhs) { m_value = fix16_mul(m_value, rhs.m_value); return *this; }
        Fix16 &operator*=(const fix16_t rhs) { m_value = fix16_mul(m_value, rhs); return *this; }
        Fix16 &operator*=(const double  rhs) { m_value = fix16_mul(m_value, fix16_from_dbl(rhs)); return *this; }
        Fix16 &operator*=(const float   rhs) { m_value = fix16_mul(m_value, fix16_from_float(rhs)); return *this; }
        Fix16 &operator*=(const int16_t rhs) { m_value *= rhs; return *this; }

        Fix16 &operator/=(const Fix16 & rhs) { m_value = fix16_div(m_value, rhs.m_value); return *this; }
        Fix16 &operator/=(const fix16_t rhs) { m_value = fix16_div(m_value, rhs); return *this; }
        Fix16 &operator/=(const double  rhs) { m_value = fix16_div(m_value, fix16_from_dbl(rhs)); return *this; }
        Fix16 &operator/=(const float   rhs) { m_value = fix16_div(m_value, fix16_from_float(rhs)); return *this; }
        Fix16 &operator/=(const int16_t rhs) { m_value = tabledivide32(m_value, rhs); return *this; }

        Fix16 &operator%=(const Fix16 & rhs) { m_value = fix16_mod(m_value, rhs.m_value); return *this; }
        Fix16 &operator%=(const fix16_t rhs) { m_value = fix16_mod(m_value, rhs); return *this; }
        Fix16 &operator%=(const double  rhs) { m_value = fix16_mod(m_value, fix16_from_dbl(rhs)); return *this; }
        Fix16 &operator%=(const float   rhs) { m_value = fix16_mod(m_value, fix16_from_float(rhs)); return *this; }
        Fix16 &operator%=(const int16_t rhs) { m_value %= rhs; return *this; }

        Fix16 &operator&=(const Fix16 & rhs) { m_value = fix16_from_int(fix16_to_int(m_value) & fix16_to_int(rhs.m_value)); return *this; }
        Fix16 &operator&=(const fix16_t rhs) { m_value = fix16_from_int(fix16_to_int(m_value) & fix16_to_int(rhs)); return *this; }
        Fix16 &operator&=(const int16_t rhs) { m_value = fix16_from_int(fix16_to_int(m_value) & rhs); return *this; }

        Fix16 &operator^=(const Fix16 & rhs) { m_value = fix16_from_int(fix16_to_int(m_value) ^ fix16_to_int(rhs.m_value)); return *this; }
        Fix16 &operator^=(const fix16_t rhs) { m_value = fix16_from_int(fix16_to_int(m_value) ^ fix16_to_int(rhs)); return *this; }
        Fix16 &operator^=(const int16_t rhs) { m_value = fix16_from_int(fix16_to_int(m_value) ^ rhs); return *this; }

        Fix16 &operator|=(const Fix16 & rhs) { m_value = fix16_from_int(fix16_to_int(m_value) | fix16_to_int(rhs.m_value)); return *this; }
        Fix16 &operator|=(const fix16_t rhs) { m_value = fix16_from_int(fix16_to_int(m_value) | fix16_to_int(rhs)); return *this; }
        Fix16 &operator|=(const int16_t rhs) { m_value = fix16_from_int(fix16_to_int(m_value) | rhs); return *this; }

        Fix16 &operator<<=(const Fix16 & rhs) { m_value <<= rhs.m_value; return *this; }
        Fix16 &operator<<=(const fix16_t rhs) { m_value <<= rhs; return *this; }
        Fix16 &operator<<=(const int16_t rhs) { m_value <<= fix16_from_int(rhs); return *this; }

        Fix16 &operator>>=(const Fix16 & rhs) { m_value >>= rhs.m_value; return *this; }
        Fix16 &operator>>=(const fix16_t rhs) { m_value >>= rhs; return *this; }
        Fix16 &operator>>=(const int16_t rhs) { m_value >>= fix16_from_int(rhs); return *this; }

        const Fix16 operator+(const Fix16 & other) const { return fix16_add(m_value, other.m_value); }
        const Fix16 operator+(const fix16_t other) const { return fix16_add(m_value, other); }
        const Fix16 operator+(const double  other) const { return fix16_add(m_value, fix16_from_dbl(other)); }
        const Fix16 operator+(const float   other) const { return fix16_add(m_value, fix16_from_float(other)); }
        const Fix16 operator+(const int16_t other) const { return fix16_add(m_value, fix16_from_int(other)); }

        const Fix16 sadd(const Fix16 & other) const { return fix16_sadd(m_value, other.m_value); }
        const Fix16 sadd(const fix16_t other) const { return fix16_sadd(m_value, other); }
        const Fix16 sadd(const double  other) const { return fix16_sadd(m_value, fix16_from_dbl(other)); }
        const Fix16 sadd(const float   other) const { return fix16_sadd(m_value, fix16_from_float(other)); }
        const Fix16 sadd(const int16_t other) const { return fix16_sadd(m_value, fix16_from_int(other)); }

        const Fix16 operator-(const Fix16 & other) const { return fix16_add(m_value, -other.m_value); }
        const Fix16 operator-(const fix16_t other) const { return fix16_add(m_value, -other); }
        const Fix16 operator-(const double  other) const { return fix16_add(m_value, -fix16_from_dbl(other)); }
        const Fix16 operator-(const float   other) const { return fix16_add(m_value, -fix16_from_float(other)); }
        const Fix16 operator-(const int16_t other) const { return fix16_add(m_value, -fix16_from_int(other)); }

        const Fix16 ssub(const Fix16 & other) const { return fix16_sadd(m_value, -other.m_value); }
        const Fix16 ssub(const fix16_t other) const { return fix16_sadd(m_value, -other); }
        const Fix16 ssub(const double  other) const { return fix16_sadd(m_value, -fix16_from_dbl(other)); }
        const Fix16 ssub(const float   other) const { return fix16_sadd(m_value, -fix16_from_float(other)); }
        const Fix16 ssub(const int16_t other) const { return fix16_sadd(m_value, -fix16_from_int(other)); }

        const Fix16 operator*(const Fix16 & other) const { return fix16_mul(m_value, other.m_value); }
        const Fix16 operator*(const fix16_t other) const { return fix16_mul(m_value, other); }
        const Fix16 operator*(const double  other) const { return fix16_mul(m_value, fix16_from_dbl(other)); }
        const Fix16 operator*(const float   other) const { return fix16_mul(m_value, fix16_from_float(other)); }
        const Fix16 operator*(const int16_t other) const { return fix16_mul(m_value, fix16_from_int(other)); }

        const Fix16 smul(const Fix16 & other) const { return fix16_smul(m_value, other.m_value); }
        const Fix16 smul(const fix16_t other) const { return fix16_smul(m_value, other); }
        const Fix16 smul(const double  other) const { return fix16_smul(m_value, fix16_from_dbl(other)); }
        const Fix16 smul(const float   other) const { return fix16_smul(m_value, fix16_from_float(other)); }
        const Fix16 smul(const int16_t other) const { return fix16_smul(m_value, fix16_from_int(other)); }

        const Fix16 operator/(const Fix16 & other) const { return fix16_div(m_value, other.m_value); }
        const Fix16 operator/(const fix16_t other) const { return fix16_div(m_value, other); }
        const Fix16 operator/(const double  other) const { return fix16_div(m_value, fix16_from_dbl(other)); }
        const Fix16 operator/(const float   other) const { return fix16_div(m_value, fix16_from_float(other)); }
        const Fix16 operator/(const int16_t other) const { return fix16_div(m_value, fix16_from_int(other)); }

        const Fix16 sdiv(const Fix16 & other) const { return fix16_sdiv(m_value, other.m_value); }
        const Fix16 sdiv(const fix16_t other) const { return fix16_sdiv(m_value, other); }
        const Fix16 sdiv(const double  other) const { return fix16_sdiv(m_value, fix16_from_dbl(other)); }
        const Fix16 sdiv(const float   other) const { return fix16_sdiv(m_value, fix16_from_float(other)); }
        const Fix16 sdiv(const int16_t other) const { return fix16_sdiv(m_value, fix16_from_int(other)); }

        bool operator==(const Fix16 & other) const { return m_value == other.m_value; }
        bool operator==(const fix16_t other) const { return m_value == other; }
        bool operator==(const double  other) const { return m_value == fix16_from_dbl(other); }
        bool operator==(const float   other) const { return m_value == fix16_from_float(other); }
        bool operator==(const int16_t other) const { return m_value == fix16_from_int(other); }

        bool operator!=(const Fix16 & other) const { return m_value != other.m_value; }
        bool operator!=(const fix16_t other) const { return m_value != other; }
        bool operator!=(const double  other) const { return m_value != fix16_from_dbl(other); }
        bool operator!=(const float   other) const { return m_value != fix16_from_float(other); }
        bool operator!=(const int16_t other) const { return m_value != fix16_from_int(other); }

        bool operator<=(const Fix16 & other) const { return m_value <= other.m_value; }
        bool operator<=(const fix16_t other) const { return m_value <= other; }
        bool operator<=(const double  other) const { return m_value <= fix16_from_dbl(other); }
        bool operator<=(const float   other) const { return m_value <= fix16_from_float(other); }
        bool operator<=(const int16_t other) const { return m_value <= fix16_from_int(other); }

        bool operator>=(const Fix16 & other) const { return m_value >= other.m_value; }
        bool operator>=(const fix16_t other) const { return m_value >= other; }
        bool operator>=(const double  other) const { return m_value >= fix16_from_dbl(other); }
        bool operator>=(const float   other) const { return m_value >= fix16_from_float(other); }
        bool operator>=(const int16_t other) const { return m_value >= fix16_from_int(other); }

        bool operator<(const Fix16 & other) const { return m_value < other.m_value; }
        bool operator<(const fix16_t other) const { return m_value < other; }
        bool operator<(const double  other) const { return m_value < fix16_from_dbl(other); }
        bool operator<(const float   other) const { return m_value < fix16_from_float(other); }
        bool operator<(const int16_t other) const { return m_value < fix16_from_int(other); }

        bool operator>(const Fix16 & other) const { return m_value > other.m_value; }
        bool operator>(const fix16_t other) const { return m_value > other; }
        bool operator>(const double  other) const { return m_value > fix16_from_dbl(other); }
        bool operator>(const float   other) const { return m_value > fix16_from_float(other); }
        bool operator>(const int16_t other) const { return m_value > fix16_from_int(other); }
};

#endif


code:
#ifndef __libfixmath_int64_h__
#define __libfixmath_int64_h__

#include "compat.h"

#ifdef __cplusplus
extern "C"
{
#endif

static FORCE_INLINE CONSTEXPR  int64_t int64_const(int32_t hi, uint32_t lo) { return (((int64_t)hi << 32) | lo); }
static FORCE_INLINE CONSTEXPR  int64_t int64_from_int32(int32_t x) { return (int64_t)x; }
static FORCE_INLINE CONSTEXPR  int32_t int64_hi(int64_t x) { return (x >> 32); }
static FORCE_INLINE CONSTEXPR uint32_t int64_lo(int64_t x) { return (x & ((1ULL << 32) - 1)); }

static FORCE_INLINE CONSTEXPR int64_t int64_add(int64_t x, int64_t y)   { return (x + y);  }
static FORCE_INLINE CONSTEXPR int64_t int64_neg(int64_t x)              { return (-x);     }
static FORCE_INLINE CONSTEXPR int64_t int64_sub(int64_t x, int64_t y)   { return (x - y);  }
static FORCE_INLINE CONSTEXPR int64_t int64_shift(int64_t x, int8_t y)  { return (y < 0 ? (x >> -y) : (x << y)); }

static FORCE_INLINE CONSTEXPR int64_t int64_mul_i32_i32(int32_t x, int32_t y) { return (x * y);  }
static FORCE_INLINE CONSTEXPR int64_t int64_mul_i64_i32(int64_t x, int32_t y) { return (x * y);  }

static FORCE_INLINE CONSTEXPR int64_t int64_div_i64_i32(int64_t x, int32_t y) { return (x / y);  }

static FORCE_INLINE CONSTEXPR int int64_cmp_eq(int64_t x, int64_t y) { return (x == y); }
static FORCE_INLINE CONSTEXPR int int64_cmp_ne(int64_t x, int64_t y) { return (x != y); }
static FORCE_INLINE CONSTEXPR int int64_cmp_gt(int64_t x, int64_t y) { return (x >  y); }
static FORCE_INLINE CONSTEXPR int int64_cmp_ge(int64_t x, int64_t y) { return (x >= y); }
static FORCE_INLINE CONSTEXPR int int64_cmp_lt(int64_t x, int64_t y) { return (x <  y); }
static FORCE_INLINE CONSTEXPR int int64_cmp_le(int64_t x, int64_t y) { return (x <= y); }

#ifdef __cplusplus
}
#endif

#endif


code:
#ifndef BGLBUILD_H_INCLUDED_
#define BGLBUILD_H_INCLUDED_

#include "baselayer.h"
#include "build.h"
#include "compat.h"
#include "glad/glad.h"
#include "hash.h"

#ifdef USE_OPENGL

#if !defined GEKKO && !defined EDUKE32_GLES
# define DYNAMIC_GL
# define DYNAMIC_GLEXT
# define USE_GLEXT
#endif

#if defined EDUKE32_GLES
# include "jwzgles.h"
#endif

# ifdef _WIN32
#  define PR_CALLBACK __stdcall
# else
#  define PR_CALLBACK
# endif

#define MAXTEXUNIT GL_TEXTURE16

enum glsamplertype
{
    SAMPLER_NONE,
    SAMPLER_NEAREST_CLAMP,
    SAMPLER_NEAREST_WRAP,
    SAMPLER_LINEAR_CLAMP,
    SAMPLER_LINEAR_WRAP,
    SAMPLER_NEAREST_NEAREST_CLAMP,
    SAMPLER_NEAREST_NEAREST_WRAP,
    SAMPLER_CLAMP,
    SAMPLER_WRAP_T,
    SAMPLER_WRAP_S,
    SAMPLER_WRAP_BOTH,
    SAMPLER_DEPTH,
    NUM_SAMPLERS
};

enum glsamplerflags {
    SAMPLER_NEAREST,
    SAMPLER_CLAMPED,
};

struct BuildGLState
{
    GLuint currentShaderProgramID;
    GLenum currentActiveTexture;

    glsamplertype currentBoundSampler[MAXTEXUNIT - GL_TEXTURE0];

    GLint x, y;
    GLsizei width, height;

    inthashtable_t state[MAXTEXUNIT - GL_TEXTURE0];

    int fullReset;
};

extern BuildGLState gl;
extern GLuint samplerObjectIDs[NUM_SAMPLERS];

#define TEXUNIT_INDEX_FROM_NAME(x) (x - GL_TEXTURE0)
#define ACTIVETEX (gl.currentActiveTexture ? TEXUNIT_INDEX_FROM_NAME(gl.currentActiveTexture) : 0)

extern void buildgl_activeTexture(GLenum texture);
extern void buildgl_bindBuffer(GLenum target, uint32_t bufferID);
extern void buildgl_bindSamplerObject(int texunit, int32_t pth_method);
extern void buildgl_bindTexture(GLenum target, uint32_t textureID);
extern void buildgl_outputDebugMessage(uint8_t severity, const char *format, ...);
extern void buildgl_resetSamplerObjects(void);
extern void buildgl_resetStateAccounting(void);
extern void buildgl_setAlphaFunc(GLenum func, GLfloat ref);
extern void buildgl_setDepthFunc(GLenum func);
extern void buildgl_setDisabled(GLenum key);
extern void buildgl_setEnabled(GLenum key);
extern void buildgl_setPerspective(float fovy, float aspect, float zNear, float zFar);
extern void buildgl_setViewport(GLint x, GLint y, GLsizei width, GLsizei height);
extern void buildgl_uLookAt(vec3f_t v_eye, vec3f_t v_center, vec3f_t v_up);
extern void buildgl_useShaderProgram(uint32_t shaderID);

extern void bind_2d_texture(GLuint texture, int filter);

static FORCE_INLINE void  buildgl_crossproduct(const GLfloat* in_a, const GLfloat* in_b, GLfloat* out)
{
    out[0] = in_a[1] * in_b[2] - in_a[2] * in_b[1];
    out[1] = in_a[2] * in_b[0] - in_a[0] * in_b[2];
    out[2] = in_a[0] * in_b[1] - in_a[1] * in_b[0];
}

static FORCE_INLINE void  buildgl_normalize(float* vec)
{
    float norm = vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2];

    norm = 1.f/Bsqrtf(norm);

    vec[0] *= norm;
    vec[1] *= norm;
    vec[2] *= norm;
}

extern int  buildgl_unprojectMatrixToViewport(vec3f_t win, const float *modelMatrix, const float *projMatrix, const int *viewport, float *objx, float *objy,
                                              float *objz);

extern int32_t r_usesamplerobjects; // FIXME: nasty circular include dependency issue
static FORCE_INLINE bool buildgl_samplerObjectsEnabled(void) { return glinfo.samplerobjects && r_usesamplerobjects; }

//////// dynamic/static API wrapping ////////

#if !defined RENDERTYPESDL && defined _WIN32 && defined DYNAMIC_GL
typedef HGLRC (WINAPI * bwglCreateContextProcPtr)(HDC);
extern bwglCreateContextProcPtr bwglCreateContext;
#define wglCreateContext bwglCreateContext
typedef BOOL (WINAPI * bwglDeleteContextProcPtr)(HGLRC);
extern bwglDeleteContextProcPtr bwglDeleteContext;
#define wglDeleteContext bwglDeleteContext
typedef PROC (WINAPI * bwglGetProcAddressProcPtr)(LPCSTR);
extern bwglGetProcAddressProcPtr bwglGetProcAddress;
#define wglGetProcAddress bwglGetProcAddress
typedef BOOL (WINAPI * bwglMakeCurrentProcPtr)(HDC,HGLRC);
extern bwglMakeCurrentProcPtr bwglMakeCurrent;
#define wglMakeCurrent bwglMakeCurrent

typedef int32_t (WINAPI * bwglChoosePixelFormatProcPtr)(HDC,CONST PIXELFORMATDESCRIPTOR*);
extern bwglChoosePixelFormatProcPtr bwglChoosePixelFormat;
#define wglChoosePixelFormat bwglChoosePixelFormat
typedef int32_t (WINAPI * bwglDescribePixelFormatProcPtr)(HDC,int32_t,UINT,LPPIXELFORMATDESCRIPTOR);
extern bwglDescribePixelFormatProcPtr bwglDescribePixelFormat;
#define wglDescribePixelFormat bwglDescribePixelFormat
typedef int32_t (WINAPI * bwglGetPixelFormatProcPtr)(HDC);
extern bwglGetPixelFormatProcPtr bwglGetPixelFormat;
#define wglGetPixelFormat bwglGetPixelFormat
typedef BOOL (WINAPI * bwglSetPixelFormatProcPtr)(HDC,int32_t,const PIXELFORMATDESCRIPTOR*);
extern bwglSetPixelFormatProcPtr bwglSetPixelFormat;
#define wglSetPixelFormat bwglSetPixelFormat
#endif

//////// glGenTextures/glDeleteTextures debugging ////////
void texdbg_bglGenTextures(GLsizei n, GLuint *textures, const char *srcfn);
void texdbg_bglDeleteTextures(GLsizei n, const GLuint *textures, const char *srcfn);

//#define DEBUG_TEXTURE_NAMES

#if defined DEBUGGINGAIDS && defined DEBUG_TEXTURE_NAMES
# define glGenTextures(numtexs, texnamear) texdbg_bglGenTextures(numtexs, texnamear, __FILE__)
# define glDeleteTextures(numtexs, texnamear) texdbg_bglDeleteTextures(numtexs, texnamear, __FILE__)
#endif
#endif //USE_OPENGL

#if !defined RENDERTYPESDL && defined _WIN32 && defined DYNAMIC_GL
extern char *gldriver;

int32_t loadwgl(const char *driver);
int32_t unloadwgl(void);
#endif

#endif


code:
/*
 * glsurface.h
 *  A 32-bit rendering surface that can quickly blit 8-bit paletted buffers implemented in OpenGL.
 *
 * Copyright � 2018, Alex Dawson. All rights reserved.
 */

#ifndef GLSURFACE_H_
#define GLSURFACE_H_

#include "compat.h"

// Initialize the glsurface with the Software renderer's buffer resolution.
// If the Software renderer's resolution and the actual resolution don't match,
//  glsurface will still render at the full size of the screen.
// If a surface already exists, glsurface_destroy() will be automatically called before re-initializing.
// Returns whether or not the glsurface could be successfully initialized.
bool glsurface_initialize(vec2_t bufferResolution);

// Destroy an existing surface.
void glsurface_destroy();

// Sets the palette to contain the RGBA byte buffer pointed to by pPalette.
// If the surface is not initialized, the function returns immediately.
void glsurface_setPalette(void* pPalette);

// Returns a pointer to the start of the surface's pixel buffer
// Returns NULL if the surface is not initialized.
void* glsurface_getBuffer();

// Returns the resolution of the surface's buffer
vec2_t glsurface_getBufferResolution();

// Blit the surface's pixel buffer to the screen using the palette set with glsurface_setPalette().
// Renders as soon as the data has been uploaded.
// If the surface is not initialized, the function returns immediately.
void glsurface_blitBuffer();

// Rebind texture
void glsurface_refresh();

#endif /* GLSURFACE_H_ */


code:
#ifndef gtkbits_h_
#define gtkbits_h_

#ifdef __cplusplus
extern "C" {
#endif

extern void gtkbuild_init(int32_t *argc, char ***argv);
extern void gtkbuild_exit(int32_t r);
extern int gtkbuild_msgbox(const char *name, const char *msg);
extern int gtkbuild_ynbox(const char *name, const char *msg);

#ifdef __cplusplus
}
#endif

#endif


code:
#include <gdk-pixbuf/gdk-pixdata.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct _EDuke32_GdkPixdata EDuke32_GdkPixdata;
struct _EDuke32_GdkPixdata
{
  guint32 magic;
  gint32  length;
  guint32 pixdata_type;
  guint32 rowstride;
  guint32 width;
  guint32 height;
  const char *pixel_data;
};

extern const EDuke32_GdkPixdata startbanner_pixdata;

#ifdef __cplusplus
}
#endif


code:
#include "gtkpixdata.h"

#define GdkPixdata EDuke32_GdkPixdata


code:
#pragma once

#ifndef hash_h_
#define hash_h_

#include "libdivide.h"

#ifdef __cplusplus
extern "C" {
#endif

// Hash functions
#define DJB_MAGIC 5381u

typedef struct hashitem  // size is 12/24 bytes.
{
    char *string;
    intptr_t key;
    struct hashitem *next;
} hashitem_t;

typedef struct
{
    uint32_t v;
    libdivide::libdivide_u32_t d;
} hashprime_t;

typedef struct
{
    union
    {
        uint32_t    size;
        hashprime_t prime;
    };
    hashitem_t **items;
} hashtable_t;

// djb3 algorithm
static inline uint32_t hash_getcode(const char *s)
{
    uint32_t h = DJB_MAGIC;
    char ch;

    while ((ch = Btolower(*s++)) != '\0')
        h = ((h << 5) + h) ^ ch;

    return h;
}

static FORCE_INLINE uint32_t hash_getbucket(hashtable_t const *t, const char *s)
{
    uint32_t const h = hash_getcode(s);
    return h - libdivide::libdivide_u32_do(h, &t->prime.d) * t->prime.v;
}

void hash_init(hashtable_t *t);
void hash_loop(hashtable_t *t, void (*func)(const char *, intptr_t));
void hash_free(hashtable_t *t);
void hash_add(hashtable_t *t, const char *s, intptr_t key, int32_t replace);
void hash_delete(hashtable_t *t, const char *s);

intptr_t hash_findcase(hashtable_t const *t, char const *s);
intptr_t hash_find(hashtable_t const *t, char const *s);

// Hash functions
// modified for raw binary keys and one big allocation, and maximum find() performance

typedef struct inthashitem
{
    intptr_t key;
    intptr_t value;
    struct inthashitem *collision; // use NULL to signify empty and pointer identity to signify end of linked list
} inthashitem_t;

typedef struct
{
    inthashitem_t *items;
    union
    {
        uint32_t    count;
        hashprime_t prime;
    };
} inthashtable_t;

// djb3 algorithm
static inline uint32_t inthash_getcode(intptr_t key)
{
    uint32_t h = DJB_MAGIC;

    for (auto keybuf = (uint8_t const *) &key, keybuf_end = keybuf + sizeof(key); keybuf < keybuf_end; ++keybuf)
        h = ((h << 5) + h) ^ (uint32_t) *keybuf;

    return h;
}

static FORCE_INLINE uint32_t inthash_getbucket(inthashtable_t const *t, intptr_t key)
{
    uint32_t const h = inthash_getcode(key);
    return h - libdivide::libdivide_u32_do(h, &t->prime.d) * t->prime.v;
}

void inthash_init(inthashtable_t *t);
void inthash_loop(inthashtable_t const *t, void (*func)(intptr_t, intptr_t));
void inthash_free(inthashtable_t *t);
void inthash_add(inthashtable_t *t, intptr_t key, intptr_t value, int32_t replace);
void inthash_delete(inthashtable_t *t, intptr_t key);

intptr_t inthash_find(inthashtable_t const *t, intptr_t key);

// keep the load factor below 0.75 and make sure the size is odd
// ideally we would find the next largest prime number
#define INTHASH_SIZE(size) ((size * 4u / 3u) | 1u)

#ifdef __cplusplus
}
#endif

#endif // hash_h_


code:
#ifndef HIGHTILE_PRIV_H
#define HIGHTILE_PRIV_H

#include "build.h"
#include "palette.h"
#include "vec.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct { uint8_t r, g, b, a; } coltype;
typedef struct { float r, g, b, a; } coltypef;
EXTERN int32_t globalnoeffect;

struct hicskybox_t {
    char *face[6];
};

typedef struct hicreplc_t {
    struct hicreplc_t *next;
    char *filename;
    struct hicskybox_t *skybox;
    vec2f_t scale;
    float alphacut, specpower, specfactor;
    char palnum;
    uint8_t flags, tfn;
} hicreplctyp;

typedef uint16_t polytintflags_t;

typedef struct {
    polytintflags_t f;
    uint8_t r, g, b;
    uint8_t sr, sg, sb;
} polytint_t;

extern polytint_t hictinting[MAXPALOOKUPS];
extern hicreplctyp *hicreplc[MAXTILES];
extern int32_t hicinitcounter;

typedef struct texcachehead_t
{
    char magic[4];	// 'PMST', was 'Polymost'
    int xdim, ydim;	// of image, unpadded
    int flags;		// 1 = !2^x, 2 = has alpha, 4 = lzw compressed
    int quality;    // r_downsize at the time the cache was written
} texcacheheader;

typedef struct texcachepic_t
{
    int size;
    int format;
    int xdim, ydim;	// of mipmap (possibly padded)
    int border, depth;
} texcachepicture;

hicreplctyp * hicfindsubst(int picnum, int palnum, int nozero = 0);
hicreplctyp * hicfindskybox(int picnum, int palnum, int nozero = 0);
void hictinting_applypixcolor(coltype* tcol, uint8_t pal, bool no_rb_swap);

void hicinit(void);
void hicsetpalettetint(int32_t palnum, char r, char g, char b, char sr, char sg, char sb, polytintflags_t effect);
// flags bitset: 1 = don't compress
int32_t hicsetsubsttex(int32_t picnum, int32_t palnum, const char *filen, float alphacut,
                       float xscale, float yscale, float specpower, float specfactor, char flags);
int32_t hicsetskybox(int32_t picnum, int32_t palnum, char *faces[6], int32_t flags);
int32_t hicclearsubst(int32_t picnum, int32_t palnum);

static inline int have_basepal_tint(void)
{
    polytint_t const & tint = hictinting[MAXPALOOKUPS-1];
    return (tint.r != 255 ||
            tint.g != 255 ||
            tint.b != 255);
}

static inline void hictinting_apply(float *color, int32_t palnum)
{
    polytint_t const & tint = hictinting[palnum];
    color[0] *= (float)tint.r * (1.f/255.f);
    color[1] *= (float)tint.g * (1.f/255.f);
    color[2] *= (float)tint.b * (1.f/255.f);
}

static inline void hictinting_apply_ub(uint8_t *color, int32_t palnum)
{
    polytint_t const & tint = hictinting[palnum];
    color[0] = (uint8_t)(color[0] * (float)tint.r * (1.f/255.f));
    color[1] = (uint8_t)(color[1] * (float)tint.g * (1.f/255.f));
    color[2] = (uint8_t)(color[2] * (float)tint.b * (1.f/255.f));
}

static inline void globaltinting_apply(float *color)
{
    color[0] *= (float)globalr * (1.f/255.f);
    color[1] *= (float)globalg * (1.f/255.f);
    color[2] *= (float)globalb * (1.f/255.f);
}

static inline void globaltinting_apply_ub(uint8_t *color)
{
    color[0] = (uint8_t)(color[0] * (float)globalr * (1.f/255.f));
    color[1] = (uint8_t)(color[1] * (float)globalg * (1.f/255.f));
    color[2] = (uint8_t)(color[2] * (float)globalb * (1.f/255.f));
}

// texcacheheader cachead.flags bits
enum
{
    CACHEAD_NONPOW2 = 1,
    CACHEAD_HASALPHA = 2,
    CACHEAD_COMPRESSED = 4,
    CACHEAD_NODOWNSIZE = 8,
    CACHEAD_HASFULLBRIGHT = 16,
    CACHEAD_NPOTWALL = 32,
};

// hicreplctyp hicr->flags bits
enum
{
    HICR_NOTEXCOMPRESS = 1,
    HICR_FORCEFILTER = 2,

    HICR_NODOWNSIZE = 16,
    HICR_ARTIMMUNITY = 32,
    HICR_INDEXED = 64,
    HICR_NOCHT = 128,
};

// hictinting[].f / gloadtile_hi() and mdloadskin() <effect> arg bits
enum
{
    HICTINT_GRAYSCALE = 1,
    HICTINT_INVERT = 2,
    HICTINT_COLORIZE = 4,
    HICTINT_USEONART = 8,
    HICTINT_APPLYOVERPALSWAP = 16,
    HICTINT_APPLYOVERALTPAL = 32,

    HICTINT_BLEND_MULTIPLY = 0<<6,
    HICTINT_BLEND_SCREEN = 1<<6,
    HICTINT_BLEND_OVERLAY = 2<<6,
    HICTINT_BLEND_HARDLIGHT = 3<<6,

    HICTINT_BLENDMASK = 64|128,

    HICTINT_ALWAYSUSEART = 256,
    HICTINT_NOFOGSHADE = 512,

    HICTINT_PRECOMPUTED = HICTINT_COLORIZE | HICTINT_BLENDMASK,
    HICTINT_IN_MEMORY = HICTINT_PRECOMPUTED | HICTINT_GRAYSCALE | HICTINT_INVERT,

    HICTINT_MEMORY_COMBINATIONS = 1<<5,
};

#define GRAYSCALE_COEFF_RED 0.3
#define GRAYSCALE_COEFF_GREEN 0.59
#define GRAYSCALE_COEFF_BLUE 0.11

static inline int32_t hicfxmask(size_t pal)
{
    return globalnoeffect ? 0 : (hictinting[pal].f & HICTINT_IN_MEMORY);
}
static inline int32_t hicfxid(size_t pal)
{
    return globalnoeffect ? 0 : ((hictinting[pal].f & (HICTINT_GRAYSCALE | HICTINT_INVERT | HICTINT_COLORIZE)) | ((hictinting[pal].f & HICTINT_BLENDMASK) << 3));
}

#ifdef __cplusplus
}
#endif

#endif


code:
/* xscreensaver, Copyright (c) 2012 Jamie Zawinski <jwz@jwz.org>
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation.  No representations are made about the suitability of this
 * software for any purpose.  It is provided "as is" without express or
 * implied warranty.
 */

/* A compatibility shim to allow OpenGL 1.3 source code to work in an
   OpenGLES environment, where almost every OpenGL 1.3 function has
   been "deprecated".  See jwzgles.c for details.
 */

#ifndef __JWZGLES_H__
#define __JWZGLES_H__

#ifndef HAVE_JWZGLES
# error: do not include this without HAVE_JWZGLES
#endif

#include "jwzglesI.h"

/* These are the OpenGL 1.3 functions that are not present in OpenGLES 1.
   As you can see from the length of this list, OpenGL and OpenGLES have
   almost nothing to do with each other.  To claim that GLES is a dialect
   of OpenGL is absurd -- English and Latin have more in common!
 */

#define glAccum				jwzgles_glAccum
#define glAntialiasing			jwzgles_glAntialiasing
#define glAreTexturesResident		jwzgles_glAreTexturesResident
#define glArrayElement			jwzgles_glArrayElement
#define glBegin				jwzgles_glBegin
#define glBitmap			jwzgles_glBitmap
#define glBlendColor			jwzgles_glBlendColor
#define glBlendEquation			jwzgles_glBlendEquation
#define glCallList			jwzgles_glCallList
#define glCallLists			jwzgles_glCallLists
#define glClearAccum			jwzgles_glClearAccum
#define glClearDepth			jwzgles_glClearDepth
#define glClearIndex			jwzgles_glClearIndex
#define glClipPlane			jwzgles_glClipPlane
#define glColor3b			jwzgles_glColor3b
#define glColor3bv			jwzgles_glColor3bv
#define glColor3d			jwzgles_glColor3f
#define glColor3dv			jwzgles_glColor3dv
#define glColor3f			jwzgles_glColor3f
#define glColor3fv			jwzgles_glColor3fv
#define glColor3i			jwzgles_glColor3i
#define glColor3iv			jwzgles_glColor3iv
#define glColor3s			jwzgles_glColor3s
#define glColor3sv			jwzgles_glColor3sv
#define glColor3ub			jwzgles_glColor3ub
#define glColor3ubv			jwzgles_glColor3ubv
#define glColor3ui			jwzgles_glColor3ui
#define glColor3uiv			jwzgles_glColor3uiv
#define glColor3us			jwzgles_glColor3us
#define glColor3usv			jwzgles_glColor3usv
#define glColor4b			jwzgles_glColor4b
#define glColor4bv			jwzgles_glColor4bv
#define glColor4d			jwzgles_glColor4d
#define glColor4dv			jwzgles_glColor4dv
#define glColor4fv			jwzgles_glColor4fv
#define glColor4i			jwzgles_glColor4i
#define glColor4iv			jwzgles_glColor4iv
#define glColor4s			jwzgles_glColor4s
#define glColor4sv			jwzgles_glColor4sv
#define glColor4ub			jwzgles_glColor4ub
#define glColor4ubv			jwzgles_glColor4ubv
#define glColor4ui			jwzgles_glColor4ui
#define glColor4uiv			jwzgles_glColor4uiv
#define glColor4us			jwzgles_glColor4us
#define glColor4usv			jwzgles_glColor4usv
#define glColorMaterial			jwzgles_glColorMaterial
#define glColorSubTable			jwzgles_glColorSubTable
#define glColorTable			jwzgles_glColorTable
#define glColorTableParameter		jwzgles_glColorTableParameter
#define glColorTableParameterfv		jwzgles_glColorTableParameterfv
#define glColorub			jwzgles_glColorub
#define glColorui			jwzgles_glColorui
#define glColorus			jwzgles_glColorus
#define glCompressedTexImage		jwzgles_glCompressedTexImage
#define glCompressedTexImage1D		jwzgles_glCompressedTexImage1D
#define glCompressedTexImage3D		jwzgles_glCompressedTexImage3D
#define glCompressedTexSubImage1D	jwzgles_glCompressedTexSubImage1D
#define glCompressedTexSubImage3D	jwzgles_glCompressedTexSubImage3D
#define glConvolutionFilter1D		jwzgles_glConvolutionFilter1D
#define glConvolutionFilter2D		jwzgles_glConvolutionFilter2D
#define glConvolutionParameter		jwzgles_glConvolutionParameter
#define glConvolutionParameterfv	jwzgles_glConvolutionParameterfv
#define glConvolutionParameteriv	jwzgles_glConvolutionParameteriv
#define glCopyColorSubTable		jwzgles_glCopyColorSubTable
#define glCopyColorTable		jwzgles_glCopyColorTable
#define glCopyConvolutionFilter1D	jwzgles_glCopyConvolutionFilter1D
#define glCopyConvolutionFilter2D	jwzgles_glCopyConvolutionFilter2D
#define glCopyPixels			jwzgles_glCopyPixels
#define glCopyTexImage1D		jwzgles_glCopyTexImage1D
#define glCopyTexImage3D		jwzgles_glCopyTexImage3D
#define glCopyTexSubImage1D		jwzgles_glCopyTexSubImage1D
#define glCopyTexSubImage3D		jwzgles_glCopyTexSubImage3D
#define glDeleteLists			jwzgles_glDeleteLists
#define glDrawBuffer			jwzgles_glDrawBuffer
#define glDrawPixels			jwzgles_glDrawPixels
#define glDrawRangeElements		jwzgles_glDrawRangeElements
#define glEdgeFlag			jwzgles_glEdgeFlag
#define glEdgeFlagPointer		jwzgles_glEdgeFlagPointer
#define glEdgeFlagv			jwzgles_glEdgeFlagv
#define glEnd				jwzgles_glEnd
#define glEndList			jwzgles_glEndList
#define glEvalCoord1d			jwzgles_glEvalCoord1d
#define glEvalCoord1dv			jwzgles_glEvalCoord1dv
#define glEvalCoord1f			jwzgles_glEvalCoord1f
#define glEvalCoord1fv			jwzgles_glEvalCoord1fv
#define glEvalCoord2d			jwzgles_glEvalCoord2d
#define glEvalCoord2dv			jwzgles_glEvalCoord2dv
#define glEvalCoord2f			jwzgles_glEvalCoord2f
#define glEvalCoord2fv			jwzgles_glEvalCoord2fv
#define glEvalMesh1			jwzgles_glEvalMesh1
#define glEvalMesh2			jwzgles_glEvalMesh2
#define glEvalPoint1			jwzgles_glEvalPoint1
#define glEvalPoint2			jwzgles_glEvalPoint2
#define glFeedbackBuffer		jwzgles_glFeedbackBuffer
#define glFogi				jwzgles_glFogi
#define glFogiv				jwzgles_glFogiv
#define glFrustum			jwzgles_glFrustum
#define glGenLists			jwzgles_glGenLists
#define glGet				jwzgles_glGet
#define glGetBooleanv			jwzgles_glGetBooleanv
#define glGetClipPlane			jwzgles_glGetClipPlane
#define glGetColorTable			jwzgles_glGetColorTable
#define glGetColorTableParameter	jwzgles_glGetColorTableParameter
#define glGetCompressedTexImage		jwzgles_glGetCompressedTexImage
#define glGetConvolutionFilter		jwzgles_glGetConvolutionFilter
#define glGetConvolutionParameter	jwzgles_glGetConvolutionParameter
#define glGetConvolutionParameteriv	jwzgles_glGetConvolutionParameteriv
#define glGetDoublev			jwzgles_glGetDoublev
#define glGetFloatv			jwzgles_glGetFloatv
#define glGetHistogram			jwzgles_glGetHistogram
#define glGetHistogramParameter		jwzgles_glGetHistogramParameter
#define glGetLightfv			jwzgles_glGetLightfv
#define glGetLightiv			jwzgles_glGetLightiv
#define glGetMapdv			jwzgles_glGetMapdv
#define glGetMapfv			jwzgles_glGetMapfv
#define glGetMapiv			jwzgles_glGetMapiv
#define glGetMaterialfv			jwzgles_glGetMaterialfv
#define glGetMaterialiv			jwzgles_glGetMaterialiv
#define glGetPixelMapfv			jwzgles_glGetPixelMapfv
#define glGetPixelMapuiv		jwzgles_glGetPixelMapuiv
#define glGetPixelMapusv		jwzgles_glGetPixelMapusv
#define glGetPointerv			jwzgles_glGetPointerv
#define glGetPolygonStipple		jwzgles_glGetPolygonStipple
#define glGetSeparableFilter		jwzgles_glGetSeparableFilter
#define glGetTexEnvfv			jwzgles_glGetTexEnvfv
#define glGetTexEnviv			jwzgles_glGetTexEnviv
#define glGetTexGendv			jwzgles_glGetTexGendv
#define glGetTexGenfv			jwzgles_glGetTexGenfv
#define glGetTexGeniv			jwzgles_glGetTexGeniv
#define glGetTexImage			jwzgles_glGetTexImage
#define glGetTexImage1D			jwzgles_glGetTexImage1D
#define glGetTexImage2D			jwzgles_glGetTexImage2D
#define glGetTexImage3D			jwzgles_glGetTexImage3D
#define glGetTexLevelParameterfv	jwzgles_glGetTexLevelParameterfv
//#define glGetTexLevelParameteriv	jwzgles_glGetTexLevelParameteriv
#define glGetTexParameterfv		jwzgles_glGetTexParameterfv
//#define glGetTexParameteriv		jwzgles_glGetTexParameteriv
#define glHistogram			jwzgles_glHistogram
#define glIndex				jwzgles_glIndex
#define glIndexMask			jwzgles_glIndexMask
#define glIndexPointer			jwzgles_glIndexPointer
#define glIndexd			jwzgles_glIndexd
#define glIndexdv			jwzgles_glIndexdv
#define glIndexf			jwzgles_glIndexf
#define glIndexfv			jwzgles_glIndexfv
/*#define glIndexi			jwzgles_glIndexi*/
#define glIndexiv			jwzgles_glIndexiv
#define glIndexs			jwzgles_glIndexs
#define glIndexsv			jwzgles_glIndexsv
#define glIndexub			jwzgles_glIndexub
#define glIndexubv			jwzgles_glIndexubv
#define glInitNames			jwzgles_glInitNames
#define glInterleavedArrays		jwzgles_glInterleavedArrays
#define glIsEnabled			jwzgles_glIsEnabled
#define glIsList			jwzgles_glIsList
#define glIsTexture			jwzgles_glIsTexture
#define glLightModeli			jwzgles_glLightModeli
#define glLightModeliv			jwzgles_glLightModeliv
#define glLighti			jwzgles_glLighti
#define glLightiv			jwzgles_glLightiv
#define glLightf			jwzgles_glLightf
#define glLightfv			jwzgles_glLightfv
#define glLineStipple			jwzgles_glLineStipple
#define glListBase			jwzgles_glListBase
#define glLoadMatrix			jwzgles_glLoadMatrix
#define glLoadName			jwzgles_glLoadName
#define glLoadTransposeMatrix		jwzgles_glLoadTransposeMatrix
#define glLoadTransposeMatrixf		jwzgles_glLoadTransposeMatrixf
#define glMap1d				jwzgles_glMap1d
#define glMap1f				jwzgles_glMap1f
#define glMap2d				jwzgles_glMap2d
#define glMap2f				jwzgles_glMap2f
#define glMapGrid1d			jwzgles_glMapGrid1d
#define glMapGrid1f			jwzgles_glMapGrid1f
#define glMapGrid2d			jwzgles_glMapGrid2d
#define glMapGrid2f			jwzgles_glMapGrid2f
#define glMateriali			jwzgles_glMateriali
#define glMaterialiv			jwzgles_glMaterialiv
#define glMultTransposeMatrix		jwzgles_glMultTransposeMatrix
#define glMultTransposeMatrixf		jwzgles_glMultTransposeMatrixf
#define glNewList			jwzgles_glNewList
#define glNormal3b			jwzgles_glNormal3b
#define glNormal3bv			jwzgles_glNormal3bv
#define glNormal3d			jwzgles_glNormal3f
#define glNormal3dv			jwzgles_glNormal3dv
#define glNormal3fv			jwzgles_glNormal3fv
#define glNormal3i			jwzgles_glNormal3i
#define glNormal3iv			jwzgles_glNormal3iv
#define glNormal3s			jwzgles_glNormal3s
#define glNormal3sv			jwzgles_glNormal3sv
#define glOrtho				jwzgles_glOrtho
#define glPassThrough			jwzgles_glPassThrough
#define glPixelMapfv			jwzgles_glPixelMapfv
#define glPixelMapuiv			jwzgles_glPixelMapuiv
#define glPixelMapusv			jwzgles_glPixelMapusv
#define glPixelStoref			jwzgles_glPixelStoref
#define glPixelTransferf		jwzgles_glPixelTransferf
#define glPixelTransferi		jwzgles_glPixelTransferi
#define glPixelZoom			jwzgles_glPixelZoom
#define glPolygonMode			jwzgles_glPolygonMode
#define glPolygonStipple		jwzgles_glPolygonStipple
#define glPopAttrib			jwzgles_glPopAttrib
#define glPopClientAttrib		jwzgles_glPopClientAttrib
#define glPopName			jwzgles_glPopName
#define glPrioritizeTextures		jwzgles_glPrioritizeTextures
#define glPushAttrib			jwzgles_glPushAttrib
#define glPushClientAttrib		jwzgles_glPushClientAttrib
#define glPushName			jwzgles_glPushName
#define glRasterPos2d			jwzgles_glRasterPos2d
#define glRasterPos2dv			jwzgles_glRasterPos2dv
#define glRasterPos2f			jwzgles_glRasterPos2f
#define glRasterPos2fv			jwzgles_glRasterPos2fv
#define glRasterPos2i			jwzgles_glRasterPos2i
#define glRasterPos2iv			jwzgles_glRasterPos2iv
#define glRasterPos2s			jwzgles_glRasterPos2s
#define glRasterPos2sv			jwzgles_glRasterPos2sv
#define glRasterPos3d			jwzgles_glRasterPos3d
#define glRasterPos3dv			jwzgles_glRasterPos3dv
#define glRasterPos3f			jwzgles_glRasterPos3f
#define glRasterPos3fv			jwzgles_glRasterPos3fv
#define glRasterPos3i			jwzgles_glRasterPos3i
#define glRasterPos3iv			jwzgles_glRasterPos3iv
#define glRasterPos3s			jwzgles_glRasterPos3s
#define glRasterPos3sv			jwzgles_glRasterPos3sv
#define glRasterPos4d			jwzgles_glRasterPos4d
#define glRasterPos4dv			jwzgles_glRasterPos4dv
#define glRasterPos4f			jwzgles_glRasterPos4f
#define glRasterPos4fv			jwzgles_glRasterPos4fv
//#define glRasterPos4i			jwzgles_glRasterPos4i
#define glRasterPos4iv			jwzgles_glRasterPos4iv
#define glRasterPos4s			jwzgles_glRasterPos4s
#define glRasterPos4sv			jwzgles_glRasterPos4sv
#define glReadBuffer			jwzgles_glReadBuffer
#define glRectd				jwzgles_glRectf
#define glRectdv			jwzgles_glRectdv
#define glRectf				jwzgles_glRectf
#define glRectfv			jwzgles_glRectfv
#define glRecti				jwzgles_glRecti
#define glRectiv			jwzgles_glRectiv
#define glRects				jwzgles_glRects
#define glRectsv			jwzgles_glRectsv
#define glRenderMode			jwzgles_glRenderMode
#define glResetHistogram		jwzgles_glResetHistogram
#define glResetMinmax			jwzgles_glResetMinmax
#define glRotated			jwzgles_glRotated
#define glScaled			jwzgles_glScalef
#define glSelectBuffer			jwzgles_glSelectBuffer
#define glSeparableFilter2D		jwzgles_glSeparableFilter2D
#define glTexCoord1d			jwzgles_glTexCoord1d
#define glTexCoord1dv			jwzgles_glTexCoord1dv
#define glTexCoord1f			jwzgles_glTexCoord1f
#define glTexCoord1fv			jwzgles_glTexCoord1fv
#define glTexCoord1i			jwzgles_glTexCoord1i
#define glTexCoord1iv			jwzgles_glTexCoord1iv
#define glTexCoord1s			jwzgles_glTexCoord1s
#define glTexCoord1sv			jwzgles_glTexCoord1sv
#define glTexCoord2d			jwzgles_glTexCoord2f
#define glTexCoord2dv			jwzgles_glTexCoord2dv
#define glTexCoord2f			jwzgles_glTexCoord2f
#define glTexCoord2fv			jwzgles_glTexCoord2fv
#define glTexCoord2i			jwzgles_glTexCoord2i
#define glTexCoord2iv			jwzgles_glTexCoord2iv
#define glTexCoord2s			jwzgles_glTexCoord2s
#define glTexCoord2sv			jwzgles_glTexCoord2sv
#define glTexCoord3d			jwzgles_glTexCoord3d
#define glTexCoord3dv			jwzgles_glTexCoord3dv
#define glTexCoord3f			jwzgles_glTexCoord3f
#define glTexCoord3fv			jwzgles_glTexCoord3fv
#define glTexCoord3i			jwzgles_glTexCoord3i
#define glTexCoord3iv			jwzgles_glTexCoord3iv
#define glTexCoord3s			jwzgles_glTexCoord3s
#define glTexCoord3sv			jwzgles_glTexCoord3sv
#define glTexCoord4d			jwzgles_glTexCoord4d
#define glTexCoord4dv			jwzgles_glTexCoord4dv
#define glTexCoord4f			jwzgles_glTexCoord4f
#define glTexCoord4fv			jwzgles_glTexCoord4fv
#define glTexCoord4i			jwzgles_glTexCoord4i
#define glTexCoord4iv			jwzgles_glTexCoord4iv
#define glTexCoord4s			jwzgles_glTexCoord4s
#define glTexCoord4sv			jwzgles_glTexCoord4sv
#define glTexEnvi			jwzgles_glTexEnvi
#define glTexEnviv			jwzgles_glTexEnviv
#define glTexGend			jwzgles_glTexGend
#define glTexGendv			jwzgles_glTexGendv
#define glTexGenf			jwzgles_glTexGenf
#define glTexGenfv			jwzgles_glTexGenfv
#define glTexGeni			jwzgles_glTexGeni
#define glTexGeniv			jwzgles_glTexGeniv
#define glTexImage1D			jwzgles_glTexImage1D
#define glTexImage3D			jwzgles_glTexImage3D
#define glTexParameterfv		jwzgles_glTexParameterfv
#define glTexParameteri			jwzgles_glTexParameteri
#define glTexParameteriv		jwzgles_glTexParameteriv
#define glTexSubImage1D			jwzgles_glTexSubImage1D
#define glTexSubImage3D			jwzgles_glTexSubImage3D
#define glTranslated			jwzgles_glTranslatef
#define glVertex2d			jwzgles_glVertex2d
#define glVertex2dv			jwzgles_glVertex2dv
#define glVertex2f			jwzgles_glVertex2f
#define glVertex2fv			jwzgles_glVertex2fv
#define glVertex2i			jwzgles_glVertex2i
#define glVertex2iv			jwzgles_glVertex2iv
#define glVertex2s			jwzgles_glVertex2s
#define glVertex2sv			jwzgles_glVertex2sv
#define glVertex3d			jwzgles_glVertex3f
#define glVertex3dv			jwzgles_glVertex3dv
#define glVertex3f			jwzgles_glVertex3f
#define glVertex3fv			jwzgles_glVertex3fv
#define glVertex3i			jwzgles_glVertex3i
#define glVertex3iv			jwzgles_glVertex3iv
#define glVertex3s			jwzgles_glVertex3s
#define glVertex3sv			jwzgles_glVertex3sv
#define glVertex4d			jwzgles_glVertex4d
#define glVertex4dv			jwzgles_glVertex4dv
#define glVertex4f			jwzgles_glVertex4f
#define glVertex4fv			jwzgles_glVertex4fv
#define glVertex4i			jwzgles_glVertex4i
#define glVertex4iv			jwzgles_glVertex4iv
#define glVertex4s			jwzgles_glVertex4s
#define glVertex4sv			jwzgles_glVertex4sv

#define gluOrtho2D(L,R,B,T)		glOrtho(L,R,B,T,-1,1)
#define gluPerspective			jwzgles_gluPerspective

#define glXChooseVisual			jwzgles_glXChooseVisual
#define glXCopyContext			jwzgles_glXCopyContext
/*#define glXCreateContext		jwzgles_glXCreateContext*/
#define glXCreateGLXPixmap		jwzgles_glXCreateGLXPixmap
#define glXDestroyContext		jwzgles_glXDestroyContext
#define glXDestroyGLXPixmap		jwzgles_glXDestroyGLXPixmap
#define glXFreeContextEXT		jwzgles_glXFreeContextEXT
#define glXGetClientString		jwzgles_glXGetClientString
#define glXGetConfig			jwzgles_glXGetConfig
#define glXGetContextIDEXT		jwzgles_glXGetContextIDEXT
#define glXGetCurrentContext		jwzgles_glXGetCurrentContext
#define glXGetCurrentDisplay		jwzgles_glXGetCurrentDisplay
#define glXGetCurrentDrawable		jwzgles_glXGetCurrentDrawable
#define glXImportContextEXT		jwzgles_glXImportContextEXT
#define glXIntro			jwzgles_glXIntro
#define glXIsDirect			jwzgles_glXIsDirect
/*#define glXMakeCurrent		jwzgles_glXMakeCurrent*/
#define glXQueryContextInfoEXT		jwzgles_glXQueryContextInfoEXT
#define glXQueryExtension		jwzgles_glXQueryExtension
#define glXQueryExtensionsString	jwzgles_glXQueryExtensionsString
#define glXQueryServerString		jwzgles_glXQueryServerString
#define glXQueryVersion			jwzgles_glXQueryVersion
/*#define glXSwapBuffers		jwzgles_glXSwapBuffers*/
#define glXUseXFont			jwzgles_glXUseXFont
#define glXWaitGL			jwzgles_glXWaitGL
#define glXWaitX			jwzgles_glXWaitX

#define gluBeginCurve			jwzgles_gluBeginCurve
#define gluBeginPolygon			jwzgles_gluBeginPolygon
#define gluBeginSurface			jwzgles_gluBeginSurface
#define gluBeginTrim			jwzgles_gluBeginTrim
#define gluBuild1DMipmaps		jwzgles_gluBuild1DMipmaps
#define gluBuild2DMipmaps		jwzgles_gluBuild2DMipmaps
#define gluCylinder			jwzgles_gluCylinder
#define gluDeleteNurbsRenderer		jwzgles_gluDeleteNurbsRenderer
#define gluDeleteQuadric		jwzgles_gluDeleteQuadric
#define gluDeleteTess			jwzgles_gluDeleteTess
#define gluDisk				jwzgles_gluDisk
#define gluEndCurve			jwzgles_gluEndCurve
#define gluEndPolygon			jwzgles_gluEndPolygon
#define gluEndSurface			jwzgles_gluEndSurface
#define gluEndTrim			jwzgles_gluEndTrim
#define gluErrorString			jwzgles_gluErrorString
#define gluGetNurbsProperty		jwzgles_gluGetNurbsProperty
#define gluGetString			jwzgles_gluGetString
#define gluGetTessProperty		jwzgles_gluGetTessProperty
#define gluLoadSamplingMatrices		jwzgles_gluLoadSamplingMatrices
#define gluLookAt			jwzgles_gluLookAt
#define gluNewNurbsRenderer		jwzgles_gluNewNurbsRenderer
#define gluNewQuadric			jwzgles_gluNewQuadric
#define gluNewTess			jwzgles_gluNewTess
#define gluNextContour			jwzgles_gluNextContour
#define gluNurbsCallback		jwzgles_gluNurbsCallback
#define gluNurbsCurve			jwzgles_gluNurbsCurve
#define gluNurbsProperty		jwzgles_gluNurbsProperty
#define gluNurbsSurface			jwzgles_gluNurbsSurface
#define gluPartialDisk			jwzgles_gluPartialDisk
#define gluPickMatrix			jwzgles_gluPickMatrix
#define gluProject			jwzgles_gluProject
#define gluPwlCurve			jwzgles_gluPwlCurve
#define gluQuadricCallback		jwzgles_gluQuadricCallback
#define gluQuadricDrawStyle		jwzgles_gluQuadricDrawStyle
#define gluQuadricNormals		jwzgles_gluQuadricNormals
#define gluQuadricOrientation		jwzgles_gluQuadricOrientation
#define gluQuadricTexture		jwzgles_gluQuadricTexture
#define gluScaleImage			jwzgles_gluScaleImage
#define gluSphere			jwzgles_gluSphere
#define gluTessBeginContour		jwzgles_gluTessBeginContour
#define gluTessBeginPolygon		jwzgles_gluTessBeginPolygon
#define gluTessCallback			jwzgles_gluTessCallback
#define gluTessEndPolygon		jwzgles_gluTessEndPolygon
#define gluTessEndContour		jwzgles_gluTessEndContour
#define gluTessNormal			jwzgles_gluTessNormal
#define gluTessProperty			jwzgles_gluTessProperty
#define gluTessVertex			jwzgles_gluTessVertex
#define gluUnProject			jwzgles_gluUnProject

/* These functions are present in both OpenGL 1.1 and in OpenGLES 1,
   but are allowed within glNewList/glEndList, so we must wrap them
   to allow them to be recorded.
 */
#define glActiveTexture			jwzgles_glActiveTexture
#define glAlphaFunc			jwzgles_glAlphaFunc
#define glBindTexture			jwzgles_glBindTexture
#define glBlendFunc			jwzgles_glBlendFunc
#define glClear				jwzgles_glClear
#define glClearColor			jwzgles_glClearColor
#define glClearStencil			jwzgles_glClearStencil
#define glColor4f			jwzgles_glColor4f
#define glColorMask			jwzgles_glColorMask
#define glColorPointer			jwzgles_glColorPointer
#define glCompressedTexImage2D		jwzgles_glCompressedTexImage2D
#define glCompressedTexSubImage2D	jwzgles_glCompressedTexSubImage2D
#define glCopyTexImage2D		jwzgles_glCopyTexImage2D
#define glCopyTexSubImage2D		jwzgles_glCopyTexSubImage2D
#define glCullFace			jwzgles_glCullFace
#define glDeleteTextures		jwzgles_glDeleteTextures
#define glDepthFunc			jwzgles_glDepthFunc
#define glDepthMask			jwzgles_glDepthMask
#define glDisable			jwzgles_glDisable
#define glDrawArrays			jwzgles_glDrawArrays
#define glDrawElements			jwzgles_glDrawElements
#define glEnable			jwzgles_glEnable
#define glFinish			jwzgles_glFinish
#define glFlush				jwzgles_glFlush
#define glFogf				jwzgles_glFogf
#define glFogfv				jwzgles_glFogfv
#define glFrontFace			jwzgles_glFrontFace
#define glGenTextures			jwzgles_glGenTextures
#define glGetIntegerv			jwzgles_glGetIntegerv
#define glHint				jwzgles_glHint
#define glLightModelf			jwzgles_glLightModelf
#define glLightModelfv			jwzgles_glLightModelfv
#define glLightf			jwzgles_glLightf
#define glLightfv			jwzgles_glLightfv
#define glLineWidth			jwzgles_glLineWidth
#define glLoadIdentity			jwzgles_glLoadIdentity
#define glLoadMatrixf			jwzgles_glLoadMatrixf
#define glLogicOp			jwzgles_glLogicOp
#define glMaterialf			jwzgles_glMaterialf
#define glMateriali			jwzgles_glMateriali
#define glMaterialfv			jwzgles_glMaterialfv
#define glMaterialiv			jwzgles_glMaterialiv
#define glMatrixMode			jwzgles_glMatrixMode
#define glMultMatrixf			jwzgles_glMultMatrixf
#define glNormal3f			jwzgles_glNormal3f
#define glNormalPointer			jwzgles_glNormalPointer
#define glPixelStorei			jwzgles_glPixelStorei
#define glPointSize			jwzgles_glPointSize
#define glPolygonOffset			jwzgles_glPolygonOffset
#define glPopMatrix			jwzgles_glPopMatrix
#define glPushMatrix			jwzgles_glPushMatrix
#define glReadPixels			jwzgles_glReadPixels
#define glRotatef			jwzgles_glRotatef
#define glScalef			jwzgles_glScalef
#define glSampleCoverage		jwzgles_glSampleCoverage
#define glScissor			jwzgles_glScissor
#define glShadeModel			jwzgles_glShadeModel
#define glStencilFunc			jwzgles_glStencilFunc
#define glStencilMask			jwzgles_glStencilMask
#define glStencilOp			jwzgles_glStencilOp
#define glTexCoordPointer		jwzgles_glTexCoordPointer
#define glTexEnvf			jwzgles_glTexEnvf
#define glTexEnvfv			jwzgles_glTexEnvfv
#define glTexImage2D			jwzgles_glTexImage2D
#define glTexParameterf			jwzgles_glTexParameterf
#define glTexSubImage2D			jwzgles_glTexSubImage2D
#define glTranslatef			jwzgles_glTranslatef
#define glVertexPointer			jwzgles_glVertexPointer
#define glViewport			jwzgles_glViewport
#define glEnableClientState		jwzgles_glEnableClientState
#define glDisableClientState		jwzgles_glDisableClientState
#define glClipPlane			jwzgles_glClipPlane

#define glGetError          jwzgles_glGetError
#define glGetString          jwzgles_glGetString

#endif /* __JWZGLES_H__ */


code:
/* xscreensaver, Copyright (c) 2012-2014 Jamie Zawinski <jwz@jwz.org>
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation.  No representations are made about the suitability of this
 * software for any purpose.  It is provided "as is" without express or
 * implied warranty.
 */

/* A compatibility shim to allow OpenGL 1.3 source code to work in an
   OpenGLES environment, where almost every OpenGL 1.3 function has
   been "deprecated".  See jwzgles.c for details.
 */

#ifndef __JWZGLES_I_H__
#define __JWZGLES_I_H__

#ifdef __cplusplus
extern "C" {
#endif

#ifdef GL_VERSION_ES_CM_1_0  /* compiling against OpenGLES 1.x */

/* These OpenGL 1.3 constants are not present in OpenGLES 1.
   Fortunately, it looks like they didn't re-use any of the numbers,
   so we can just keep using the OpenGL 1.3 values.  I'm actually
   kind of shocked that the GLES folks passed up that opportunity
   for further clusterfuckery.
 */
# define GLdouble double

# define GL_ACCUM_BUFFER_BIT			0x00000200
# undef GL_ALL_ATTRIB_BITS
# define GL_ALL_ATTRIB_BITS			0x000FFFFF
# define GL_AUTO_NORMAL				0x0D80
# define GL_BLEND_SRC_ALPHA			0x80CB
# define GL_C3F_V3F				0x2A24
# define GL_C4F_N3F_V3F				0x2A26
# define GL_C4UB_V2F				0x2A22
# define GL_C4UB_V3F				0x2A23
# define GL_CLAMP				0x2900
# define GL_COLOR_BUFFER_BIT			0x00004000
# define GL_COLOR_MATERIAL_FACE			0x0B55
# define GL_COLOR_MATERIAL_PARAMETER		0x0B56
# define GL_COMPILE				0x1300
# define GL_CURRENT_BIT				0x00000001
# define GL_DEPTH_BUFFER_BIT			0x00000100
# define GL_DOUBLEBUFFER			0x0C32
# define GL_ENABLE_BIT				0x00002000
# define GL_EVAL_BIT				0x00010000
# define GL_EYE_LINEAR				0x2400
# define GL_EYE_PLANE				0x2502
# define GL_FEEDBACK				0x1C01
# define GL_FILL				0x1B02
# define GL_FOG_BIT				0x00000080
# define GL_HINT_BIT				0x00008000
# define GL_INTENSITY				0x8049
# define GL_LIGHTING_BIT			0x00000040
# define GL_LIGHT_MODEL_COLOR_CONTROL		0x81F8
# define GL_LIGHT_MODEL_LOCAL_VIEWER		0x0B51
# define GL_LINE				0x1B01
# define GL_LINE_BIT				0x00000004
# define GL_LIST_BIT				0x00020000
# define GL_N3F_V3F				0x2A25
# define GL_OBJECT_LINEAR			0x2401
# define GL_OBJECT_PLANE			0x2501
# define GL_PIXEL_MODE_BIT			0x00000020
# define GL_POINT_BIT				0x00000002
# define GL_POLYGON				0x0009
# define GL_POLYGON_BIT				0x00000008
# define GL_POLYGON_MODE			0x0B40
# define GL_POLYGON_SMOOTH			0x0B41
# define GL_POLYGON_STIPPLE			0x0B42
# define GL_POLYGON_STIPPLE_BIT			0x00000010
# define GL_Q					0x2003
# define GL_QUADS				0x0007
# define GL_QUAD_STRIP				0x0008
# define GL_R					0x2002
# define GL_RENDER				0x1C00
# define GL_RGBA_MODE				0x0C31
# define GL_S					0x2000
# define GL_SCISSOR_BIT				0x00080000
# define GL_SELECT				0x1C02
# define GL_SEPARATE_SPECULAR_COLOR		0x81FA
# define GL_SINGLE_COLOR			0x81F9
# define GL_SPHERE_MAP				0x2402
# define GL_STENCIL_BUFFER_BIT			0x00000400
# define GL_T					0x2001
# define GL_T2F_C3F_V3F				0x2A2A
# define GL_T2F_C4F_N3F_V3F			0x2A2C
# define GL_T2F_C4UB_V3F			0x2A29
# define GL_T2F_N3F_V3F				0x2A2B
# define GL_T2F_V3F				0x2A27
# define GL_T4F_C4F_N3F_V4F			0x2A2D
# define GL_T4F_V4F				0x2A28
# define GL_TEXTURE_1D				0x0DE0
# define GL_TEXTURE_ALPHA_SIZE			0x805F
# define GL_TEXTURE_BIT				0x00040000
# define GL_TEXTURE_BLUE_SIZE			0x805E
# define GL_TEXTURE_BORDER			0x1005
# define GL_TEXTURE_BORDER_COLOR		0x1004
# define GL_TEXTURE_COMPONENTS			0x1003
# define GL_TEXTURE_GEN_MODE			0x2500
# define GL_TEXTURE_GEN_Q			0x0C63
# define GL_TEXTURE_GEN_R			0x0C62
# define GL_TEXTURE_GEN_S			0x0C60
# define GL_TEXTURE_GEN_T			0x0C61
# define GL_TEXTURE_GREEN_SIZE			0x805D
# define GL_TEXTURE_HEIGHT			0x1001
# define GL_TEXTURE_INTENSITY_SIZE		0x8061
# define GL_TEXTURE_LUMINANCE_SIZE		0x8060
# define GL_TEXTURE_RED_SIZE			0x805C
# define GL_TEXTURE_WIDTH			0x1000
# define GL_TRANSFORM_BIT			0x00001000
# define GL_UNPACK_ROW_LENGTH			0x0CF2
# define GL_UNSIGNED_INT_8_8_8_8_REV		0x8367
# define GL_V2F					0x2A20
# define GL_V3F					0x2A21
# define GL_VIEWPORT_BIT			0x00000800
# define GL_INT					0x1404
# define GL_DOUBLE				0x140A

#endif

extern void jwzgles_reset (void);

/* Prototypes for the things re-implemented in jwzgles.c
 */

extern int  jwzgles_glGenLists (int n);
extern void jwzgles_glNewList (int id, int mode);
extern void jwzgles_glEndList (void);
extern void jwzgles_glDeleteLists (int list, int range);
extern void jwzgles_glBegin (int mode);
extern void jwzgles_glNormal3fv (const GLfloat *);
extern void jwzgles_glNormal3f (GLfloat x, GLfloat y, GLfloat z);
extern void jwzgles_glTexCoord1f (GLfloat s);
extern void jwzgles_glTexCoord2fv (const GLfloat *);
extern void jwzgles_glTexCoord2f (GLfloat s, GLfloat t);
extern void jwzgles_glTexCoord2i (GLint s, GLint t);
extern void jwzgles_glTexCoord3fv (const GLfloat *);
extern void jwzgles_glTexCoord3f (GLfloat s, GLfloat t, GLfloat r);
extern void jwzgles_glTexCoord4fv (const GLfloat *);
extern void jwzgles_glTexCoord4f (GLfloat s, GLfloat t, GLfloat r, GLfloat q);
extern void jwzgles_glVertex2f (GLfloat x, GLfloat y);
extern void jwzgles_glVertex2fv (const GLfloat *);
extern void jwzgles_glVertex2i (GLint x, GLint y);
extern void jwzgles_glVertex3f (GLfloat x, GLfloat y, GLfloat z);
extern void jwzgles_glVertex3dv (const GLdouble *);
extern void jwzgles_glVertex3fv (const GLfloat *);
extern void jwzgles_glVertex3i (GLint x, GLint y, GLint z);
extern void jwzgles_glVertex4f (GLfloat x, GLfloat y, GLfloat z, GLfloat w);
extern void jwzgles_glVertex4fv (const GLfloat *);
extern void jwzgles_glVertex4i (GLint x, GLint y, GLint z, GLint w);
extern void jwzgles_glEnd (void);
extern void jwzgles_glCallList (int id);
extern void jwzgles_glClearIndex(GLfloat c);
extern void jwzgles_glBitmap (GLsizei, GLsizei, GLfloat, GLfloat, GLfloat,
                              GLfloat, const GLubyte *);
extern void jwzgles_glPushAttrib(int);
extern void jwzgles_glPopAttrib(void);

/* These functions are present in both OpenGL 1.3 and in OpenGLES 1,
   but are allowed within glNewList/glEndList, so we must wrap them
   to allow them to be recorded.
 */
extern void jwzgles_glActiveTexture (GLuint);
extern void jwzgles_glBindTexture (GLuint, GLuint);
extern void jwzgles_glBlendFunc (GLuint, GLuint);
extern void jwzgles_glClear (GLuint);
extern void jwzgles_glClearColor (GLclampf, GLclampf, GLclampf, GLclampf);
extern void jwzgles_glClearStencil (GLuint);
extern void jwzgles_glColorMask (GLuint, GLuint, GLuint, GLuint);
extern void jwzgles_glCullFace (GLuint);
extern void jwzgles_glDepthFunc (GLuint);
extern void jwzgles_glDepthMask (GLuint);
extern void jwzgles_glDisable (GLuint);
extern void jwzgles_glDrawArrays (GLuint, GLuint, GLuint);
extern GLboolean jwzgles_glIsEnabled (GLuint);
extern void jwzgles_glEnable (GLuint);
extern void jwzgles_glFrontFace (GLuint);
extern void jwzgles_glHint (GLuint, GLuint);
extern void jwzgles_glLineWidth (GLfloat);
extern void jwzgles_glLoadIdentity (void);
extern void jwzgles_glLogicOp (GLuint);
extern void jwzgles_glMatrixMode (GLuint);
extern void jwzgles_glMultMatrixf (const GLfloat *);
extern void jwzgles_glLoadMatrixf (const GLfloat *);
extern void jwzgles_glPointSize (GLfloat);
extern void jwzgles_glPolygonOffset (GLfloat, GLfloat);
extern void jwzgles_glPopMatrix (void);
extern void jwzgles_glPushMatrix (void);
extern void jwzgles_glScissor (GLuint, GLuint, GLuint, GLuint);
extern void jwzgles_glShadeModel (GLuint);
extern void jwzgles_glStencilFunc (GLuint, GLuint, GLuint);
extern void jwzgles_glStencilMask (GLuint);
extern void jwzgles_glStencilOp (GLuint, GLuint, GLuint);
extern void jwzgles_glViewport (GLuint, GLuint, GLuint, GLuint);
extern void jwzgles_glTranslatef (GLfloat, GLfloat, GLfloat);
extern void jwzgles_glRotatef (GLfloat, GLfloat, GLfloat, GLfloat);
extern void jwzgles_glRotated (GLdouble, GLdouble x, GLdouble y, GLdouble z);
extern void jwzgles_glScalef (GLfloat, GLfloat, GLfloat);
extern void jwzgles_glColor3f (GLfloat, GLfloat, GLfloat);
extern void jwzgles_glColor4f (GLfloat, GLfloat, GLfloat, GLfloat);
extern void jwzgles_glColor3fv (const GLfloat *);
extern void jwzgles_glColor4fv (const GLfloat *);
extern void jwzgles_glColor3s (GLshort, GLshort, GLshort);
extern void jwzgles_glColor4s (GLshort, GLshort, GLshort, GLshort);
extern void jwzgles_glColor3sv (const GLshort *);
extern void jwzgles_glColor4sv (const GLshort *);
extern void jwzgles_glColor3us (GLushort, GLushort, GLushort);
extern void jwzgles_glColor4us (GLushort, GLushort, GLushort, GLushort);
extern void jwzgles_glColor3usv (const GLushort *);
extern void jwzgles_glColor4usv (const GLushort *);
extern void jwzgles_glColor3d (GLdouble, GLdouble, GLdouble);
extern void jwzgles_glColor4d (GLdouble, GLdouble, GLdouble, GLdouble);
extern void jwzgles_glColor3dv (const GLdouble *);
extern void jwzgles_glColor4dv (const GLdouble *);
extern void jwzgles_glColor4i (GLint, GLint, GLint, GLint);
extern void jwzgles_glColor3i (GLint, GLint, GLint);
extern void jwzgles_glColor3iv (const GLint *);
extern void jwzgles_glColor4iv (const GLint *);
extern void jwzgles_glColor4ui (GLuint, GLuint, GLuint, GLuint);
extern void jwzgles_glColor3ui (GLuint, GLuint, GLuint);
extern void jwzgles_glColor3uiv (const GLuint *);
extern void jwzgles_glColor4uiv (const GLuint *);
extern void jwzgles_glColor4b (GLbyte, GLbyte, GLbyte, GLbyte);
extern void jwzgles_glColor3b (GLbyte, GLbyte, GLbyte);
extern void jwzgles_glColor4bv (const GLbyte *);
extern void jwzgles_glColor3bv (const GLbyte *);
extern void jwzgles_glColor4ub (GLubyte, GLubyte, GLubyte, GLubyte);
extern void jwzgles_glColor3ub (GLubyte, GLubyte, GLubyte);
extern void jwzgles_glColor4ubv (const GLubyte *);
extern void jwzgles_glColor3ubv (const GLubyte *);
extern void jwzgles_glMaterialf (GLuint, GLuint, GLfloat);
extern void jwzgles_glMateriali (GLuint, GLuint, GLuint);
extern void jwzgles_glMaterialfv (GLuint, GLuint, const GLfloat *);
extern void jwzgles_glMaterialiv (GLuint, GLuint, const GLint *);
extern void jwzgles_glFinish (void);
extern void jwzgles_glFlush (void);
extern void jwzgles_glPixelStorei (GLuint, GLuint);
extern void jwzgles_glEnableClientState (GLuint);
extern void jwzgles_glDisableClientState (GLuint);

extern void jwzgles_glInitNames (void);
extern void jwzgles_glPushName (GLuint);
extern GLuint jwzgles_glPopName (void);
extern GLuint jwzgles_glRenderMode (GLuint);
extern void jwzgles_glSelectBuffer (GLsizei, GLuint *);
extern void jwzgles_glLightf (GLenum, GLenum, GLfloat);
extern void jwzgles_glLighti (GLenum, GLenum, GLint);
extern void jwzgles_glLightfv (GLenum, GLenum, const GLfloat *);
extern void jwzgles_glLightiv (GLenum, GLenum, const GLint *);
extern void jwzgles_glLightModelf (GLenum, GLfloat);
extern void jwzgles_glLightModeli (GLenum, GLint);
extern void jwzgles_glLightModelfv (GLenum, const GLfloat *);
extern void jwzgles_glLightModeliv (GLenum, const GLint *);
extern void jwzgles_glGenTextures (GLuint, GLuint *);
extern void jwzgles_glFrustum (GLfloat, GLfloat, GLfloat, GLfloat,
                               GLfloat, GLfloat);
extern void jwzgles_glOrtho (GLfloat, GLfloat, GLfloat, GLfloat,
                             GLfloat, GLfloat);
extern void jwzgles_glTexImage1D (GLenum target, GLint level,
                                  GLint internalFormat,
                                  GLsizei width, GLint border,
                                  GLenum format, GLenum type,
                                  const GLvoid *pixels);
extern void jwzgles_glTexImage2D (GLenum target,
                                  GLint  	level,
                                  GLint  	internalFormat,
                                  GLsizei  	width,
                                  GLsizei  	height,
                                  GLint  	border,
                                  GLenum  	format,
                                  GLenum  	type,
                                  const GLvoid *data);
extern void jwzgles_glTexSubImage2D (GLenum target, GLint level,
                                     GLint xoffset, GLint yoffset,
                                     GLsizei width, GLsizei height,
                                     GLenum format, GLenum type,
                                     const GLvoid *pixels);
extern void jwzgles_glCompressedTexImage2D (GLenum target,
                                            GLint  	level,
                                            GLint  	internalFormat,
                                            GLsizei  	width,
                                            GLsizei  	height,
                                            GLint  	border,
                                            GLsizei imageSize,
                                            const GLvoid *data);
extern void jwzgles_glCompressedTexSubImage2D (GLenum target, GLint level,
                                               GLint xoffset, GLint yoffset,
                                               GLsizei width, GLsizei height,
                                               GLenum format, GLsizei imageSize,
                                               const GLvoid *pixels);
extern void jwzgles_glCopyTexImage2D (GLenum target, GLint level,
                                      GLenum internalformat,
                                      GLint x, GLint y,
                                      GLsizei width, GLsizei height,
                                      GLint border);
extern void jwzgles_glInterleavedArrays (GLenum, GLsizei, const GLvoid *);
extern void jwzgles_glTexEnvf (GLuint, GLuint, GLfloat);
extern void jwzgles_glTexEnvi (GLuint, GLuint, GLuint);
extern void jwzgles_glTexParameterf (GLuint, GLuint, GLfloat);
extern void jwzgles_glTexParameteri (GLuint, GLuint, GLuint);
extern void jwzgles_glTexGeni (GLenum, GLenum, GLint);
extern void jwzgles_glTexGenfv (GLenum, GLenum, const GLfloat *);
extern void jwzgles_glGetTexGenfv (GLenum, GLenum, GLfloat *);
extern void jwzgles_glRectf (GLfloat, GLfloat, GLfloat, GLfloat);
extern void jwzgles_glRecti (GLint, GLint, GLint, GLint);
extern void jwzgles_glLightModelfv (GLenum, const GLfloat *);
extern void jwzgles_glClearDepth (GLfloat);
extern GLboolean jwzgles_glIsList (GLuint);
extern void jwzgles_glColorMaterial (GLenum, GLenum);
extern void jwzgles_glPolygonMode (GLenum, GLenum);
extern void jwzgles_glFogf (GLenum, GLfloat);
extern void jwzgles_glFogi (GLenum, GLint);
extern void jwzgles_glFogfv (GLenum, const GLfloat *);
extern void jwzgles_glFogiv (GLenum, const GLint *);
extern void jwzgles_glAlphaFunc (GLenum, GLfloat);
extern void jwzgles_glClipPlane (GLenum, const GLdouble *);
extern void jwzgles_glDrawBuffer (GLenum);
extern void jwzgles_glDeleteTextures (GLuint, const GLuint *);

extern void jwzgles_gluPerspective (GLdouble fovy, GLdouble aspect,
                                    GLdouble near, GLdouble far);
extern void jwzgles_gluLookAt (GLfloat eyex, GLfloat eyey, GLfloat eyez,
                               GLfloat centerx, GLfloat centery,
                               GLfloat centerz,
                               GLfloat upx, GLfloat upy, GLfloat upz);
extern GLint jwzgles_gluProject (GLdouble objx, GLdouble objy, GLdouble objz,
                                 const GLdouble modelMatrix[16],
                                 const GLdouble projMatrix[16],
                                 const GLint viewport[4],
                                 GLdouble *winx, GLdouble *winy,
                                 GLdouble *winz);
extern int jwzgles_gluBuild2DMipmaps (GLenum target,
                                      GLint internalFormat,
                                      GLsizei width,
                                      GLsizei height,
                                      GLenum format,
                                      GLenum type,
                                      const GLvoid *data);
extern void jwzgles_glGetFloatv (GLenum pname, GLfloat *params);
extern void jwzgles_glGetPointerv (GLenum pname, GLvoid *params);
extern void jwzgles_glGetDoublev (GLenum pname, GLdouble *params);
extern void jwzgles_glGetIntegerv (GLenum pname, GLint *params);
extern void jwzgles_glGetBooleanv (GLenum pname, GLboolean *params);
extern void jwzgles_glVertexPointer (GLuint, GLuint, GLuint, const void *);
extern void jwzgles_glNormalPointer (GLenum, GLuint, const void *);
extern void jwzgles_glColorPointer (GLuint, GLuint, GLuint, const void *);
extern void jwzgles_glTexCoordPointer (GLuint, GLuint, GLuint, const void *);
extern void jwzgles_glBindBuffer (GLuint, GLuint);
extern void jwzgles_glBufferData (GLenum, GLsizeiptr, const void *, GLenum);
extern const char *jwzgles_gluErrorString (GLenum error);

extern GLenum jwzgles_glGetError();
extern const GLubyte * jwzgles_glGetString(GLenum name);

// typedef float GLclampd;

extern void jwzgles_glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
extern void jwzgles_glCopyTexSubImage2D (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
extern void jwzgles_glDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices );

#ifdef __cplusplus
}
#endif

#endif /* __JWZGLES_I_H__ */


code:
// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman
// Ken Silverman's official web site: "http://www.advsys.net/ken"
// See the included license file "BUILDLIC.TXT" for license info.
//
// This file has been modified from Ken Silverman's original release
// by Jonathon Fowler (jf@jonof.id.au)
// by the EDuke32 team (development@voidpoint.com)

#ifndef klzw_h_
#define klzw_h_

#include "compat.h"

#ifdef __cplusplus
extern "C" {
#endif

// These two follow the argument order of the C functions "read" and "write":
// handle, buffer, length.
typedef int32_t (*klzw_readfunc)(intptr_t, void *, int32_t);
typedef void (*klzw_writefunc)(intptr_t, void const *, int32_t);

int32_t klzw_read_compressed(void *buffer, int dasizeof, int count, intptr_t const f, klzw_readfunc readfunc);
void klzw_write_compressed(const void * const buffer, int dasizeof, int count, intptr_t const f, klzw_writefunc writefunc);

#ifdef __cplusplus
}
#endif

#endif // klzw_h_


code:
#ifndef compat_h_
#include "compat.h"
#endif

#include "vfs.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct
{
    buildvfs_FILE fil;    //0:no file open, !=0:open file (either stand-alone or zip)
    int32_t comptyp; //0:raw data (can be ZIP or stand-alone), 8:PKZIP LZ77 *flate
    int32_t seek0;   //0:stand-alone file, !=0: start of zip compressed stream data
    int32_t compleng;//Global variable for compression FIFO
    int32_t comptell;//Global variable for compression FIFO
    int32_t leng;    //Uncompressed file size (bytes)
    int32_t pos;     //Current uncompressed relative file position (0<=pos<=leng)
    int32_t endpos;  //Temp global variable for kzread
    int32_t jmpplc;  //Store place where decompression paused
    int32_t i;       //For stand-alone/ZIP comptyp#0, this is like "uncomptell"
    //For ZIP comptyp#8&btype==0 "<64K store", this saves i state
    int32_t bfinal;  //LZ77 decompression state (for later calls)
} kzfilestate;

extern kzfilestate kzfs;

	//High-level (easy) picture loading function:
extern void kpzdecode (int32_t, intptr_t *, int32_t *, int32_t *);
extern void kpzload (const char *, intptr_t *, int32_t *, int32_t *);
	//Low-level PNG/JPG functions:
extern void kpgetdim (const char *, int32_t, int32_t *, int32_t *);
extern int32_t kprender (const char *, int32_t, intptr_t, int32_t, int32_t, int32_t);

	//ZIP functions:
extern int32_t kzaddstack (const char *);
extern void kzuninit ();
extern intptr_t kzopen (const char *);
extern int32_t kzread (void *, int32_t);
extern int32_t kzseek (int32_t, int32_t);

static inline int32_t kztell(void) { return kzfs.fil ? kzfs.pos : -1; }
static inline int32_t kzeof(void) { return kzfs.fil ? kzfs.pos >= kzfs.leng : -1; }
static inline int32_t kzfilelength(void) { return kzfs.fil ? kzfs.leng : 0; }
static inline int32_t kzgetc(void) { char ch; return kzread(&ch, 1) ? ch : -1; }
static inline void kzclose(void) { MAYBE_FCLOSE_AND_NULL(kzfs.fil); }

extern void kzfindfilestart (const char *); //pass wildcard string
extern int32_t kzfindfile (char *); //you alloc buf, returns 1:found,0:~found

//like stricmp(st0,st1) except: '/' == '\'

extern char toupperlookup[256];
static inline int32_t filnamcmp(const char *j, const char *i)
{
    // If we reach at the end of both strings, we are done
    while (*i && *j && (toupperlookup[*i] == toupperlookup[*j]))
        i++, j++;
    return *i != '\0' || *j != '\0';
}
extern int32_t wildmatch(const char *match, const char *wild);

#ifdef __cplusplus
}
#endif