GLFW+ Freebasic
GLFW+ Freebasic
(OS bullseye, Raspbian 4b, FB1.09)
Hello
I wanted to run glfw_splitview.bas example
located in
examples/graphics/OpenGL
To do this, I downloaded the corresponding GLFW library
sudo apt-get update
sudo apt-get install libglfw3
sudo apt-get install libglfw3-dev
But when run, the compiler writes:
ld: FBscrres1a1.o: in "main" function:
FBscrres1a1.c:(.text+0x152c): undefined reference to "glfwOpenWindow"
ld: FBscrres1a1.c:(.text+0x1568): undefined reference to "glfwEnable"
ld: FBscrres1a1.c:(.text+0x1574): undefined reference to "glfwEnable"
ld: FBscrres1a1.c:(.text+0x158c): undefined reference to "glfwSetMousePosCallback"
ld: FBscrres1a1.c:(.text+0x15e0): undefined reference to "glfwSleep"
m etc.
What am I doing wrong and what needs to be done?
Sincerely PavelUT
Hello
I wanted to run glfw_splitview.bas example
located in
examples/graphics/OpenGL
To do this, I downloaded the corresponding GLFW library
sudo apt-get update
sudo apt-get install libglfw3
sudo apt-get install libglfw3-dev
But when run, the compiler writes:
ld: FBscrres1a1.o: in "main" function:
FBscrres1a1.c:(.text+0x152c): undefined reference to "glfwOpenWindow"
ld: FBscrres1a1.c:(.text+0x1568): undefined reference to "glfwEnable"
ld: FBscrres1a1.c:(.text+0x1574): undefined reference to "glfwEnable"
ld: FBscrres1a1.c:(.text+0x158c): undefined reference to "glfwSetMousePosCallback"
ld: FBscrres1a1.c:(.text+0x15e0): undefined reference to "glfwSleep"
m etc.
What am I doing wrong and what needs to be done?
Sincerely PavelUT
Re: GLFW+ Freebasic
I think you need to look at the header files to extract the functions and rewrite them to suit fb, like the .bi files for other libraries.
But I don't have Linux, so that is as far as I can go here.
But I don't have Linux, so that is as far as I can go here.
Re: GLFW+ Freebasic
looks like those functions have been replaced by other functions, like glfwOpenWindow is probably glfwCreateWindow looks like the bi is outdated
here are the Windows dll exports, the functions should be cross-platform
here are the Windows dll exports, the functions should be cross-platform
Code: Select all
LIBRARY glfw3.dll
EXPORTS
glfwCreateCursor
glfwCreateStandardCursor
glfwCreateWindow
glfwCreateWindowSurface
glfwDefaultWindowHints
glfwDestroyCursor
glfwDestroyWindow
glfwExtensionSupported
glfwFocusWindow
glfwGetClipboardString
glfwGetCurrentContext
glfwGetCursorPos
glfwGetEGLContext
glfwGetEGLDisplay
glfwGetEGLSurface
glfwGetError
glfwGetFramebufferSize
glfwGetGamepadName
glfwGetGamepadState
glfwGetGammaRamp
glfwGetInputMode
glfwGetInstanceProcAddress
glfwGetJoystickAxes
glfwGetJoystickButtons
glfwGetJoystickGUID
glfwGetJoystickHats
glfwGetJoystickName
glfwGetJoystickUserPointer
glfwGetKey
glfwGetKeyName
glfwGetKeyScancode
glfwGetMonitorContentScale
glfwGetMonitorName
glfwGetMonitorPhysicalSize
glfwGetMonitorPos
glfwGetMonitorUserPointer
glfwGetMonitorWorkarea
glfwGetMonitors
glfwGetMouseButton
glfwGetOSMesaColorBuffer
glfwGetOSMesaContext
glfwGetOSMesaDepthBuffer
glfwGetPhysicalDevicePresentationSupport
glfwGetPrimaryMonitor
glfwGetProcAddress
glfwGetRequiredInstanceExtensions
glfwGetTime
glfwGetTimerFrequency
glfwGetTimerValue
glfwGetVersion
glfwGetVersionString
glfwGetVideoMode
glfwGetVideoModes
glfwGetWGLContext
glfwGetWin32Adapter
glfwGetWin32Monitor
glfwGetWin32Window
glfwGetWindowAttrib
glfwGetWindowContentScale
glfwGetWindowFrameSize
glfwGetWindowMonitor
glfwGetWindowOpacity
glfwGetWindowPos
glfwGetWindowSize
glfwGetWindowUserPointer
glfwHideWindow
glfwIconifyWindow
glfwInit
glfwInitHint
glfwJoystickIsGamepad
glfwJoystickPresent
glfwMakeContextCurrent
glfwMaximizeWindow
glfwPollEvents
glfwPostEmptyEvent
glfwRawMouseMotionSupported
glfwRequestWindowAttention
glfwRestoreWindow
glfwSetCharCallback
glfwSetCharModsCallback
glfwSetClipboardString
glfwSetCursor
glfwSetCursorEnterCallback
glfwSetCursorPos
glfwSetCursorPosCallback
glfwSetDropCallback
glfwSetErrorCallback
glfwSetFramebufferSizeCallback
glfwSetGamma
glfwSetGammaRamp
glfwSetInputMode
glfwSetJoystickCallback
glfwSetJoystickUserPointer
glfwSetKeyCallback
glfwSetMonitorCallback
glfwSetMonitorUserPointer
glfwSetMouseButtonCallback
glfwSetScrollCallback
glfwSetTime
glfwSetWindowAspectRatio
glfwSetWindowAttrib
glfwSetWindowCloseCallback
glfwSetWindowContentScaleCallback
glfwSetWindowFocusCallback
glfwSetWindowIcon
glfwSetWindowIconifyCallback
glfwSetWindowMaximizeCallback
glfwSetWindowMonitor
glfwSetWindowOpacity
glfwSetWindowPos
glfwSetWindowPosCallback
glfwSetWindowRefreshCallback
glfwSetWindowShouldClose
glfwSetWindowSize
glfwSetWindowSizeCallback
glfwSetWindowSizeLimits
glfwSetWindowTitle
glfwSetWindowUserPointer
glfwShowWindow
glfwSwapBuffers
glfwSwapInterval
glfwTerminate
glfwUpdateGamepadMappings
glfwVulkanSupported
glfwWaitEvents
glfwWaitEventsTimeout
glfwWindowHint
glfwWindowHintString
glfwWindowShouldClose
Re: GLFW+ Freebasic
Well, let the code be outdated. In this case I am trying to compile the program
attached with FB1.09 as an example. So the program must compile and run.
What needs to be done for this?
OS Linux
attached with FB1.09 as an example. So the program must compile and run.
What needs to be done for this?
OS Linux
Re: GLFW+ Freebasic
Extract from glfw3.bi
In order to compile that example, find and install binaries for version 3.1.1.
Code: Select all
#define _glfw3_h_
const GLFW_VERSION_MAJOR = 3
const GLFW_VERSION_MINOR = 1
const GLFW_VERSION_REVISION = 1
Re: GLFW+ Freebasic
I don't understand you a bit. I already installed the libraries:
sudo apt-get install libglfw3
sudo apt-get install libglfw3-dev
sudo apt-get install libglfw3
sudo apt-get install libglfw3-dev
Re: GLFW+ Freebasic
PavelUT, the example you are trying to compile will not compile as is, a number of details would need to be changed besides using an updated glfw.bi or more correctly use glfw3.bi
in Linux you might still be able to get glfw2, that might be compatible with the current glfw.bi and examples
in Linux you might still be able to get glfw2, that might be compatible with the current glfw.bi and examples
Re: GLFW+ Freebasic
I tested on windows.
the .bi file is for
const GLFW_VERSION_MAJOR = 2
const GLFW_VERSION_MINOR = 7
const GLFW_VERSION_REVISION = 9
I.e. 2.7.9
But I downloaded that version and compiled to libglwf.a, still many errors.
I'll try creating a 64 bit .dll later.
the .bi file is for
const GLFW_VERSION_MAJOR = 2
const GLFW_VERSION_MINOR = 7
const GLFW_VERSION_REVISION = 9
I.e. 2.7.9
But I downloaded that version and compiled to libglwf.a, still many errors.
I'll try creating a 64 bit .dll later.
Re: GLFW+ Freebasic
Hi dodicat
you inspired me to try and build glfw-2.7.9, here are my libs https://drive.google.com/file/d/1D4ZBuo ... sp=sharing
the example glfw_splitview.bas compiles ok and it runs but the screen flashes, the graphics show alright but it flashes a lot
[edit]
got the source from https://github.com/glfw/glfw-legacy
compile from msys2-shell
make win32-msys
[edit2]
if you click on the screen then the flashing stops, sometimes the frame still flashes
you inspired me to try and build glfw-2.7.9, here are my libs https://drive.google.com/file/d/1D4ZBuo ... sp=sharing
the example glfw_splitview.bas compiles ok and it runs but the screen flashes, the graphics show alright but it flashes a lot
[edit]
got the source from https://github.com/glfw/glfw-legacy
compile from msys2-shell
make win32-msys
[edit2]
if you click on the screen then the flashing stops, sometimes the frame still flashes
Re: GLFW+ Freebasic
Hello, thank you very much for your concern.
I figured out what the problem is. For my configuration
(OS bullseye, Raspbian 4b, FB1.09) need library
GLFW version 2, and I installed 3.
In order to run the example, I had to remove 3
version and install the second one, after which everything compiled normally.
Thanks for the help.
1 more question, 3 is it possible to make GLFW3 work
if the video card only supports OpenGl2
I figured out what the problem is. For my configuration
(OS bullseye, Raspbian 4b, FB1.09) need library
GLFW version 2, and I installed 3.
In order to run the example, I had to remove 3
version and install the second one, after which everything compiled normally.
Thanks for the help.
1 more question, 3 is it possible to make GLFW3 work
if the video card only supports OpenGl2
Re: GLFW+ Freebasic
Use fbfrog to make your own header. No one will make it for you. If you ask for, they will say you have no rights to ask. So it's better to do it yourself.
https://github.com/freebasic/fbfrog
Starting with glfw3.h
https://github.com/freebasic/fbfrog
Starting with glfw3.h
Re: GLFW+ Freebasic
Package libglfw3-dev installs libglfw3 as a dependency, you need not install the later explicitly.
The number 3 in the package name does not mean that it's compiled from a source code with major version 3. In order to find out the source code version execute
Code: Select all
dpkg -l glfw3
Anyway, the header must match the binary version (as close as possible). You can also use h_2_bi for translation, watching (and learning) the process line by line in Geany IDE.
@960305 (miilvyxg, j8w344c6, ...)
Back again?
Re: GLFW+ Freebasic
No need to use dpkg. You can check it on the web.
https://packages.debian.org/en/bullseye/libglfw3-dev
https://packages.debian.org/en/bullseye/libglfw3-dev
Re: GLFW+ Freebasic
with the aid of fbfrog I translated the splitview example, it's a bit C'ish but it works
the only flaw that I notice is the outline when click&drag on the bottom-right pane is wrong
maybe dodicat will spot the error and correct it
the code could be cleaned up to make it more Basic
the only flaw that I notice is the outline when click&drag on the bottom-right pane is wrong
maybe dodicat will spot the error and correct it
the code could be cleaned up to make it more Basic
Code: Select all
#pragma once
#include once "GL/glfw.bi"
#include once "crt/math.bi"
#include once "crt/stdio.bi"
#include once "crt/stdlib.bi"
extern "C"
'const M_PI = 3.14159265358979323846
dim shared xpos as long = 0
dim shared ypos as long = 0
dim shared width_ as long
dim shared height as long
dim shared active_view as long = 0
dim shared rot_x as long = 0
dim shared rot_y as long = 0
dim shared rot_z as long = 0
dim shared do_redraw as long = 1
const TORUS_MAJOR = 1.5
const TORUS_MINOR = 0.5
const TORUS_MAJOR_RES = 32
const TORUS_MINOR_RES = 32
private sub drawTorus()
static torus_list as GLuint = 0
dim i as long
dim j as long
dim k as long
dim s as double
dim t as double
dim x as double
dim y as double
dim z as double
dim nx as double
dim ny as double
dim nz as double
dim scale as double
dim twopi as double
if torus_list = 0 then
torus_list = glGenLists(1)
glNewList(torus_list, GL_COMPILE_AND_EXECUTE)
twopi = 2.0 * 3.14159265358979323846
for i=0 to TORUS_MINOR_RES-1
glBegin(GL_QUAD_STRIP)
for j=0 to TORUS_MAJOR_RES
for k=1 to 0 step -1
s = ((i + k) mod 32) + 0.5
t = j mod 32
x = (1.5 + (0.5 * cos((s * twopi) / 32))) * cos((t * twopi) / 32)
y = 0.5 * sin((s * twopi) / 32)
z = (1.5 + (0.5 * cos((s * twopi) / 32))) * sin((t * twopi) / 32)
nx = x - (1.5 * cos((t * twopi) / 32))
ny = y
nz = z - (1.5 * sin((t * twopi) / 32))
scale = 1.0 / sqrt(((nx * nx) + (ny * ny)) + (nz * nz))
nx *= scale
ny *= scale
nz *= scale
glNormal3f(csng(nx), csng(ny), csng(nz))
glVertex3f(csng(x), csng(y), csng(z))
next
next
glEnd()
next
glEndList()
else
glCallList(torus_list)
end if
end sub
private sub drawScene()
dim model_diffuse(0 to 3) as const GLfloat = {1.0f, 0.8f, 0.8f, 1.0f}
dim model_specular(0 to 3) as const GLfloat = {0.6f, 0.6f, 0.6f, 1.0f}
dim model_shininess as const GLfloat = 20.0f
glPushMatrix()
glRotatef( cast(GLfloat,rot_x)*0.5!, 1.0!, 0.0!, 0.0! )
glRotatef( cast(GLfloat,rot_y)*0.5!, 0.0!, 1.0!, 0.0! )
glRotatef( cast(GLfloat,rot_z)*0.5!, 0.0!, 0.0!, 1.0! )
glColor4fv(@model_diffuse(0))
glMaterialfv(GL_FRONT, GL_DIFFUSE, @model_diffuse(0))
glMaterialfv(GL_FRONT, GL_SPECULAR, @model_specular(0))
glMaterialf(GL_FRONT, GL_SHININESS, model_shininess)
drawTorus()
glPopMatrix()
end sub
private sub drawGrid(byval scale as single, byval steps as long)
dim i as long
dim x as single
dim y as single
glPushMatrix()
glClearColor(0.05f, 0.05f, 0.2f, 0.0f)
glClear(GL_COLOR_BUFFER_BIT)
glLoadIdentity()
gluLookAt(0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
glDepthMask(GL_FALSE)
glColor3f(0.0f, 0.5f, 0.5f)
glBegin(GL_LINES)
x = (scale * 0.5f) * csng(steps - 1)
y = ((-scale) * 0.5f) * csng(steps - 1)
for i=0 to steps-1
glVertex3f(-x, y, 0.0f)
glVertex3f(x, y, 0.0f)
y += scale
next
x = ((-scale) * 0.5f) * csng(steps - 1)
y = (scale * 0.5f) * csng(steps - 1)
for i=0 to steps-1
glVertex3f(x, -y, 0.0f)
glVertex3f(x, y, 0.0f)
x += scale
next
glEnd()
glDepthMask(GL_TRUE)
glPopMatrix()
end sub
private sub drawAllViews()
dim light_position(0 to 3) as const GLfloat = {0.0f, 8.0f, 8.0f, 1.0f}
dim light_diffuse(0 to 3) as const GLfloat = {1.0f, 1.0f, 1.0f, 1.0f}
dim light_specular(0 to 3) as const GLfloat = {1.0f, 1.0f, 1.0f, 1.0f}
dim light_ambient(0 to 3) as const GLfloat = {0.2f, 0.2f, 0.3f, 1.0f}
dim aspect as double
if height > 0 then
aspect = cdbl(width_) / cdbl(height)
else
aspect = 1.0
end if
glClearColor(0.0f, 0.0f, 0.0f, 0.0f)
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glEnable(GL_SCISSOR_TEST)
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
glEnable(GL_LINE_SMOOTH)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho((-3.0) * aspect, 3.0 * aspect, -3.0, 3.0, 1.0, 50.0)
glViewport(0, height / 2, width_ / 2, height / 2)
glScissor(0, height / 2, width_ / 2, height / 2)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(0.0f, 10.0f, 1e-3f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f)
drawGrid(0.5, 12)
drawScene()
glViewport(0, 0, width_ / 2, height / 2)
glScissor(0, 0, width_ / 2, height / 2)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(0.0f, 0.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f)
drawGrid(0.5, 12)
drawScene()
glViewport(width_ / 2, 0, width_ / 2, height / 2)
glScissor(width_ / 2, 0, width_ / 2, height / 2)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f)
drawGrid(0.5, 12)
drawScene()
glDisable(GL_LINE_SMOOTH)
glDisable(GL_BLEND)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
glEnable(GL_CULL_FACE)
glCullFace(GL_BACK)
glFrontFace(GL_CW)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(65.0f, aspect, 1.0f, 50.0f)
glViewport(width_ / 2, height / 2, width_ / 2, height / 2)
glScissor(width_ / 2, height / 2, width_ / 2, height / 2)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(3.0f, 1.5f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f)
glLightfv(GL_LIGHT1, GL_POSITION, @light_position(0))
glLightfv(GL_LIGHT1, GL_AMBIENT, @light_ambient(0))
glLightfv(GL_LIGHT1, GL_DIFFUSE, @light_diffuse(0))
glLightfv(GL_LIGHT1, GL_SPECULAR, @light_specular(0))
glEnable(GL_LIGHT1)
glEnable(GL_LIGHTING)
drawScene()
glDisable(GL_LIGHTING)
glDisable(GL_CULL_FACE)
glDisable(GL_DEPTH_TEST)
glDisable(GL_SCISSOR_TEST)
if (active_view > 0) andalso (active_view <> 2) then
glViewport(0, 0, width_, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0.0, 2.0, 0.0, 2.0, 0.0, 1.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glColor3f(1.0f, 1.0f, 0.6f)
glTranslatef( cast(GLfloat,(active_view - 1) and 1), cast(GLfloat,1 - ((active_view - 1) / 2)), 0.0!)
glBegin(GL_LINE_STRIP)
glVertex2i(0, 0)
glVertex2i(1, 0)
glVertex2i(1, 1)
glVertex2i(0, 1)
glVertex2i(0, 0)
glEnd()
end if
end sub
private sub windowSizeFun(byval w as long, byval h as long)
width_ = w
height = iif(h > 0, h, 1)
do_redraw = 1
end sub
private sub windowRefreshFun()
do_redraw = 1
end sub
private sub mousePosFun(byval x as long, byval y as long)
select case active_view
case 1
rot_x += y - ypos
rot_z += x - xpos
do_redraw = 1
exit select
case 3
rot_x += y - ypos
rot_y += x - xpos
do_redraw = 1
exit select
case 4
rot_y += x - xpos
rot_z += y - ypos
do_redraw = 1
end select
xpos = x
ypos = y
end sub
private sub mouseButtonFun(byval button as long, byval action as long)
if (button = 0) andalso (action = 1) then
active_view = 1
if xpos >= (width_ / 2) then
active_view += 1
end if
if ypos >= (height / 2) then
active_view += 2
end if
elseif button = 0 then
active_view = 0
end if
do_redraw = 1
end sub
end extern
private function main() as long
if glfwInit() = 0 then
fprintf(stderr, !"Failed to initialize GLFW\n")
return (EXIT_FAILURE)
end if
if glfwOpenWindow(500, 500, 0, 0, 0, 0, 16, 0, GLFW_WINDOW) = 0 then
fprintf(stderr, !"Failed to open GLFW window\n")
glfwTerminate()
return (EXIT_FAILURE)
end if
glfwSwapInterval(1)
glfwSetWindowTitle("Split view demo")
glfwEnable(GLFW_STICKY_KEYS)
glfwEnable(GLFW_MOUSE_CURSOR)
glfwDisable(GLFW_AUTO_POLL_EVENTS)
glfwSetWindowSizeCallback(@windowSizeFun)
glfwSetWindowRefreshCallback(@windowRefreshFun)
glfwSetMousePosCallback(@mousePosFun)
glfwSetMouseButtonCallback(@mouseButtonFun)
do
if do_redraw then
drawAllViews()
glfwSwapBuffers()
do_redraw = 0
end if
glfwWaitEvents()
loop while (glfwGetKey(GLFW_KEY_ESC) <> GLFW_PRESS) andalso glfwGetWindowParam(GLFW_OPENED)
glfwTerminate()
return (EXIT_SUCCESS)
end function
main()