OpenGL (without GLUT)
Posted: Mon Mar 29, 2010 10:47 pm
okay, so after Fred's revelation that using the subsystem of OpenGL to open a screen is a method of getting OpenGL started, I had a go, and lo and behold, I was able to set the background colour. Yes!
So, the next step was to move onto drawing a polygon. Obviously. And here is where I am getting stuck, it just doesn't work. Well, that isn't entirely correct, I get a black screen. The irritating bit is that this example works in Windows, so I can only assume that my Imports are wrong, or it's something else that I've overlooked.
Any ideas guys?
So, the next step was to move onto drawing a polygon. Obviously. And here is where I am getting stuck, it just doesn't work. Well, that isn't entirely correct, I get a black screen. The irritating bit is that this example works in Windows, so I can only assume that my Imports are wrong, or it's something else that I've overlooked.
Any ideas guys?
Code: Select all
CompilerIf Subsystem("OpenGL")
CompilerElse
Debug "Set the subsystem to OpenGL"
End
CompilerEndIf
#GL_SMOOTH = $1D01
#GL_DEPTH_TEST = $0B71
#GL_LEQUAL = $0203
#GL_PERSPECTIVE_CORRECTION_HINT = $0C50
#GL_NICEST = $1102
#GL_MODELVIEW = $1700
#GL_PROJECTION = $1701
#GL_COLOR_BUFFER_BIT = $00004000
#GL_DEPTH_BUFFER_BIT = $00000100
#GL_QUADS = $0007
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
Import "/usr/lib/libX11.a"+Chr('"')+" -l"+Chr('"')+"GL"
CompilerElse
Import "Opengl32.lib"
CompilerEndIf
glShadeModel(mode.l)
glClearColor(red.f, green.f, blue.f, alpha.f)
glClearDepth(depth.d)
glEnable(capability.l)
glDepthFunc(function.l)
glHint(target.l, mode.l)
glViewport(x.l, y.l, width.l, height.l)
glMatrixMode(mode.l)
glLoadIdentity()
glClear(masks.l)
glTranslatef(x.f, y.f, z.f)
glBegin(mode.l)
glVertex3f(x.f, y.f, z.f)
glEnd()
EndImport
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
Import "/usr/lib/libGLU.a"
CompilerElse
Import "Glu32.lib"
CompilerEndIf
gluPerspective(fovY.d, aspect.d, zNear.d, zFar.d)
EndImport
Procedure InitGL()
glShadeModel(#GL_SMOOTH)
glClearColor(0, 0, 0, 0)
glClearDepth(1)
glEnable(#GL_DEPTH_TEST)
glDepthFunc(#GL_LEQUAL)
glHint(#GL_PERSPECTIVE_CORRECTION_HINT, #GL_NICEST)
EndProcedure
Procedure ResizeScene(width, height)
If height < 1 : height = 1 : EndIf
If width < 1 : width = 1 : EndIf
glViewport(0, 0, width, height)
glMatrixMode(#GL_PROJECTION)
glLoadIdentity()
gluPerspective(45, width / height, 0.1, 1000)
glMatrixMode(#GL_MODELVIEW)
glLoadIdentity()
EndProcedure
Procedure DrawScene()
Static zoom.f = -2.0
glClear(#GL_COLOR_BUFFER_BIT | #GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(0, 0.0, zoom)
glBegin(#GL_QUADS)
glVertex3f(-1, 1, 0)
glVertex3f( 1, 1, 0)
glVertex3f( 1, -1, 0)
glVertex3f(-1, -1, 0)
glEnd()
zoom - 0.1
EndProcedure
InitSprite()
OpenWindow (0, 100, 100, 512, 512, "OpenGL Window")
OpenWindowedScreen(WindowID(0), 0, 0, 512, 512, 0, 0, 0)
ResizeScene(512, 512)
InitGL()
Repeat
Select WaitWindowEvent(1)
Case #PB_Event_CloseWindow
Break
Case #PB_Event_SizeWindow
;ResizeScene(WindowWidth(0), WindowHeight(0))
EndSelect
DrawScene()
FlipBuffers()
ForEver