OpenGL (without GLUT)

Linux specific forum
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

OpenGL (without GLUT)

Post by Foz »

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?

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
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: OpenGL (without GLUT)

Post by Foz »

Hmmm... how can I find out if what I'm importing is in fact correct?

Is there a tool what will scan .a or .so files and tell me what procedures are available for me to call?
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: OpenGL (without GLUT)

Post by Foz »

Well, thanks to the latest changes in to PB, it reported that there were problems when trying to use the (badly) imported procedures. I still get a black screen though.

Can anyone give me a hint on how to debug this? I check the glGetError() but nothing bad is being returned...

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
  ImportC "/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()
  
  glGetError()
EndImport

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  ImportC "/usr/lib/libX11.a"+Chr('"')+" -l"+Chr('"')+"GL"
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, 0.0, 0.0)
  glClearDepth(1.0)
  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.0,  1.0,  -10.0)
    glVertex3f( 1.0,  1.0,  -10.0)
    glVertex3f( 1.0, -1.0,  -10.0)
    glVertex3f(-1.0, -1.0,  -10.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))
      
    Case 0
      
      DrawScene()
      FlipBuffers()
  EndSelect
  
  glError = glGetError()
  Select glError
    Case 0
      ; no error, do nothing
    Default
      Debug glError
  EndSelect
ForEver
remi_meier
Enthusiast
Enthusiast
Posts: 468
Joined: Sat Dec 20, 2003 6:19 pm
Location: Switzerland

Re: OpenGL (without GLUT)

Post by remi_meier »

Well, as it seems FlipBuffers() kills the perspective :lol:

Just call ResizeScene(WindowWidth(0), WindowHeight(0))
before / after / around FlipBuffers() and it works.

btw: If you don't want to import every function yourself, I
and Vain already did the work. Just take a look at
http://remi.secretly.de/downloads/OpenG ... nux.tar.gz
You will also find GLUT imports and a sweet little 2D-OpenGL
Engine.


greetz
remi
Athlon64 3700+, 1024MB Ram, Radeon X1600
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: OpenGL (without GLUT)

Post by Foz »

Thank you! Thank you! Thank you! :mrgreen:

I already have your work (which is how I got started :)), but I find that I need to redo the imports because you use the parameters of (a.d, b.d, c.d, d.d) leave me wondering what I'm supposed to be assigning to them ;)

Back onto this though... how utterly insane! :D I find it bizarre that the Windows version works, but the Linux version requires a new perspective all over again.

Fred... is there some sort of additional gubbins with the Linux FlipBuffers() that doesn't exist with the Windows version? Do you think it could be fixed?
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: OpenGL (without GLUT)

Post by Foz »

Just wondering... with Windows, I don't need to include the OpenGL api, as they are already there, just with a _ appended to the procedure name.

How can I replicate that with my ImportC statement in Linux?
Niffo
Enthusiast
Enthusiast
Posts: 504
Joined: Tue Jan 31, 2006 9:43 am
Location: France

Re: OpenGL (without GLUT)

Post by Niffo »

Last edited by Niffo on Fri Apr 09, 2010 6:20 pm, edited 2 times in total.
Niffo
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: OpenGL (without GLUT)

Post by Foz »

Bing! Thanks!
Post Reply