How to use OpenGL 3.0+ with your projects.

Previous topic - Next topic

bigsofty

Why? GLBasic uses the default OpenGL 1.1 headers for it's OpenGL. These are functional but lack a lot of features. Advanced blending modes, shaders with decent features etc. need GL 3.0+
To add OpenGL functionality to your project I use GLee (GL Easy Extension library), see here... https://www.opengl.org/sdk/libs/GLee/


To use it within your projects all the hard work is done within the project options dialog. I used the GCC command line option to pre-empt the GLBasic linking process.

Before that though, I need a folder, within my games ("PMS") project folder to hold the GLee.h and GLee.c library files. See attached archive.



STEP 1: Create a container folder and copy the GLee files into it

For my PMS game, its in "MyC", within the PMS game project folder...

Code (glbasic) Select
"C:\Coding Folder\Projects\GLBasic\PMS\MyC"

Obviously change the "C:\Coding Folder\Projects\GLBasic\PMS\" bit to match your own projects path.

Once that has been created. Extract the files mentioned above into the "MyC" folder.



STEP 2: Include the header and link it's library file in the project options

Open your project options dialog ( In the GLB IDE Menu - "Project" then "Options" )

An on your "cmp" (Compiler command line options) and "lnk" (Linker command line options) add these two lines (keep the quotes BTW)

In "cmp" ...
   
Code (glbasic) Select
-I"C:\Coding Folder\Projects\GLBasic\PMS\MyC" -include GLee.h

In "lnk" ...
   
Code (glbasic) Select
"C:\Coding Folder\Projects\GLBasic\PMS\MyC\GLee.c"

Save and exit.


Thats it!


Here's a very quick test for OpenGL 3.0 support ...


Code (glbasic) Select
INLINE
if (GLEE_VERSION_3_0)
{
  //OpenGL 3.0 is supported (Minimum)
  DEBUG( (DGStr)" OpenGL 3.0+ supported " );
}
glClampColor(GL_CLAMP_READ_COLOR, GL_FALSE); // Quick usless OpenGL 3.0 only command
// to show that its working. Remove in final game!
// There should be NO compile errors if GLBasic accepts
// it as a valid inline command.
ENDINLINE


Check for errors. The above should be at the beginning of any program that uses this lib as it's a good check for older unsupported cards too.

A couple of tips.

Changing the linked library("lnk") "C:\Coding Folder\Projects\GLBasic\PMS\MyC\GLee.c" to ""C:\Coding Folder\Projects\GLBasic\PMS\MyC\GLee.a" allows for static linking of GLee and therefore much quicker compiles. But you will need to recompile (GLee.c & GLee.h into GLee.a) for any other platform other than Windows to staticly link it for another platform. There is a Windows "GLee.a" in the "GLee_MinGW.zip" within the main archive. This is what I actually use.

Once the library is installed, you now have full OpenGL inline support using DGInt, DGNat, DGStr etc. This is VERY handy once you get comfortable with mixing inline GL code with normal GLBasic. It's also very easy to wrap the new GL commands.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Ian Price

Sounds great. Is there any reason why it can't be incorporated directly into GLBasic so that the user has no extra faffing?
I came. I saw. I played.

bigsofty

Thanks Ian. There's no reason why this couldn't be incorporated into the compile chain AFAIK. The only thing to remember that anyone using this needs to link into this library BEFORE "gl.h". You can keep "gl.h" if you like but it serves no purpose after this library as GLee already incorporates the base "gl.h" definition in it's own header definition as well as the extra OpenGL 1-3+ extensions.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

MrPlow

Nice! Thanks BigSofty!

Any idea how faster or smoother the end result is after switching from 1.x to 3.0?

:)
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

bigsofty

Thanks Mr Plow. TBH I would imagine that to really take advantage of the new extensions, you would need to use them in code. Be that in the GLBasic compiler source or within your own inline code. There is a list of extensions within the GLee ZIP file. There are a vast amount of them, most will be ways to do things that either were not possible or are a simply much faster way of doing OpenGL 1.1 things. A small example would be, there is support for mesh instancing in OpenGL 2.0, that is to cache your mesh in graphics memory, rather than transfer it to graphics memory each time you draw a mesh. This can allow you to have thousands rather than hundreds of meshes on screen at ounce without any loss of speed.

You still need to dip into inline C a bit to take advantage though as this isn't a new engine, it just allows access to a better OpenGL API within your inline C.
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

dreamerman

Tried to check difference in speed for PolyVector, and didn't see improvement for that, as BigSofty mentioned without using proper OGL 2.0/3.0 code you will not see major differences. I did test that on some old template for checking collision/effect speed and I must say that's nice to remind yourself how fast GLBasic is in simple 2d drawing with PolyVector, specially compared to some other 'native' & 'optimized' tools :DD
Very nice, and I was curious how did You managed to achieve those fancy effects in your 'PMS' project, well done! ;-)
Check my source code editor for GLBasic - link Update: 20.04.2020

bigsofty

Thanks Dreamerman. Yup, GLBasic is very fast, I actually develop in an old pentium dual core(I was getting increasingly worried about optimisation on my big rig with a GTX1080 in it) Lenovo M73 Tiny desktop, it has 4 gigs with intel on board GPU. My game runs at a steady 60hz on it with space to spare. This is definitely down to how well GLBasic has been optimised, even on a single thread GLBasic is blisteringly fast!
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

mentalthink

WOW !!! I think this need GLBasic , very good 3D... I think we can do very impressive 3D games for PC. Thanks a lot for this work...

bigsofty

Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)