BASIC

Author Topic: A little "HowTo" use OpenGL in GLBasic  (Read 20055 times)

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5020
  • O Rly?
    • View Profile
Hi my friends,

i will share with you guys my litte 3D test with OpenGL in GLbasic.
It's just a start on how to use a "Camera" to move like in Minecraft (Creativemode).
I update the gl.gbas a bit to make it possible to use RenderLists in GLB, the only thing i add was:

Code: GLBasic [Select]
INLINE
} extern "C" { GLuint __stdcall glGenLists( GLuint range );; }; namespace __GLBASIC__{
ENDINLINE
FUNCTION glGenLists: range
        INLINE
                return OGL glGenLists(range);
        ENDINLINE
ENDFUNCTION
 

RenderLists speed up the rendering by ->>>  :o  ... :D
It give you a good start on how to use OpenGL and on how to create objects!

Maybe it gives you a start for youre next game ( hope so ), let me know it!

if you have any questions, ask me.


Maybe i code some more features into it like a  OBJ loader, that was my next point on the list :D


EDIT: Fix the upload, now its working sry! 
« Last Edit: 2014-Aug-13 by Schranz0r »
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4212
    • View Profile
    • Portfolio
Re: A little "HowTo" use OpenGL in GLBasic
« Reply #1 on: 2014-Aug-13 »
Nice Schranzor, I will give a try. :good:

edit: strange, I get this:
Quote
_______________________________________
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.9.988 SN:37233beb - 3D, NET
..\Samples\Common\gl.gbas (failed to open)
"Axes.gbas"(24) warning : GPC1001 probably unassigned variable : GL_COMPILE
"Axes.gbas"(25) warning : GPC1001 probably unassigned variable : GL_LINES
"Object.gbas"(47) warning : GPC1001 probably unassigned variable : GL_QUADS
"OpenGLUtils.gbas"(10) warning : GPC1001 probably unassigned variable : GL_TEXTURE_2D
"OpenGLUtils.gbas"(10) warning : GPC1001 probably unassigned variable : GL_TEXTURE_MIN_FILTER
"OpenGLUtils.gbas"(10) warning : GPC1001 probably unassigned variable : GL_NEAREST
"OpenGLUtils.gbas"(11) warning : GPC1001 probably unassigned variable : GL_TEXTURE_MAG_FILTER
"SimpleOpenGLGame.gbas"(106) error : GPC0009 call to undefined function : glRotatef
« Last Edit: 2014-Aug-13 by erico »

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5020
  • O Rly?
    • View Profile
Re: A little "HowTo" use OpenGL in GLBasic
« Reply #2 on: 2014-Aug-13 »
i fix the upload!
« Last Edit: 2014-Aug-13 by Schranz0r »
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
Re: A little "HowTo" use OpenGL in GLBasic
« Reply #3 on: 2014-Aug-14 »
Lots of questions:

Sorry about my ignorance, what are renderlists?

I dont see how this create a speed increase, what is needed to do this?
I will try to apply this to APE,  my 3d particle system.

I like the idea of an OBJ loader, perhaps you can fix the glbasic object converter instead?

And since youre tinkering....one real big problem with GLBasic 3d is the z ordering.....i have not yet found a solution, no matter how objects are ordered onto the screen according to z depth(even physically coded), there are still  weird artifacts like transparencies and blobs of incorrect lighting/color etc.


Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3366
  • Integrated Brain
    • View Profile
Re: A little "HowTo" use OpenGL in GLBasic
« Reply #4 on: 2014-Aug-14 »
Schranz0r thanks , I don't test because I'm in Linux, but from OpenGL 3.0 you don't need download any .h inst?¿, I read Nvidia make something you don't need to say to the compiler nothing.

Ok the render list, what it's, ?¿ I'm equal like Hemlos I don't know what are this.

For place a obj import really this have to be very very easy, I real a lot of documentation on the web about .obj, and seems the best friendly and easy format for play with it.

For anyone are interested in OpenGl and 3D , you have in English this huge and awesome web, I think it's a very important guy into OpenGL...
http://nehe.gamedev.net/

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4212
    • View Profile
    • Portfolio
Re: A little "HowTo" use OpenGL in GLBasic
« Reply #5 on: 2014-Aug-14 »
Works fine now. :good:
I will save it to examine further.

The camera rotations go smooth here but the movement kind of jitters here and there, why so?

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5020
  • O Rly?
    • View Profile
Re: A little "HowTo" use OpenGL in GLBasic
« Reply #6 on: 2014-Aug-14 »
Hey no stuttering here....

renderlist:


only draw/create the object one time, then send it to the graphicscard.
the only thing you need in the mainloop is to call the list on the card!

Larger objects will be rendering much faster then immediate mode!
If you need to change the object, recreate the list one time not every frame like immediate mode.
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
Re: A little "HowTo" use OpenGL in GLBasic
« Reply #7 on: 2014-Aug-14 »
 :giveup:

Im looking through all the code, i dont see anything remotely close to what you mentioned:
renderlists
immediate mode
creative mode

Where is the tutorial?  :S
« Last Edit: 2014-Aug-14 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: A little "HowTo" use OpenGL in GLBasic
« Reply #8 on: 2014-Aug-14 »
Displaylists are depreciated and not supported in OpenGL 3.1+ core profile (ok, doesnt matter for us) and OpenGL ES. So you can not run this on mobile devices. Also GL_QUADS does not exist in OpenGL ES too (replace with GL_TRIANGLE_STRIP).

I recommend to not use gl.gbas, instead write all your rendering stuff in INLINE C++ and OpenGL. So you avoid the wrapper overhead, and get some tiny speed improvement. See my libSPRITE how to do it. Also multmatrix is faster then doing multiple rotate/translate stuff again and again, which is why I do this in my (not yet officially published) Entity System.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4212
    • View Profile
    • Portfolio
Re: A little "HowTo" use OpenGL in GLBasic
« Reply #9 on: 2014-Aug-14 »
Hey no stuttering here....

None here for rotations.
Translations give some, significants ones.

I´m not good enough to figure out why. :(


Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: A little "HowTo" use OpenGL in GLBasic
« Reply #10 on: 2014-Aug-14 »
Sounds like the same shuttering you can get in GLBasic too, its caused by float inaccuracy and setting up the camera. If the engine creator is careful it can be avoided.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1543
    • View Profile
Re: A little "HowTo" use OpenGL in GLBasic
« Reply #11 on: 2014-Aug-14 »
Looks good and perhaps I will give it a try.

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5020
  • O Rly?
    • View Profile
Re: A little "HowTo" use OpenGL in GLBasic
« Reply #12 on: 2014-Aug-14 »
I don't care about mobile and whats not supportet in newer version...

It's just a way to start.
It's the easy way and not the perfect one. If you new to GL you can't go from zero to hero in a day...

Whats the "new" way to render? VAO or VBO?
« Last Edit: 2014-Aug-14 by Schranz0r »
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
Re: A little "HowTo" use OpenGL in GLBasic
« Reply #13 on: 2014-Aug-14 »
I just wanted to state this, so users can decide if this meets their needs.

VAo and VBO both are possible AFAIK.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
Re: A little "HowTo" use OpenGL in GLBasic
« Reply #14 on: 2014-Aug-14 »
Thanks for this, it will come in very handy in the near (hopefully) future. I'm about to start learning C++ as I want to learn more about OpenGL although more in a 2D context rather than 3D. As practically every OpenGL tutorial is C/C++ based a basic grounding in C/C++ will not do me any harm & will be useful for other things (there is so much useful code out there also).

Luckily skimming through the tutorials there is nothing really heavy looking C/C++ wise although GLEW & GLUT get mentioned quite often which currently mean nothing to me as of yet so will cross that bridge when I get to it.

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)