Git Product home page Git Product logo

gfm's Introduction

GFM

logo

IMPORTANT 2: GFM has been deprecated in favor of dplug:math. Use version 8 if you want the former content gfm:integer and gfm:math content. No PR will be accepted.

Hello,

Here is something I wanted to do for a while. I'm abandoning gfm in favor of dplug:math (vectors, matrices, and box), which will be tailored for Dplug needs. I know gfm has been a reliable and stable library over the years but there should be much better libraries around nowadays. gfm has never been super good in usability and purpose; and I just have no need for such a generic library anymore. I hope you understand and go build a better library. Overstretching with too many libraries to maintain is not very good for me. p0nce

IMPORTANT: GFMv8 has been stripped down to gfm:math and gfm:integers only. Use version 7 if you want the former content.

See the changelog here to upgrade: https://github.com/d-gamedev-team/gfm/wiki/Changelog

License

Public Domain (Unlicense).

How to use GFM?

Add the sub-package you are interested in in your dub.json:

   {
      "dependencies": {
        "gfm:math": "~>8.0"
      }
   }

Changelog

https://github.com/d-gamedev-team/gfm/wiki/Changelog

Why use GFM?

  • GFM provides math primitives that are useful for games like vectors/matrices/quaternions in the gfm:math package,
  • Also provide arbitrary sized integers, fixed point numbers, and half-float numbers in gfm:integers,

This library is really small now

There used to be a lot more stuff in GFM previously. See http://code.dlang.org to discover lots of useful libraries for your programs.

gfm's People

Contributors

ahmetsait avatar andrewbenton avatar berulacks avatar chances avatar clinei avatar coldencullen avatar cromfr avatar drug007 avatar francesco-cattoglio avatar gitter-badger avatar jackstouffer avatar jamesbarnett avatar martinnowak avatar moon-chilled avatar n8sh avatar p0nce avatar petarkirov avatar s-ludwig avatar sheepandshepherd avatar vanscheijen avatar vuaru avatar yoplitein avatar zshazz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gfm's Issues

More examples

I've tried several minimal VBO examples online, but I just cannot get it to render..
The basics are pretty simple:

    vec3f[3] vertices = [
        vec3f(-1.0f, -1.0f, 0.0f),
        vec3f( 1.0f, -1.0f, 0.0f),
        vec3f( 0.0f,  1.0f, 0.0f)
        ];

    GLuint VBO;
    glGenBuffers(1, &VBO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, vec3f.sizeof*vertices.length, vertices.ptr, GL_STATIC_DRAW);
        glBindBuffer(GL_ARRAY_BUFFER, VBO);
        glEnableVertexAttribArray(0);
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, cast(void*)0);
        glDrawArrays(GL_TRIANGLES, 0, 3); // nothing
        //glDrawArrays(GL_POINTS, 0, 3); // single white point ca. in the middle
        glDisableVertexAttribArray(0);

How would a minimal VBO triangle look like?

Here's the full program (slightly modified simplegl.d):

import gfm.sdl2.all;
import gfm.common.all;
import gfm.opengl.all;

class MyWindow : SDL2Window
{
    this(SDL2 sdl2, box2i position, bool fullscreen)
    {
        super(sdl2, position, fullscreen, true, false);
    }
}

void main()
{
    auto log = new ConsoleLog();

    auto sdl2 = new SDL2(log);
    scope(exit) sdl2.close();

    auto gl = new OpenGL(log);
    scope(exit) gl.close();

    auto displays = sdl2.getDisplays();

    if (displays.length == 0)
        return; // no display

    auto bounds = displays[0].bounds().shrink(vec2i(40));

    auto window = new MyWindow(sdl2, bounds, false);
    scope(exit) window.close();

    auto eventQueue = new SDL2EventQueue(sdl2);
    eventQueue.registerWindow(window);

    gl.reload();

    auto shader = new GLShader(gl, GL_FRAGMENT_SHADER,
    [
    r"uniform vec4 col;

      void main()
      {
          gl_FragColor = col;
      }
     "]);

    auto program = new GLProgram(gl, shader);

    vec3f[3] vertices = [
        vec3f(-1.0f, -1.0f, 0.0f),
        vec3f( 1.0f, -1.0f, 0.0f),
        vec3f( 0.0f,  1.0f, 0.0f)
        ];

    GLuint VBO;
    glGenBuffers(1, &VBO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, vec3f.sizeof*vertices.length, vertices.ptr, GL_STATIC_DRAW);

    glClearColor(0, 0, 0, 0);
    while(!eventQueue.keyboard().isPressed(SDLK_ESCAPE))
    {
        eventQueue.processEvents();

        glClear(GL_COLOR_BUFFER_BIT);
        glViewport(0, 0, bounds.width, bounds.height);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

        program.uniform("col").set(vec4f(1.0f, 1.0f, 1.0f, 0.0f));
        program.use();

        glBindBuffer(GL_ARRAY_BUFFER, VBO);
        glEnableVertexAttribArray(0);
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, cast(void*)0);
        glDrawArrays(GL_TRIANGLES, 0, 3); // nothing
        //glDrawArrays(GL_POINTS, 0, 3); // single white point ca. in the middle
        glDisableVertexAttribArray(0);

        program.unuse();

        window.swapBuffers();
    }
}

simplegl example fails.

../../../.dub/packages/gfm-master/opengl/gfm/opengl/program.d(257): Error: function pointer glGetActiveUniformsiv (uint, int, const(uint)*, uint, int*) is not callable using argument types (uint, uint*, uint*, uint, int*)

Faulty vector.cross

The cross product is different from what I believe is correct (and wiki agrees with me)

Fixed:

Vector!(T, 3u) cross(T)(const Vector!(T, 3u) a, const Vector!(T, 3u) b) pure nothrow
{
    return Vector!(T, 3u)(a.y * b.z - a.z * b.y,
                          a.z * b.x - a.x * b.z,
                          a.x * b.y - a.y * b.x);
}

Fix SimpleRNG

The D version is buggy, at least in uniform distribution. Make it work more with std.random.

Quaternion opCast

Simple cast.

module main;

import gfm.math.quaternion;
import gfm.math.matrix;

void main()
{
    quaternionf quat = quaternionf.IDENTITY;
    mat4f mat = cast(mat4f)quat;
}

Results in:

\src\main.d(21): Error: template gfm.math.quaternion.Quaternion!(float).Quaternion.opCast does not match any function template declaration
\imports\gfm\math\quaternion.d(109): Error: template gfm.math.quaternion.Quaternion!(float).Quaternion.opCast cannot deduce template function from argument types !(Matrix!(float,4u,4u))()

DMD bug

Ok, this is actually a DMD bug, but I wasn't able to reproduce it with a simple testcase.
Adding the bug here hoping that you can reproduce it with a smaller testcase.

Compiling the shader example with dub --build=release gives this error:

../../../.dub/packages/gfm-master/net/gfm/net/cbor.d(609): Error: variable hu used before set

This simple testcase doesn't reproduce it though:

union U {
    int   i;
    float f;
}
void main() {
    U u = void;
    u.i = 1;
}

Using dmd 2.064 on GNU/Linux x64.

sanitizeUTF8 faulty

Outputs:

info: Platform: [87, 105, 110, 100, 111, 119, 115], 2 CPU, L1 cacheline size: 64b
info: Available driver: [119, 105, 110, 100, 111, 119, 115]

Expected:
info: Platform: Windows, 2 CPU, L1 cacheline size: 64b
info: Available driver: windows

GLShader.compile() prints garbage.

Ie.

info: ÿ'*
info: ÿ&*
info: ÿ&*
info: ÿ%*
info: ÿ'3��É�
info: ÿ&3��É�
info: ÿ&3��É�
info: ÿ%3��É�
info: ÿ$3��É�
info: ÿ#3��É�

Doesn't compile

gfm.sdl2.sdl.SDL2Exception@../gfm/sdl2/sdl.d(24): Failed to load symbol SDL_GetTouch from shared library libSDL2.so

Seems SDL2 has been frozen, but Derelict3 haven't pulled in the changes yet.
Refs: mdparker/Derelict3#94

matrix.lookAt

The matrix.lookAt did not behave as I expected.
It seems this returns a column-major result, instead of row-major.
Therefore I have to always transpose the result before passing it to shaders.
This seems inconsistent, because the other matrices in gfm are all row-major.

Yours:

            static Matrix lookAt(vec3!T eye, vec3!T target, vec3!T up) pure nothrow
            {
                vec3!T Z = (eye - target).normalized();
                vec3!T X = cross(up, Z).normalized();
                vec3!T Y = cross(Z, X);

                return Matrix(    X.x,         Y.x,         Z.x,     0,
                                  X.y,         Y.y,         Z.y,     0,
                                  X.z,         Y.z,         Z.z,     0,
                              dot(X, eye), dot(Y, eye), dot(Z, eye), 1);
            }

Mine:

                return Matrix(  X.x,         X.y,         X.z,     -dot(X, eye),
                                Y.x,         Y.y,         Y.z,     -dot(Y, eye),
                                Z.x,         Z.y,         Z.z,     -dot(Z, eye),
                                0,           0,           0,        1);

Also note the minus for the dot products.

Should resources be structs?

Open question.

We have two alternatives:

  • making resources structs, implement this(this) for all, and forget about close methods
  • keep the classes, close() methods is not called anymore by the destructors, and log a warning in destructors if possible (might not be)

Polynomials

Merge solver.d with a generic polynomial class.

Linux SDL Invalid window

Another issue from a workmate:

Original /gfm/sdl2/sdl.d

info: Platform: Linux, 4 CPU, L1 cacheline size: 64b
error: SDL (category error, priority error): Invalid window
info: Available driver: x11
info: Available driver: dummy
error: SDL (category error, priority error): Passed a NULL mutex
error: SDL (category error, priority error): Passed a NULL mutex
error: SDL (category error, priority error): Invalid window
info: Running using video driver: x11
info: 1 video display(s) detected.
info: OpenGL loaded, version 11
info: OpenGL reloaded, version 33
info:     Version: 3.3.0 NVIDIA 304.43
info:     Renderer: GeForce GT 330M/PCIe/SSE2
info:     Vendor: NVIDIA Corporation
info:     GLSL version: 3.30 NVIDIA via Cg compiler
info:     Extensions: 252 found
info:     - EXT_texture_filter_anisotropic is supported
info:     - EXT_framebuffer_object is supported

Forcing video subsystem initilisation directly after SDL load in constructor:

final class SDL2
{
    public
    {
        this(Log log)
        {
            _log = log;
            _SDLInitialized = false;
            _SDL2LoggingRedirected = false;
            try
            {
                // in debug builds, use a debug version of SDL2
                debug
//                    DerelictSDL2.load("SDL2d.dll");
                    DerelictSDL2.load("libSDL2.so");
              else
                    DerelictSDL2.load();

SDL_InitSubSystem(SDL_INIT_VIDEO); // NEW
           }
            catch(DerelictException e)
            {
                throw new SDL2Exception(e.msg);
            }
...

Removes the first Invalid window error, indicating a different result for:
subSystemInit(SDL_INIT_VIDEO);

info: Platform: Linux, 4 CPU, L1 cacheline size: 64b
info: Available driver: x11
info: Available driver: dummy
error: SDL (category error, priority error): Passed a NULL mutex
error: SDL (category error, priority error): Passed a NULL mutex
error: SDL (category error, priority error): Invalid window
info: Running using video driver: x11
info: 1 video display(s) detected.
info: OpenGL loaded, version 11
info: OpenGL reloaded, version 33
info:     Version: 3.3.0 NVIDIA 304.43
info:     Renderer: GeForce GT 330M/PCIe/SSE2
info:     Vendor: NVIDIA Corporation
info:     GLSL version: 3.30 NVIDIA via Cg compiler
info:     Extensions: 252 found
info:     - EXT_texture_filter_anisotropic is supported
info:     - EXT_framebuffer_object is supported

dub 0.9.22 build fails

For some reason dub can't see the subpackages when it's looking for dependencies.

$ dub build -v
Using dub registry url 'http://code.dlang.org/'
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/john/.dub/packages/local-packages.json
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/john/.dub/packages/local-packages.json
Determined package version using GIT: gfm ~master
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/john/.dub/packages/local-packages.json
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/john/.dub/packages/local-packages.json
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/john/.dub/packages/local-packages.json
Version selection for dependency gfm:enet of gfm is missing.
Version selection for dependency gfm:math of gfm is missing.
Version selection for dependency gfm:net of gfm is missing.
Version selection for dependency gfm:core of gfm is missing.
Version selection for dependency gfm:assimp of gfm is missing.
Version selection for dependency gfm:freeimage of gfm is missing.
Version selection for dependency gfm:image of gfm is missing.
Version selection for dependency gfm:opengl of gfm is missing.
Version selection for dependency gfm:sdl2 of gfm is missing.
Checking for missing dependencies.
Search for versions of gfm (1 package suppliers)
Search for versions of derelict_extras-enet (1 package suppliers)
Search for versions of derelict-util (1 package suppliers)
Search for versions of derelict-assimp3 (1 package suppliers)
Search for versions of derelict-fi (1 package suppliers)
Search for versions of derelict-gl3 (1 package suppliers)
Search for versions of derelict-sdl2 (1 package suppliers)
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/john/.dub/packages/local-packages.json
Version selection for dependency gfm:enet of gfm is missing.
Version selection for dependency gfm:math of gfm is missing.
Version selection for dependency gfm:net of gfm is missing.
Version selection for dependency gfm:core of gfm is missing.
Version selection for dependency gfm:assimp of gfm is missing.
Version selection for dependency gfm:freeimage of gfm is missing.
Version selection for dependency gfm:image of gfm is missing.
Version selection for dependency gfm:opengl of gfm is missing.
Version selection for dependency gfm:sdl2 of gfm is missing.
Checking for upgrades.
Search for versions of gfm (1 package suppliers)
Search for versions of derelict_extras-enet (1 package suppliers)
Search for versions of derelict-util (1 package suppliers)
Search for versions of derelict-assimp3 (1 package suppliers)
Search for versions of derelict-fi (1 package suppliers)
Search for versions of derelict-gl3 (1 package suppliers)
Search for versions of derelict-sdl2 (1 package suppliers)
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/john/.dub/packages/local-packages.json
Version selection for dependency gfm:enet of gfm is missing.
Version selection for dependency gfm:math of gfm is missing.
Version selection for dependency gfm:net of gfm is missing.
Version selection for dependency gfm:core of gfm is missing.
Version selection for dependency gfm:assimp of gfm is missing.
Version selection for dependency gfm:freeimage of gfm is missing.
Version selection for dependency gfm:image of gfm is missing.
Version selection for dependency gfm:opengl of gfm is missing.
Version selection for dependency gfm:sdl2 of gfm is missing.
WARNING: A deprecated branch based version specification is used for the dependency gfm:enet. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:math. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:net. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:core. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:assimp. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:freeimage. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:image. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:opengl. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
WARNING: A deprecated branch based version specification is used for the dependency gfm:sdl2. Please use numbered versions instead. Also note that you can still use the dub.selections.json file to override a certain dependency to use a branch instead.
Error executing command build: Unknown dependency: gfm:enet

Full exception: object.Exception@source/dub/project.d(156): Unknown dependency: gfm:enet

wglMakeCurrent invalid handle

Compile & run example/simplegl.d results in, on esc:

error: SDL (category error, priority error): wglMakeCurrent(): The handle is invalid.

Linux 64bit

Someone I work with has asked me to tell you the following:

Linux/ OS issue:
In /gfm/sdl2/sdl.d, constructor holds a Windows specific call.

    debug
        DerelictSDL2.load("SDL2d.dll");

Can be fixed by OS checks, as done elsewhere already:

    DerelictSDL2.load("SDL2d.dll");
    DerelictSDL2.load("libSDL2.so");

Issues with 64-bit compile:
Use of size_t and array.lenght, which on 32-bit will 4 bytes in size (int), for 64-bit these are 8 bytes, (ulong).
This causes compile time errors like:

/gfm/opengl/uniform.d(139): Error: function pointer glUniform1fv (int, int, const(float)*) is not callable using argument types (int,ulong,float*)

A possible fix would be to compile gfm (and the code using it) using the '-m32' copile flag.
However, than the libSDL2.so (and any other library) will have to be 32-bit also.
This is not true by default for any 64-bit linux system, as it will use 64-bit libs.
A better solution is to use int instead of size_t/length, as, in gfm, size_t is often used for 'size parameters' to gl functions.
These take GLints as input, irrespective of architecture, so invariably feeding them ints would seem a reasonable choice.

Some affected classes, probably many more:
gfm/opengl/shader.d
gfm/opengl/textureunit.d
gfm/opengl/uniform.d
gfm/opengl/vbo.d
gfm/sdl2/renderer.d

DISCLAIMER, below are quick hacks to get a 64-bit compile (no proper diff, sorry):

gfm/opengl/shader.d
-                lengths[i] = localLines[i].length;
+                lengths[i] = cast(int)localLines[i].length;

gfm/opengl/textureunit.d
-            int index = targetToIndex(cast(Target)target);
+            int index = cast(int)targetToIndex(cast(Target)target);

gfm/opengl/uniform.d
-        size_t _size;
+        int _size;

gfm/opengl/vbo.d
-                        glVertexPointer(n, glType, sizeOfVertex, cast(GLvoid *) offset);
+                        glVertexPointer(n, glType, cast(int)sizeOfVertex, cast(GLvoid *) offset);

                         break;

                     case Role.COLOR:
                         glEnableClientState(GL_COLOR_ARRAY);
-                        glColorPointer(n, glType, sizeOfVertex, cast(GLvoid *) offset);
+                        glColorPointer(n, glType, cast(int)sizeOfVertex, cast(GLvoid *) offset);
                         break;

                     case Role.TEX_COORD:
                         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-                        glTexCoordPointer(n, glType, sizeOfVertex, cast(GLvoid *) offset);
+                        glTexCoordPointer(n, glType, cast(int)sizeOfVertex, cast(GLvoid *) offset);
                         break;

                     case Role.NORMAL:
                         glEnableClientState(GL_NORMAL_ARRAY);
                         assert(n == 3);
-                        glNormalPointer(glType, sizeOfVertex, cast(GLvoid *) offset);
+                        glNormalPointer(glType, cast(int)sizeOfVertex, cast(GLvoid *) offset);
                         break;
                 }
             }
             else
             {
                 glEnableVertexAttribArray(index);
-                glVertexAttribPointer(index, n, glType, GL_FALSE, sizeOfVertex, cast(GLvoid *) offset);
+                glVertexAttribPointer(index, n, glType, GL_FALSE, cast(int)sizeOfVertex, cast(GLvoid *) offset);


gfm/sdl2/renderer.d
@@ -150,7 +150,7 @@ final class SDL2Renderer
         void drawLines(vec2i[] points)
         {
-            SDL_RenderDrawLines(_renderer, cast(SDL_Point*)(points.ptr), points.length);
+            SDL_RenderDrawLines(_renderer, cast(SDL_Point*)(points.ptr), cast(int)points.length);
         }

@@ -160,7 +160,7 @@ final class SDL2Renderer
         void drawPoints(vec2i[] points)
         {
-            SDL_RenderDrawPoints(_renderer, cast(SDL_Point*)(points.ptr), points.length);
+            SDL_RenderDrawPoints(_renderer, cast(SDL_Point*)(points.ptr), cast(int)points.length);

Transition to std.logger

The std.logger proposal landed in the DUB registry with the name "logger". It looks like the most promising logger package available.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.