November 25, 2020, 01:46:44 PM

Author Topic: Any chance of a GLFW port?  (Read 6991 times)

Offline DruggedBunny

  • Jr. Member
  • **
  • Posts: 60
Any chance of a GLFW port?
« on: March 10, 2020, 02:04:32 AM »
Hi Brucey,

Just wondering if you've looked at GLFW and how easy/difficult it would be to port?

I've been playing with this site's tutorials in Visual Studio, but would much rather be doing it in Blitz!

But I can't for the life of me figure out the basics of setting up an OpenGL window in Max with the right context version/profile, totally confused by the potential mixes of GLEW, GLAD, SDL, GLGraphics, etc, etc and I've been trawling through the mod sources for hours trying to figure it out, to no avail!

I'm basically hoping to be able to implement the window setup here using GLFW:

https://learnopengl.com/Getting-started/Hello-Window

I don't know if you're big on new library requests, but if you don't ask... !

Failing that, does anyone have a simple example that would implement a version 3.3 core profile??

Thanks for reading,
James Boyd/DruggedBunny.

Offline Brucey

  • Full Member
  • ***
  • Posts: 136
Re: Any chance of a GLFW port?
« Reply #1 on: March 10, 2020, 06:30:04 AM »
Hi James :)

You may find this interesting : https://github.com/bmx-ng/ray.mod

It is a binding for raylib, which actually uses GLFW for windowing and events, etc.

Okay, so it's not directly using it in actual BlitzMax code.. so it's a bit of a cheat. However, I guess it proves it wouldn't be a giant leap to implement it properly.

Offline DruggedBunny

  • Jr. Member
  • **
  • Posts: 60
Re: Any chance of a GLFW port?
« Reply #2 on: March 10, 2020, 08:18:58 AM »
Oh, cool, thanks, Brucey!

I'll have a look tonight to see if I can see how it's been done, but if you find yourself bored one day... !

I know GLAD is in there already, so it would make NG pretty darn handy for use with LearnOpenGL.

Thanks again.

Offline Brucey

  • Full Member
  • ***
  • Posts: 136
Re: Any chance of a GLFW port?
« Reply #3 on: March 10, 2020, 04:37:05 PM »
If I was going to do it, I'd be more inclined to make it more "BlitzMaxy", so rather than have to pass a window handle into all the window functions, there'd be a Type that hides that...

Although if you really wanted to stay true to the examples, you could still work with the "raw" functions.

Offline DruggedBunny

  • Jr. Member
  • **
  • Posts: 60
Re: Any chance of a GLFW port?
« Reply #4 on: March 10, 2020, 09:56:50 PM »
No complaints from me, Brucey, if you find yourself with time on your hands... ;)

I just want a nice easy way to set up windows/contexts with particular feature sets of OpenGL (eg. 3.3 in the tutorial, with Core Profile) so I can play with the actual GL code, and this was nice and easy for me to grasp in C++ with GLFW, but it's just... no fun!

Thanks for considering, appreciated!

Offline Brucey

  • Full Member
  • ***
  • Posts: 136
Re: Any chance of a GLFW port?
« Reply #5 on: March 11, 2020, 07:12:31 AM »
Would something like this work for you?
Code: [Select]
SuperStrict

Framework GLFW.GLFWWindow
Import GLFW.GLFWOpenGL

' settings
Const SCR_WIDTH:Int = 800
Const SCR_HEIGHT:Int = 600

' glfw: initialize and configure
TGLFWWindow.Hint(GLFW_CONTEXT_VERSION_MAJOR, 3)
TGLFWWindow.Hint(GLFW_CONTEXT_VERSION_MINOR, 3)
TGLFWWindow.Hint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE)

' glfw window creation
Local window:TGLFWWindow = New TMyWindow.Create(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL")

If Not window Then
Throw "Failed to create GLFW window"
End If


window.MakeContextCurrent()

' glad: load all OpenGL function pointers
gladLoadGL(glfwGetProcAddress)

' render loop
While Not window.ShouldClose()

' input
ProcessInput(window)

' render
glClearColor(0.2, 0.3, 0.3, 1.0)
glClear(GL_COLOR_BUFFER_BIT)

' glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
window.SwapBuffers()
PollSystem

Wend

' process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
Function ProcessInput(window:TGLFWWindow)
If window.IsKeyDown(GLFW_KEY_ESCAPE) Then
window.SetShouldClose(True)
End If
End Function

Type TMyWindow Extends TGLFWWindow

' glfw: whenever the window size changed (by OS or user resize) this callback function executes
Method OnFramebufferSize(width:Int, height:Int) Override

' make sure the viewport matches the new window dimensions; note that width and
' height will be significantly larger than specified on retina displays.
glViewport(0, 0, width, height)
End Method

End Type

It's a bit rough around the edges at the moment - for example, I'm still toying with having the "load gl" bit done automagically somewhere...

The window handles all the callbacks, so you just override the ones you are interested in...

Offline DruggedBunny

  • Jr. Member
  • **
  • Posts: 60
Re: Any chance of a GLFW port?
« Reply #6 on: March 11, 2020, 08:21:03 AM »
Yeah, that looks great to me!

It is relatively low-level stuff, especially since half the point is to get into 'raw' OpenGL, so I don't think it's too much of a hardship to have to call the one-line GLAD loader, though I get where you're coming from.

Look forward to trying it -- I'll basically be going through the tutorial (admittedly rather slowly), so should get to give it a good test anyway.

Offline Brucey

  • Full Member
  • ***
  • Posts: 136
Re: Any chance of a GLFW port?
« Reply #7 on: March 11, 2020, 05:26:37 PM »
Evening  8)

See how you get on with : https://github.com/bmx-ng/glfw.mod

There is one example - which is basically the first learnOpenGL example.
I've used the default GLAD header from which to generate the sources from. If that doesn't cover everything you need, let me know and I'll see about generating a new header with a higher OpenGL level.

It's only been tested on Win32 64-bit so far, so YMMV anywhere else.

Offline DruggedBunny

  • Jr. Member
  • **
  • Posts: 60
Re: Any chance of a GLFW port?
« Reply #8 on: March 11, 2020, 11:36:02 PM »
Wow, Brucey, I'm sure I've said it a fair few times, but you are truly a god among men! I only posted thinking you might add it to a list of possibles, if I was lucky!

The sample works here (I'm on Windows 7 64-bit anyway), so I'll dig in over the next few days and see if I can implement a few more samples, and try keep them in order to add to the mod examples.

I'll buy you a few pints at the end of the month... thank you so much for this!

Offline Brucey

  • Full Member
  • ***
  • Posts: 136
Re: Any chance of a GLFW port?
« Reply #9 on: March 12, 2020, 06:21:35 AM »
Heh, glad I could be useful :)

It's all gone rather smoothly so far. No major hiccups as yet - although I should probably get around to trying it on some of the other platforms at some point.
I'll get the rest of the apis implemented and document it a bit more too.


And as it happens, we are doing a special on github sponsorship at the moment, available from only $1 a month. But no worries either way ;)

Have fun!

Offline Derron

  • Hero Member
  • *****
  • Posts: 3261
Re: Any chance of a GLFW port?
« Reply #10 on: March 12, 2020, 07:12:24 AM »
And as it happens, we are doing a special on github sponsorship at the moment, available from only $1 a month. But no worries either way ;)

Dunno how long (it is for "one year") but the next few months github will double what you sponsor. So my fiver becomes a tenner.


Will try the sample on linux when back at home.


bye
Ron

Offline Brucey

  • Full Member
  • ***
  • Posts: 136
Re: Any chance of a GLFW port?
« Reply #11 on: March 12, 2020, 07:14:50 AM »
As I say, I haven't tried it on any other targets yet, and usually it requires a few tweaks to get things sorted.... don't hold your breath.

Offline DruggedBunny

  • Jr. Member
  • **
  • Posts: 60
Re: Any chance of a GLFW port?
« Reply #12 on: March 12, 2020, 08:09:48 AM »
Ha, didn't even know GitHub sponsorship was a thing! I'll look into it!

Offline Brucey

  • Full Member
  • ***
  • Posts: 136
Re: Any chance of a GLFW port?
« Reply #13 on: March 12, 2020, 04:30:07 PM »
It now builds and runs on 64-bit Linux (Ubuntu).

Offline DruggedBunny

  • Jr. Member
  • **
  • Posts: 60
Re: Any chance of a GLFW port?
« Reply #14 on: March 13, 2020, 05:53:33 AM »
Nice!

Just to show I'm doing something with this, I've started converting some of the GitHub samples.

Done 1.1 and 1.2, which basically puts me at your sample! However, I'm attempting to implement each from scratch myself, just referencing your sample to get the hang of the differences.

I'll do a few more tonight/tomorrow (oh, and will look at patronage) and post somewhere, then move on to the tutorial proper, which I was trying to do in C++ without reference to the 'answers' (ie. final source) so as to better understand what was going on.

It's ten to six, so I'm going back to bed...

Thanks again, Brucey.

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal