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

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews