amnu3387

amnu3387

Hi,

I’m not sure if a NIF is the best option for this - I’m also not experienced with C (don’t even know how to properly link libs, for instance) at all but I’m taking small steps in order to use OpenGL.

Imagine you are building a graphical interface that needs to do OpenGL. I can write a small program in C that just opens a window and stays there. All good.

My question now is, if I want to interact with this program, like send it draw commands so it applies them to the gl context, what would be the best way to do that? Although initially a toy project I would definitely prefer the option that is the most performant, as this would be something akin to a browser.

Do you know any good resources/libs for looking into this? I’m going for the lowest common denominator possible - elixir/erl ↔ c program using glfw3 - the C program also has to be able to callback somehow, since glfw handles user interaction on the window as well.

Any pointers welcomed, thanks

Showing Posts 1 to 10

lud

lud

You could use a simple TCP socket between the two programs. Erlang has great support for that. Your C program would connect to the TCP server. Have a look at gen_tcp — OTP 29.0.2 (kernel 11.0.2) .

dimitarvp

dimitarvp

UI naturally lends itself to message passing so I’d put a GenServer in front of your native UI code so as to make it innately serial (one message at a time / no parallel processing of messages).

As for the native interface, it could be C, Rust or anything you are comfortable with (but ergonomic caveats do still apply so I’d pick Rust 99% of the time).

amnu3387

amnu3387 OP

Thanks, yes that could definitively work and I’ve used gen_tcp in the past.
I’m trying to learn a bit more about lower level code, with C and OpenGl in this case, and Erlang interfacing with these.

I’m not really knowledgeable when it comes to it so perhaps a tcp socket would be in fact the best way of doing it - but if say, you’re doing a lot of drawing wouldn’t it benefit somehow of being in a NIF ?

amnu3387

amnu3387 OP

My idea would be that initially each tab would be a gen_statem, but eventually would move to being an erlang node. Then shared resources (caches, etc) would be shared through mnesia.

Yes, I’m not really comfortable with anything lower level hence why I want to practice - I chose C because I can’t understand what Rust brings on without understanding C - most examples for OpenGL go with c++ but I would really prefer to learn the basics first before going on some rabbit chasing :smiley:

dimitarvp

dimitarvp

Fair. As a preliminary spoiler alert: in C it’s trivial to allocate a memory buffer of 10 bytes and then try to get a value from the 11th element. This, oversimplified, has been the reason for most of the security fiascos in the last several years.

Rust prevents those.

amnu3387

amnu3387 OP

Very oversimplified I would guess :slight_smile:

ityonemo

ityonemo

Wait a second, am I wrong that Rust does not prevent you from trying to grab the 11th element of a 10-vector! that’s a runtime panic. If you want erroring bounds checking you need a wrapped type

dimitarvp

dimitarvp

Ah, I was aiming at arrays. :slight_smile:

And still, runtime panic isn’t the same as buffer [over|under]flow which can lead to the program being compromised. But I agree that panics aren’t very useful by themselves.

dominicletz

dominicletz

Creator of Elixir Desktop

Just FYI you do have full access to OpenGL from elixir already today. Have a look at the wings3d project. It’s an OpenGL based 3d modeller written in Erlang http://www.wings3d.com/

Source code: GitHub - dgud/wings: Wings3D is an advanced sub-division 3D modeller. · GitHub

amnu3387

amnu3387 OP

I had looked at wings (was surprised the forum still seems to be active), and also scenic that uses GLFW too, but got a bit overwhelmed on how to start/work the c part :slight_smile: like from easy mode and build from there as that’s how I learn better. I will certainly look into them for inspiration.

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews