INLINE
bool LoadFile(char *filename)
{
return true;
}
ENDINLINE
ENDFUNCTION
How do I call the above inline C subroutine from GLBasic with the correct parameter and types...?
Also...
Where do I put my...
#include // Header File For Standard Input / Output
If you want to include some file, be warned, that you must provide it. I don't provide any std files with GLBasic SDK.
The easiest way is to put all inline stuff in a seperate file. That way you are sure, that at the top of this file you're not in the main function anymore.
INLINE
} // close current namespace
include
namespace __GLBASIC__ { // restore namespace
ENDINLINE
For calling a function I suggest this:
FUNCTION LoadFile: file$
INLINE
bool good=true;
FILE* pF = fopen(file_Str . c_str(), "rb");
fputs(pF, ....
return good;
ENDINLINE
Aha, so thats how its done! :)
Thanks Gernot, Im learning C as need be for GLBasic... do I need the standard .h file that is supplied with GCC or will anyone do? If so, does it need to specific to the compiler version?
Many thanks,
I think any std file will do. Getting a copy from a GCC compiler is a good choice, though.
:( I cant get this to work, no matter what headers I try, I've tried djgpp,mingw (gcc), PelleC, etc... stdio.h but they all throw up errors on compilation... each header has different errors.
I placed them in ..."\Program Files\GLBasic\Compiler\platform\Include"...
Removed some bits and edited the headers... down to a few errors... Ill continue to try and fix them tomorrow...
Best is to copy/paste the function declarations you need only.
My biggest problem is that GLBasic seems to do an automatic type conversion mystring_Str and DGInt for example, which makes them incompatible with these system calls?
mystring_Str.c_str()
gives a const char*
mystring_Str.GetStr(minimum_length);
...
mystring_Str.CalcLen();
gives a char* (not very wise, though)
DGInt is simply a double, so you can cast to e.g. int
DGInt mynumber=1.23;
int n = (int) mynumber;
P.S. I've been getting this error quite a bit over the last couple of days, when posting Gernot...
"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, service@webmailer.de and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log."
Small question... where to you store your textures Gernot(array of GLuint), I would like to load my own textures and use the OpenGL texture ID from within GLBasic?
try get_sprite_texture() command. See an example here:
http://www.glbasic.com/forum/viewtopic.php?pid=4031#p4031
Ah, thank you, I forgotten about that example! :D
EDIT: Ah, its actually new one... doh! ...thanks again bud ;)
Quote from: bigsoftyRemoved some bits and edited the headers... down to a few errors... Ill continue to try and fix them tomorrow...
Not happy with my current headers... they work but I'm not happy with there compatibility (lots of edits t get working)... does anyone have a zip file handy with all the headers for C99? What worries me is that the headers may not be cross platform compatible, since some headers I've looked at seem to have different Defines for different O.S. and my will be on at least 3 platforms...
Also...
Im using standard OpenGL types... GLuint, GLbyte, etc... via typedefs inline, is this OK, I noticed you dont use them Gernot (maybe because you know them off by heart ;))?
OK, time to stop and take stock...
First why go to the bother, I could easily just compile a DLL BUT as said I wanted my program to work across various platforms... a DLL does not work in linux for example, so, inline, with the game... seemed the best idea...
The headers I need, are..., and
Ive ran into a few problems (or potential problems)...
1) Standard C99 headers seem to be quite incompatible... I tried many.
2) Some of these headers are for win32 only, so compilation on one platform does not guarantee it will run on another.
Interfacing with GLBasic variables via type casting was working fine.
Gernot, any advice how to proceed?
you can make linux dll's (they are called .so (shared object) as well. But that might give you headache as well.
You can get the headers for each compiler and put it in the correct directory. I'll attach the headers that came with the GCC version here. Wait.
Quote from: GernotFrischYou can get the headers for each compiler and put it in the correct directory. I'll attach the headers that came with the GCC version here. Wait.
That's a very good idea... :)
May I suggest you consider packaging these with GLBasic as there kinda essential for anyone doing in-line C above DLL header integration...
http://www.glbasic.com/files/headers.rar copy these in the platform directory. It should get you going.
Thanks for the help Gernot, downloading now...
Great so far... works like a dream, thanks again Gernot... and as bonus all I need now to play with OpenGL is "#include ", no more cut and paste! :D
This should be definite option for anyone using the inline C ;)
Are these header files still OK to use?
Mac OSX has been added since then and there are no header files in the 'platform' to support it?
Also, do these files need to be updated with each version of GLBasic?
These headers are win32 only, IIRC. Do you need mac headers?
Quote from: GernotFrischThese headers are win32 only, IIRC. Do you need mac headers?
Well, my game expands a little on the GL support and uses some other inline C, so I suppose yes, if I want to eventually port it to Mac and other platforms. To be honest I was going to do the win32 version first and then convert to other platforms.
It would be nice if this was part of the official distribution and supported, it really does add a lot to the extendibility of GLBasic. I think its one of those relatively 'hidden' features that no other of the gamebasics offer that is incredibly powerful once harnessed.
As a request, as part of the cross-compile process could a remark be put on the end of the generated 'c' source line, saying what GLBasic line is being processed...
So for example...
This error...
C:/DOCUME~1/Dad/LOCALS~1/Temp/glbasic/gpc_temp4.cpp:50: error: `GLuints' does not name a type
Would become this error...
C:/DOCUME~1/Dad/LOCALS~1/Temp/glbasic/gpc_temp4.cpp:50: error: `GLuints' does not name a type
// From: OpenGL.BAS, Line: 22This would allow in-line programmers to locate the correct line in the Glbasic source where error was produced,
Just a suggestion.
OK. We've already started on an OpenGL wrapper. If only I could find it....
An "OpenGL wrapper"? That sounds interesting?
Quote from: GernotFrischOK. We've already started on an OpenGL wrapper. If only I could find it....
OpenGL Wrapper for GLBasic? Any info? If its a lib that can allow me to insert OpenGL commands directly into my GLBasic source, without having to resort to in-line C, then that would be REALLY helpful! :D
Yes, yes. Oh dear. I'm so short on time these days.
I'll really really have a look now.
Any luck Gernot? ;)
My laptop's screen is dead. I'll have to see if I can find time after fixing it this week. So, so sorry.
Ah bummer, no problem Gernot, I hope its not a bad problem...
http://www.glbasic.com/files/gl.gbas
BINGO! The complete OpenGL Command set inline in GLBasic!!! Muhahaha!
Yay! Great stuff, your some guy Gernot! :D
There goes my weekend..! time to play... ;)
init_GL()
WHILE TRUE
X_MAKE3D 1,1000,45 // Viewport 3D
glClear(GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
glTranslatef(-1.5,0.0,-6.0); // Move Left 1.5 Units And Into The Screen 6.0
glBegin(GL_TRIANGLES); // Drawing Using Triangles
glColor3f(1.0,0.0,0.0); // Set The Color To Red
glVertex3f( 0.0, 1.0, 0.0); // Top
glColor3f(0.0,1.0,0.0); // Set The Color To Green
glVertex3f(-1.0,-1.0, 0.0); // Bottom Left
glColor3f(0.0,0.0,1.0); // Set The Color To Blue
glVertex3f( 1.0,-1.0, 0.0); // Bottom Right
glEnd(); // Finished Drawing The Triangle
glTranslatef(3.0,0.0,0.0); // Move Right 3 Units
glColor3f(0.5,0.5,1.0); // Set The Color To Blue One Time Only
glBegin(GL_QUADS); // Draw A Quad
glVertex3f(-1.0, 1.0, 0.0); // Top Left
glVertex3f( 1.0, 1.0, 0.0); // Top Right
glVertex3f( 1.0,-1.0, 0.0); // Bottom Right
glVertex3f(-1.0,-1.0, 0.0); // Bottom Left
glEnd(); // Done Drawing The Quad
SHOWSCREEN
WEND
:D
I had to put all the GL Globals in a FUNCTION...
FUNCTION init_GL:
GLOBAL GL_VERSION_1_1 = 1
GLOBAL GL_VERSION_1_2 = 1
GLOBAL GL_VERSION_1_3 ...
...
ENDFUNCTION
...which allowed me to load in the GLB GL code as a seperate library.
Now if this was built into the command set... I wouldn't have the overhead of a function call and return for each GL command... hint, hint ;)
This is so potentially powerful that the extension of the graphics engine could be handled by the community! New 3d formats, landscape support etc...!
If it's built-in, there would be the overhead as well for wrapping the data types.
You should not need a initGL function. GLBasic should assign the values to the globals.
uhm... oh dear. It might not.
Could be a "missing feature".
Ah, I see... I could allays pre-process it externally and in-line every GLCommand I suppose... sounds terrible but I'm sure I could automate it. Now if we had pre-process Macro support... :P hehe
Yep, if its loading in as a seperate file it complains the globals are outside a function, its no bother though to wrap them in a function and call it once...
...BUT thanks again Gernot, this is great and lots of fun for anyone trying to learn OpenGL in basic and it works! :D
Fixed the GLOBAL bug, update might take some time, though. Have to test a lot before.
Ah, cool, this will make libs that little bit easier to be portable! ;)
Although, I kinda like to have an initialisation section for globals... feels more structured? Maybe just me...
On a related note, is it possible for you to release the little bit of C++ code that initialises the rendering context for 3D and 2D as its kinda guesswork on my part to how the various OpenGL options have been configured and my code should follow... I can see why you may not want to do this Gernot though, so its not important if you don't want to. ;)
Talking about inline, seems to be that the demo version of this program, still doesn't accepts it, It would be good to have it... although, I'm not complaining but simply asking for it, Please forgive me, if I said something that isn't proper ...
It was a bug. I changed it in the new version.
ok thanks, maybe i should download it, since I want to start using Newton Sdk... to create gravity.. (anyway I still need to find a way to make this possible by using basic language only.)
gravity?
g = 9.81
timefactor = 0.01 // adjust here
acc_y = g
WHILE TRUE
speed_y = (speed_y * g ) timefactor
pos_y = pos_y + speed_d*timefactor
PRINT "Falling", 0,pos_y
SHOWSCREEN
WEND