cxgo icon indicating copy to clipboard operation
cxgo copied to clipboard

Add GLFW/glfw3.h and update opengl.h

Open TotallyGamerJet opened this issue 3 years ago • 8 comments

TotallyGamerJet avatar Aug 18 '21 01:08 TotallyGamerJet

I wouldn't merge it just yet. I wanted to make sure the header looked good before I wrote an adapter. I had a few questions:

  • what to do about glfwSetErrorCallback. There is no equivalent in the go-gl/glfw library. Should I just make a function that does nothing in the adapter library?
  • Also, I didn't know how to properly handle the callbacks. The set callbacks functions are methods on a window which is easy enough to implement. However, the callback function itself takes a pointer to the window. How would I define a callback type since the windowT wasn't defined yet?
  • Once I finished the adapter library would it be cloned onto gotranspile account?

TotallyGamerJet avatar Aug 18 '21 12:08 TotallyGamerJet

what to do about glfwSetErrorCallback. There is no equivalent in the go-gl/glfw library. Should I just make a function that does nothing in the adapter library?

Yes, looking at the name we can fake it for now.

Also, I didn't know how to properly handle the callbacks. The set callbacks functions are methods on a window which is easy enough to implement. However, the callback function itself takes a pointer to the window. How would I define a callback type since the windowT wasn't defined yet?

If I understand correctly you are asking how to define a pointer to a type, before defining the type, right?

If so, you can check how FILE is defined. The general idea is that you first create a pointer type with no underlying type (aka void*), then define a named type with all the callback which can potentially use the pointer type that you defined, and then set the underlying type of the pointer to the named type you just created.

Once I finished the adapter library would it be cloned onto gotranspile account?

Yes, if it's okay for you. It would be easier to move it to the same org. I should also invite you to the organization, by the way.

dennwc avatar Aug 18 '21 15:08 dennwc

@dennwc sorry I haven’t been working on this. I have been busy with uni. I’m not sure when I’ll have time again to work on the commit. It is just missing some callbacks and methods but overall it is correct. If you want to just merge this in you can or wait until I have time to add the rest. Also the gotranspile/glfw is 100% done as long as there are no future functions that need specific changes. I don’t know any off the top of my head.

TotallyGamerJet avatar Aug 29 '21 13:08 TotallyGamerJet

Hello, I was wondering if the end-goal of this work is to transpile glfw to pure go ? I've seen this adapter https://github.com/gotranspile/glfw, but I don't understand its use, is it a first step toward it ? edit: Also I probably should have created an issue there ? (Sorry)

Zyko0 avatar Nov 03 '21 10:11 Zyko0

Hey @Zyko0 ! Cxgo could be used to eventually transpile GLFW to pure Go, but that's not the main goal. This specific PR make it easier to transpile C projects that use GLFW to Go. Having said that, it would be interesting to try what you proposed.

dennwc avatar Nov 14 '21 20:11 dennwc

Thank you for clarifying ! Yes we might need to port glfw to Go for https://github.com/hajimehoshi/ebiten project anyway, so I wanted to know if this work started somewhere else 😅

Zyko0 avatar Nov 14 '21 20:11 Zyko0

@Zyko0 I've actually really wanted to port glfw to pure go. The main issue is that it would require porting the windowing apis for windows and linux. There are many pure go windows api libraries but none are complete so someone would need to use the metadata to generate it (see this issue). For linux, there is an XCB port but glfw uses XLib and wayland so those would need to be ported. Then headers will also need to be written which would be a lot of work. Either way, glfw on mac would still require c because there is no way to create a window without ObjC. It's a noble effort that I hope eventually gets done!

TotallyGamerJet avatar Nov 15 '21 03:11 TotallyGamerJet

@TotallyGamerJet Thanks for your explanations about the current state of such a port ! 😄

Zyko0 avatar Nov 16 '21 16:11 Zyko0

This is open for quite a while now, so I'll review it again and will port these changes to main branch.

dennwc avatar May 30 '23 20:05 dennwc

Oh wow it definitely has. I totally forgot about this. I could take a look today and if it's not too difficult to port to main I can do that.

TotallyGamerJet avatar May 31 '23 10:05 TotallyGamerJet

Closing in favor of #71

TotallyGamerJet avatar Jun 02 '23 02:06 TotallyGamerJet