c3lang / vendor

External C3 libraries
MIT License
14 stars 11 forks source link

OpenGL Bindings #16

Closed ellipse12 closed 4 weeks ago

ellipse12 commented 1 month ago

I was not sure if it was better to have multiple files or just one. So I added one file for each sub-module, I am willing to merge them together if necessary though.

ellipse12 commented 1 month ago

I also was not sure what to link to for every target, so I just did the ones I know.

lerno commented 1 month ago

Oh, this was an interesting solution. So the idea was that to avoid the user having to specify a version, all are available and you pick from the versions you know are available?

ellipse12 commented 1 month ago

Sort of? I believe the version number in the source is in reference to when the specific functions were added, as the earlier versions definitely do not have all of the functions of that version (e.g. fixed pipeline functions like glStart and glEnd are not included). I came from a background of using Java/LWJGL which does something similar with their bindings.

ellipse12 commented 1 month ago

I could probably add the old functions, though it would likely take a little while longer.

lerno commented 1 month ago

There is the alternative to use the env so for module opengl::gl13; replace that by module opengl @if(env::GL_VERSION >= 13);. Another thing would be to have module opengl13::gl and then have each version essentially include the other and you'd import module opengl15::gl and you get everything

ellipse12 commented 1 month ago

Is env defined in the project.json? or is it a separate custom module?

lerno commented 1 month ago

I am talking about std::core::env, which can be injected. Another option is to have import opengl in every module, and it then looks for the constant opengl::VERSION which a user of the module must define, so essentially:

module opengl;
const int VERSION = 22;
module mycode;
...

This would work.

ellipse12 commented 1 month ago

how do you inject it? (sorry I am still a bit new to C3)

ellipse12 commented 1 month ago

Also as of this moment the bindings should be fully functional with the latest version of OpenGL.

lerno commented 1 month ago

Literally just placing these rows anywhere in your sources:

module opengl;
const int VERSION = 22;
ellipse12 commented 1 month ago

You can access it then through env?

lerno commented 1 month ago

That's not even needed if all opengl modules import this.

ellipse12 commented 1 month ago

Do you mind explaining to me how it(injecting variables into env) works anyway, it may be useful in other ways.

ellipse12 commented 1 month ago

I'll start working on supporting earlier versions

lerno commented 1 month ago

Basically all modules are extendable, so if your program adds something to some other module it's there.

ellipse12 commented 1 month ago

Ooh ok so it's just like the opengl thing but with std::core::env

ellipse12 commented 1 month ago

I have been looking around and I can't seem to find older versions of the OpenGL headers/ xml spec. Would it be alright if you just merged this pull request and I will work on trying to find sources for older versions.

ellipse12 commented 1 month ago

Oh wait I found the previous versions. It will probably take a day or two to do all of them.

ellipse12 commented 1 month ago

Finished adding all of the previous versions! I also tested it by making a simple triangle and everything seemed to work.

lerno commented 4 weeks ago

Awesome work!