wilbert wrote:Cocoa uses NSGL, Carbon uses AGL. Maybe that's the reason ? (just guessing, I have no knowledge of OpenGL)
I think you may be right. Unfortunately I have no knowledge of neither how to integrate cocoa funktions into PureBasic nor am I an expert in OpenGL. The linked example was my first try...
But the following example utilizes a WindowedScreen and - like Fred stated - it only needs a WindowedScreen and gl commands to render OpenGL graphics. My linked example seems to have made things more complicate than needed...
It runs on Macs with PB 4.61, PB 4.70 Beta 1.5 x86 and x64 and with PB 4.70 Beta 1.5 x86 with subsystem carbon:
Code: Select all
#GL_COLOR_BUFFER_BIT = $00004000
#GL_DEPTH_BUFFER_BIT = $00000100
#GL_MODELVIEW = $1700
#GL_PROJECTION = $1701
#GL_TRIANGLES = 4
EnableExplicit
ImportC "/System/Library/Frameworks/OpenGL.framework/OpenGL"
glBegin_(PrimitiveID.I) As "_glBegin"
glClear_(BuffersToClear.I) As "_glClear"
glColor3f_(Red.F, Green.F, Blue.F) As "_glColor3f"
glEnd_() As "_glEnd"
glLoadIdentity_() As "_glLoadIdentity"
glMatrixMode_(Target.I) As "_glMatrixMode"
glTranslatef_(x.F, y.F, z.F) As "_glTranslatef"
gluPerspective_(FieldOfViewAngle.D, WidthToHeightRatio.D, DistanceToNearPlane.D, DistanceToFarPlane.D) As "_gluPerspective"
glVertex3f_(x.F, y.F, z.F) As "_glVertex3f"
glViewport_(x.I, y.I, Width.I, Height.I) As "_glViewport"
EndImport
If InitSprite() = 0
MessageRequester("Error", "Can't open screen & sprite environment!")
End
EndIf
OpenWindow(0, 270, 100, 640, 480, "MacOS X Cocoa & Carbon OpenGL demo", #PB_Window_SystemMenu)
SetWindowColor(0, 0)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)
Repeat
glViewport_(0, 0, WindowWidth(0), WindowHeight(0))
glMatrixMode_(#GL_PROJECTION)
glLoadIdentity_()
gluPerspective_(30.0, Abs(WindowWidth(0) / WindowHeight(0)), 0.1, 500.0)
glMatrixMode_(#GL_MODELVIEW)
glLoadIdentity_()
glClear_(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glLoadIdentity_()
glTranslatef_(0.0, 0.0, -8.0)
glColor3f_(1.0, 1.0, 1.0)
glBegin_(#GL_TRIANGLES) ; Start drawing a triangle
glColor3f_ ( 1.0, 0.0, 0.0) ; Set top point of triangle to Red
glVertex3f_( 0.0, 1.0, 0.0) ; First point of the triangle
glColor3f_ ( 0.0, 1.0, 0.0) ; Set left point of triangle to Green
glVertex3f_(-1.0, -1.0, 0.0) ; Second point of the triangle
glColor3f_ ( 0.0, 0.0, 1.0) ; Set right point of triangle to Blue
glVertex3f_( 1.0, -1.0, 0.0) ; Third point of the triangle
glEnd_() ; Done drawing the triangle
FlipBuffers()
Until WaitWindowEvent() = #PB_Event_CloseWindow