A good 3D math library in C for OpenGL?

Started by
12 comments, last by Fulcrum.013 4 years, 11 months ago

Hello!

I'm trying to find a good math library to use in my game engine. Because I need good DLL support, and c++ has tired me with DLLs, I ended up choosing C. I found CGLM but maybe you know something better :P Of course I won't create the entire engine in C, I will use a lot of c++ but the DLL (which will include the renderer and any GL calls) will be made purely in C.

Thank you.


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

Advertisement
2 hours ago, babaliaris said:

c++ has tired me with DLLs,

What is wrong with C++ dlls that C dlls do not have ?

12 minutes ago, _Silence_ said:

What is wrong with C++ dlls that C dlls do not have ?

I have trouble compiling them in different platforms, even though I'm really careful with name mangling.


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

I like these two.

  1. https://github.com/HandmadeMath/Handmade-Math
  2. https://github.com/felselva/mathc

If you're having trouble with DLLs in C++, wouldn't it be a better idea to drop the DLLs than to drop C++?

Seriously, DLLs are a huge pain in the ass for basically no benefit.  The only time DLLs make sense is when different parts of the project need to be distributed under different licenses.  That's a legal reason for using DLLs.  There is no technical reason for using DLLs, ever.

I am confused by the term dll as math libraries i think of (vectors, matrixes, quaternions, boudning shapes, rays, collisions, intersections, etc. pp) usually come as header-only files.

How about data types and precision that are much easier to implement in C++ (templates) than in C ? Almost all math libs i know, if they are not for pure demonstration purposes, offer that functionality.

 

I would recommend GLM, since it is made to have similar styntax to GLSL, so you can write your math in the same way; both server-side and client-side. Especially if you enable swizzling, "vec3 v = other.xyz;". It is not a DLL, so no linking required.

I'm with "a light breeze" on not dropping C++. It will probably serve you better to work in C++ than C, if you want to make games and work with graphics. There is no need to learn C first and then move on to C++, since the languages grow increasingly distant by each new release.

Not sure about C-compatibility though. CGLM seems to be GLM, so I would go with that.
https://www.khronos.org/news/permalink/new-optimized-opengl-graphics-math-glm-for-c-feedback-requested

https://github.com/recp/cglm

Good luck! :)

// Fredrick Johansson, loopaware.com/fredrick

5 hours ago, a light breeze said:

If you're having trouble with DLLs in C++, wouldn't it be a better idea to drop the DLLs than to drop C++?

Seriously, DLLs are a huge pain in the ass for basically no benefit.  The only time DLLs make sense is when different parts of the project need to be distributed under different licenses.  That's a legal reason for using DLLs.  There is no technical reason for using DLLs, ever.

The reason I want dll's is for updating mechanisms and moding techniques. If I want to be able to send updates for my game, linking everything to an executable will require on a single change in the code to resend the whole executable to the clients. If the game is 50gb, even the slight change in the code would lead to send that 50gb all over again. With dll's I can just send that particular dll only where the change in the code happened.

Also, if I want to support modes, I must give the users a way of extending the game without actually the need to download the whole project. They are going to just include an API which i will provide them, compile their code into a Dll and then just copy-paste that dll into the game directory and the game will automatically load the dll and use the code to dynamically extend the capabilities of the game. 


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

7 minutes ago, babaliaris said:

. If the game is 50gb,

So it have at least 49.9gb in datapack and less than 100 mb in executables/dlls.

#define if(a) if((a) && rand()%100)

52 minutes ago, Fulcrum.013 said:

So it have at least 49.9gb in datapack and less than 100 mb in executables/dlls.

I'm not sure what you mean, but the 49.9gb will already exist on the user's installation, so I will only send the 100mb dll to the user when he updates the game.


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

This topic is closed to new replies.

Advertisement