GLBasic forum

Main forum => Tutorials => Topic started by: Schranz0r on 2014-Aug-13

Title: A little "HowTo" use OpenGL in GLBasic
Post by: Schranz0r on 2014-Aug-13
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! 
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: erico 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
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: Schranz0r on 2014-Aug-13
i fix the upload!
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: Hemlos 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.


Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: mentalthink 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/
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: erico 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?
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: Schranz0r 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.
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: Hemlos 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
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: kanonet 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 (http://www.glbasic.com/forum/index.php?topic=7992.0) 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 (http://www.kanonet.de/downloads/libesl).
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: erico 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. :(

Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: kanonet 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.
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: matchy on 2014-Aug-14
Looks good and perhaps I will give it a try.
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: Schranz0r 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?
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: kanonet 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.
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: fuzzy70 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
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: Schranz0r on 2014-Aug-14
I can try to make a tutorial to get more in detail.
But maybe in german, my english is a bit awkward  :S
So i need a native speaker to translate...
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: Hemlos on 2014-Aug-15
You are very fluent, i can understand you 99.99% of the time...which is alot better than some of the natives around here in Florida.
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: matchy on 2014-Aug-15
Alright now.  ;) I have created a demo using the sprite output from SBlectric's terrain generator and I had to modify the face library to include vertex coloring.  :zzz:
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: erico on 2014-Aug-15
I will try to poke my nose where it dosen´t belong... :D
I have no idea how this is all happening, but say Matchy, can´t you UVmap the polygons instead?

edit: what? hard to understand Schranzor? Come on! just call Mentalthink and he will fix it up :)  (just joking of course Mental!)
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: matchy on 2014-Aug-15
Matchy says!  :D :D

The wrapper is fine and really is simple. It's the face library that needs improvements. For example, the association with type as arrays and converting them to.
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: Schranz0r on 2014-Aug-18
Should i redo it to Vertex buffer object ( VBO )  ???
Ah... and the Rendering to Triangles/ Trianglestrips?
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: matchy on 2014-Aug-18
In the face library, you have random rgb color for testing but how are they set externally?  :S That was my only major issue because I have to include a color[4] array for that type.  ::)
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: Schranz0r on 2014-Aug-18
remove the random once and extend the facetype to apply a color
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: matchy on 2014-Aug-18
Have you even looked at my source with that modified?  :'(
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: Schranz0r on 2014-Aug-18
no ^^


REMOVE THIS:

Code: (glbasic) [Select]

LOCAL r# = RND(100)
LOCAL g# = RND(100)
LOCAL b# = RND(100)

glColor3f(r/100,g/100,b/100)

in FUNCTION createObject_test

but you don't use it  :S
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: matchy on 2014-Aug-18
Why not?  :whistle:
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: Schranz0r on 2014-Aug-18
look at the other post
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: matchy on 2014-Aug-18
Now you are confusing just me.  :'( Did you, or anyone else, try out the terrain tiler?  :zzz:
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: Schranz0r on 2014-Aug-18
ok i think i don't understand you right....

You have still random colors?
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: mentalthink on 2014-Aug-18
Schranz0r don't worry about your English I understand always 100% you say, in fact I only imagine you're German for the nick in the Avatar.
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: kanonet on 2014-Aug-18
Should i redo it to Vertex buffer object ( VBO )  ???
Ah... and the Rendering to Triangles/ Trianglestrips?
Would be interesting. And yes to triangles/trianglestips.

BTW how would you do animations?
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: matchy on 2014-Aug-19
I have already taken out the random colors.

For the last time, can I get feedback from anyone regarding my demo because that is all I ask:
Here is the link again, in case you have dyslexia:
http://www.glbasic.com/forum/index.php?action=dlattach;topic=9962.0;attach=6817
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: fuzzy70 on 2014-Aug-19
Your demo seems to work fine Matchy. Things look a bit odd if you go below the cubes as looks like faces are fighting each other to be viewed.

Other than that what feedback are you looking for?

Lee
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: matchy on 2014-Aug-19
Thanks fuzzy70 and you'll see the face color modifications. I think that I am not putting in the bottom face of the cubes and it's really just supposed to be land. Also, it crashes above 128x128 but I am able to get more than twice otherwise with my code.
With my "3d engine" I was able to turn off zbuffer and display only the side of the cube (wall) that is required. I did this so that is would work on Android.
So what would be interesting to have an algorithm to do just that. I mean, when creating a cube, where is the back?


Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: fuzzy70 on 2014-Aug-19
I'll have a look, am pretty sure I saw an algorithm somewhere that culls cube faces as if your close up you only see one side & if far away the maximum you will ever see are 3 sides.

Also personally any of the cubes that's blue I would make them share the same colour so there the same level like water should be as there not small enough to simulate waves or such but that's not the point of the demo.

Lee
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: matchy on 2014-Aug-19
 :good:

I don't know how it could without recreating the object. In terms on block tiling, one simple way to do it is to just create a 3-sided cube then just rotate it to face the player.

Alternatively, what I wanted to original to with the demo was to have it as one object (top face) with it's slant to the next tile height, so it looks like proper terrain. :whistle:
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: fuzzy70 on 2014-Aug-19
Alternatively, what I wanted to original to with the demo was to have it as one object (top face) with it's slant to the next tile height, so it looks like proper terrain. :whistle:
That's just a simple plane generated from an array, pretty sure on one of the noise posts (cant remember if perlin or simplex noise) I posted a program that scrolls the noise isometric style drawn with polyvectors. That wasn't drawn from arrays but rather calculating the noise per frame so major performance hit.

Not sure if this would help but glEnable(GL_CULL_FACE) might give a boost over scanning what faces are visible or not as unlike a minecraft style display where there are cubes possibly above & below these ones are just adjacent to each other.

Lee
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: matchy on 2014-Aug-19
I almost had terrain just commented/left out the code in the demo because it was getting late that evening.

Next test should be for Android, because that is the original reason for the idea of efficient object drawing, otherwise its shouldn't really be a concern aside from speed.
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: fuzzy70 on 2014-Aug-19
Other than the quick & dirty iso one I posted using polyvectors (which was only done to show another way of viewing the noise plus added FMB to roughen it up a bit) by last exploration of landscape generation was on the Amiga in Assembly language & lookup tables lol. Basically a long while ago  :D

Lee
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: Schranz0r on 2014-Aug-19
BTW how would you do animations?

I don't think about it...  :zzz:
should i?
Title: Re: A little "HowTo" use OpenGL in GLBasic
Post by: kanonet on 2014-Aug-19
How should I know, its your project?
IMHO if you dont use shaders, you need to build the animated object at runtime, each frame. So you could not use your display lists etc. Pr do you know a way that I dont see?
(If you use shaders you can render static objects and just animate them in shader - but I have done this myself already, so Im less interested in this)