How to initialise and use OpenGL (not OGRE) in MacOSX
How to initialise and use OpenGL (not OGRE) in MacOSX
Hello,
I have a working Windows and Linux application in PB that uses direct OpenGL API to show 3D objects.
Does someone know how to initialise OpenGL (not OGRE) and use its API from PB in MacOSX (x86) ?
Regards.
I have a working Windows and Linux application in PB that uses direct OpenGL API to show 3D objects.
Does someone know how to initialise OpenGL (not OGRE) and use its API from PB in MacOSX (x86) ?
Regards.
Niffo
Ok, so here is the minimum to initialize and use OpenGL with Glut on MacOS
Code: Select all
EnableExplicit
ImportC "/System/Library/Frameworks/GLUT.framework/GLUT"
glutInit(*argcp.i, *argv.b)
glutInitDisplayMode(mode.i)
glutInitWindowPosition(x.i, y.i)
glutInitWindowSize(width.i, height.i)
glutMainLoop()
glutCreateWindow(title.s)
glutFullScreen()
glutDisplayFunc(*Proc)
glutIdleFunc(*Proc)
glutSwapBuffers()
EndImport
ImportC "/System/Library/Frameworks/OpenGL.framework/OpenGL"
glClear(mask.l)
glClearColor(red.f, green.f, blue.f, alpha.f)
EndImport
;IncludeFile "gl.pbi"
#GL_COLOR_BUFFER_BIT = $00004000
#GL_DEPTH_BUFFER_BIT = $00000100
;IncludeFile "glut.pbi"
#GLUT_RGB = $0000
#GLUT_DEPTH = $0010
#GLUT_DOUBLE = $0002
ProcedureC draw()
glClearColor(1, 0, 0, 0)
glClear(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glutSwapBuffers()
EndProcedure
Define a = 0
glutInit(@a, 0)
glutInitWindowSize(256, 256);
glutInitWindowPosition(0, 0);
glutInitDisplayMode(#GLUT_RGB | #GLUT_DEPTH | #GLUT_DOUBLE);
glutCreateWindow("Title")
glutDisplayFunc(@draw())
;glutIdleFunc(@draw())
;glutKeyboardFunc(@key())
;glutReshapeFunc(@reshape())
glutMainLoop()
Niffo
And here is the minimum to initialize OpenGL on a PB Window without the use of GLUT :
Code: Select all
EnableExplicit
ImportC "/System/Library/Frameworks/OpenGL.framework/OpenGL"
glClear(mask.l)
glClearColor(red.f, green.f, blue.f, alpha.f)
EndImport
;IncludeFile "gl.pbi"
#GL_COLOR_BUFFER_BIT = $00004000
#GL_DEPTH_BUFFER_BIT = $00000100
ImportC "/System/Library/Frameworks/AGL.framework/AGL"
aglChoosePixelFormat.l(*gdevs, ndev.i, *attribs.i)
aglDestroyContext.b(ctx.l);
aglDestroyPixelFormat(pix.l)
aglCreateContext.l(pix.l, share.l)
aglSetDrawable.b(ctx.l, draw.l)
aglSetCurrentContext.b(ctx.l)
aglSwapBuffers(ctx.l)
EndImport
;IncludeFile "agl.pbi"
#AGL_NONE = 0
#AGL_RGBA = 4
#AGL_DOUBLEBUFFER = 5
#AGL_DEPTH_SIZE = 12
ImportC "/System/Library/Frameworks/Carbon.framework/Carbon"
GetWindowPort.l(window.l)
EndImport
OpenWindow (0, 100, 100, 256, 256, "OpenGL Window")
Dim attributes.i(4)
attributes(0) = #AGL_RGBA
attributes(1) = #AGL_DOUBLEBUFFER
attributes(2) = #AGL_DEPTH_SIZE
attributes(3) = 24
attributes(4) = #AGL_NONE
Define.l myAGLContext = #Null
Define.l myAGLPixelFormat
myAGLPixelFormat = aglChoosePixelFormat(#Null, 0, @attributes())
If myAGLPixelFormat
myAGLContext = aglCreateContext(myAGLPixelFormat, #Null)
aglSetDrawable(myAGLContext, GetWindowPort(WindowID(0)))
aglSetCurrentContext(myAGLContext)
aglDestroyPixelFormat(myAGLPixelFormat)
EndIf
Repeat
Select WaitWindowEvent(10)
Case #PB_Event_CloseWindow
Break
Default
glClearColor(1, 0, 0, 0)
glClear(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
aglSwapBuffers(myAGLContext)
EndSelect
ForEver
Niffo
Thank you for answering to yourself!
Could be useful in the future.
Ehm, please forgive me, but could you share the code you use under linux to open a opengl window with PB ? If possibile both windowed and full screen ? I probably need to look into that in the future and a working example could point me in the right direction from the start.
Thanks.
Could be useful in the future.
Ehm, please forgive me, but could you share the code you use under linux to open a opengl window with PB ? If possibile both windowed and full screen ? I probably need to look into that in the future and a working example could point me in the right direction from the start.
Thanks.
Maybe you can start with the excellent work of "remi_meier" :
http://www.purebasic.fr/english/viewtop ... 261#223261
http://www.purebasic.fr/english/viewtop ... 261#223261
Niffo
Re:
Thanks to Fred's little throw away comment in another thread, tis easy - simply set the subsystem to opengl first:luis wrote:Ehm, please forgive me, but could you share the code you use under linux to open a opengl window with PB ? If possibile both windowed and full screen ? I probably need to look into that in the future and a working example could point me in the right direction from the start.
Code: Select all
InitSprite()
ImportC "/usr/lib/libX11.a"+Chr('"')+" -l"+Chr('"')+"GL"
glClear(color.l)
glClearColor(r.f,g.f,b.f,a.f)
EndImport
#GL_COLOR_BUFFER_BIT = $00004000
#GL_DEPTH_BUFFER_BIT = $00000100
OpenWindow (0, 100, 100, 256, 256, "OpenGL Window")
OpenWindowedScreen(WindowID(0), 0, 0, 256, 256, 0, 0, 0)
Repeat
Select WaitWindowEvent(10)
Case #PB_Event_CloseWindow
Break
Default
glClearColor(1, 0.5, 0, 0)
glClear(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
FlipBuffers()
EndSelect
ForEver
Re: How to initialise and use OpenGL (not OGRE) in MacOSX
Yup, I saw that, for basic usage seems to be a good shortcut!
Thanks.
Thanks.
"Have you tried turning it off and on again ?"
A little PureBasic review
A little PureBasic review
Re: How to initialise and use OpenGL (not OGRE) in MacOSX
Last edited by Niffo on Tue Apr 20, 2010 2:03 pm, edited 1 time in total.
Niffo
Re: How to initialise and use OpenGL (not OGRE) in MacOSX
It certainly appears that way, copy and pasting certain strings it can find.