PureBasic OpenGL Version?

Advanced game related topics
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: PureBasic OpenGL Version?

Post by J. Baker »

flaith wrote:Sorry to dig up this post, but I need to know if Purebasic still use OpenGL 1.2 because I tried with my old laptop (OpenGL 1.4) and the sprite system no longer works.
He could be useful to check the OpenGL version and to have a function for this or a warning from the compiler :)
I have an OpenGL 1.4 ATI card on a Windows ME pc and it seems to work.
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Re: PureBasic OpenGL Version?

Post by Rescator »

Gotta love thread necromancy (sometimes).

Here's an example on how to fetch the OpenGL version.

A few things to keep in mind though, only call Get_OpenGL_Version() after you have used OpenScreen() or OpenWindowedScreen() trying to call this before that (but after InitSprite() will not work.

And obviously this will only work if the subsytem is OpenGL.
The version.revision is returned, if no revision then only the version is returned (no dot) and if getting the version fails then a empty string is returned.

AFAIK this should work even with OpenGL 1.1 (maybe OpenGL 1.0), simply told it should work on Windows 2000 and later, this should also work on Linux/Mac.

Code: Select all

CompilerIf Subsystem("OpenGL")
	#GL_VERSION=$1F02
	Procedure.s Get_OpenGL_Version()
		Protected *ext,text$,ver$,version$,revision$
		*ext = glGetString_(#GL_VERSION)
		If *ext
			text$=PeekS(*ext,256,#PB_Ascii)
			ver$=StringField(text$,1," ")
			version$=StringField(ver$,1,".")
			revision$=StringField(ver$,2,".")
			If revision$ And version$
				text$=version$+"."+revision$
			ElseIf version$
				text$=version$
			Else
				text$=""
			EndIf
		EndIf
		ProcedureReturn text$
	EndProcedure
CompilerEndIf


If InitSprite() = 0
	MessageRequester("Error", "Can't open screen & sprite environment!", 0)
	End
EndIf


If OpenWindow(0, 0, 0, 220, 160, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	ButtonGadget(0, 170, 135, 45, 20, "Quit")
	
	If OpenWindowedScreen(WindowID(0), 0, 0, 160, 160)
		CreateSprite(0, 20, 20)
		If StartDrawing(SpriteOutput(0))
			Box(0, 0, 20, 20, RGB(255, 0, 155))
			Box(5, 5, 10, 10, RGB(155, 0, 255))
			StopDrawing()
		EndIf
	Else
		MessageRequester("Error", "Can't open windowed screen!", 0)
		End
	EndIf
EndIf

Debug "WTF"
Debug Program_Get_OpenGL_Version()
Debug "WTF"

direction = 2
Repeat
	; It's very important to process all the events remaining in the queue at each frame
	;
	Repeat
		Event = WindowEvent()
		
		Select Event 
			Case #PB_Event_Gadget
				If EventGadget() = 0
					End
				EndIf
				
			Case #PB_Event_CloseWindow
				End 
		EndSelect
	Until Event = 0
	
	FlipBuffers() 
	ClearScreen(RGB(0, 0, 0))
	DisplaySprite(0, x, x)
	x + direction
	If x > 140 : direction = -2 : EndIf
	If x < 0   : direction =  2 : EndIf
	Delay(1)
ForEver
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: PureBasic OpenGL Version?

Post by J. Baker »

On OS X, you'll have to import OpenGL. Anyway, returns OpenGL version 1.3 here on XP and 2.1 on Snow Leopard. Looks like this returns what your graphics card can currently handle and not PureBasic's OpenGL version. I would guess PureBasic is still using 1.2+ like Fred had said a while back?

Thanks Rescator! ;)

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
 ImportC "/System/Library/Frameworks/OpenGL.framework/OpenGL"
   glGetString_(Version.i) As "_glGetString"
 EndImport
CompilerEndIf

CompilerIf Subsystem("OpenGL") And #PB_Compiler_OS = #PB_OS_Windows Or #PB_Compiler_OS = #PB_OS_MacOS
   #GL_VERSION=$1F02
   Procedure.s Get_OpenGL_Version()
      Protected *ext,text$,ver$,version$,revision$
      *ext = glGetString_(#GL_VERSION)
      If *ext
         text$=PeekS(*ext,256,#PB_Ascii)
         ver$=StringField(text$,1," ")
         version$=StringField(ver$,1,".")
         revision$=StringField(ver$,2,".")
         If revision$ And version$
            text$=version$+"."+revision$
         ElseIf version$
            text$=version$
         Else
            text$=""
         EndIf
      EndIf
      ProcedureReturn text$
   EndProcedure
CompilerEndIf


If InitSprite() = 0
   MessageRequester("Error", "Can't open screen & sprite environment!", 0)
   End
EndIf


If OpenWindow(0, 0, 0, 220, 160, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   ButtonGadget(0, 170, 135, 45, 20, "Quit")
   
   If OpenWindowedScreen(WindowID(0), 0, 0, 160, 160)
      CreateSprite(0, 20, 20)
      If StartDrawing(SpriteOutput(0))
         Box(0, 0, 20, 20, RGB(255, 0, 155))
         Box(5, 5, 10, 10, RGB(155, 0, 255))
         StopDrawing()
      EndIf
   Else
      MessageRequester("Error", "Can't open windowed screen!", 0)
      End
   EndIf
EndIf

Debug "WTF"
Debug Get_OpenGL_Version()
Debug "WTF"

direction = 2
Repeat
   ; It's very important to process all the events remaining in the queue at each frame
   ;
   Repeat
      Event = WindowEvent()
      
      Select Event
         Case #PB_Event_Gadget
            If EventGadget() = 0
               End
            EndIf
            
         Case #PB_Event_CloseWindow
            End
      EndSelect
   Until Event = 0
   
   FlipBuffers()
   ClearScreen(RGB(0, 0, 0))
   DisplaySprite(0, x, x)
   x + direction
   If x > 140 : direction = -2 : EndIf
   If x < 0   : direction =  2 : EndIf
   Delay(1)
ForEver
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: PureBasic OpenGL Version?

Post by luis »

J. Baker wrote:... returns OpenGL version 1.3 here on XP and 2.1 on Snow Leopard. Looks like this returns what your graphics card can currently handle and not PureBasic's OpenGL version. I would guess PureBasic is still using 1.2+ like Fred had said a while back?
On the same hw ? I mean are you using the MacBook Air 2010 from your signature and you get 2.1 on OSX and 1.3 on XP ?
Because in this case you can probably just update your Windows drivers.
Again if it's the same card, what card is it exactly ? Just curious.

About what glGetString_(#GL_VERSION) tells you:

#GL_VERSION returns the OpenGL version associated to the rendering context created by PB.

It's not necessarily the highest OpenGL version supported by the driver/card combination.

PB afaik asks for a legacy OpenGL RC, so you can have three different outcomes.

1) The driver does support only a legacy version of OpenGL up to 2.1 (maybe 1.4, maybe 1.2, maybe 2.0 ..., whatever)
The OpenGL version associated to the RC will be a version not higher than 2.1.
This is the case for older drivers before the introduction of OpenGL 3.0+

2) The driver does support a core profile (OpenGL 3.0+) and ALSO a compatibility profile.
The OpenGL version associated to the RC will be a version > 2.1 up to the highest version for which a compatibility profile is available (starting from 3.2 where the compatibility profile was introduced, there is a hole before that).
So even if PB is asking for a legacy OpenGL RC, you end up with a version like 3.2 or 4.4 or whatever. And you can actually use some modern functions while still following the legacy OpenGL programming style. You can mix legacy with new.
This is what typically happens with modern drivers from the major vendors (nVidia, AMD, Intel) under Windows and very often under Linux.

3) The driver does support a core profile (OpenGL 3.0+) but NOT a compatibility profile.
The OpenGL version associated to the RC will be a version up to 2.1, should be 2.1 in fact.
This is what happens under OSX, where Apple decided to not support a compatibility profile and the highest OpenGL versions are available only when requesting a core profile.

And yes, the returned string with the OpenGL version does not tell you what PB requires/use, just what OpenGL version is available to it (and to you) after the RC creation.

So this does not answer flaith's question :|
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: PureBasic OpenGL Version?

Post by J. Baker »

luis wrote:
J. Baker wrote:... returns OpenGL version 1.3 here on XP and 2.1 on Snow Leopard. Looks like this returns what your graphics card can currently handle and not PureBasic's OpenGL version. I would guess PureBasic is still using 1.2+ like Fred had said a while back?
On the same hw ? I mean are you using the MacBook Air 2010 from your signature and you get 2.1 on OSX and 1.3 on XP ?
Because in this case you can probably just update your Windows drivers.
Again if it's the same card, what card is it exactly ? Just curious.
Oh no. I have XP on a different machine. It has an older ATI card, which I like for development. That way I know the game I'm working on will work with older computers. Plus it allows me to make sure the game is running optimized. So hopefully no complaints on performance issues when I'm done with it. As for the driver though, it's the latest available for XP due to its age. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
electrochrisso
Addict
Addict
Posts: 980
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: PureBasic OpenGL Version?

Post by electrochrisso »

Image
J. Baker, I see you are still running, do you ever get tired. :)
PureBasic! Purely one of the best 8)
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: PureBasic OpenGL Version?

Post by luis »

I hope he's running in the right direction ... :P
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: PureBasic OpenGL Version?

Post by J. Baker »

electrochrisso wrote:Image
J. Baker, I see you are still running, do you ever get tired. :)
Funny thing is, I have issues with sleep. Three to four hours of sleep is pretty common with me but I eventually crash. Sometimes it takes a week or two but I eventually get almost eight hours. ;)
luis wrote:I hope he's running in the right direction ... :P
Not all the time, lol. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
User avatar
electrochrisso
Addict
Addict
Posts: 980
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: PureBasic OpenGL Version?

Post by electrochrisso »

J. Baker wrote:Funny thing is, I have issues with sleep. Three to four hours of sleep is pretty common with me but I eventually crash. Sometimes it takes a week or two but I eventually get almost eight hours. ;)
Hey Fred! See what PureBasic can do to a person. :lol:
PureBasic! Purely one of the best 8)
User avatar
J. Baker
Addict
Addict
Posts: 2178
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Re: PureBasic OpenGL Version?

Post by J. Baker »

electrochrisso wrote:
J. Baker wrote:Funny thing is, I have issues with sleep. Three to four hours of sleep is pretty common with me but I eventually crash. Sometimes it takes a week or two but I eventually get almost eight hours. ;)
Hey Fred! See what PureBasic can do to a person. :lol:
LOL! You got that right. ;)
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.
Post Reply