Beta release 2.0.1b
Moderator: Moderators
First update in 2012 adds a new scripting feature: Pass reference arguments to functions using the "ref" syntax. "Ref" stands for "reference".
This allows you to return more than one value from a function.
Example 1:
Another great thing with this feature is that it allows to call dll-functions that expects a pointer to an integer as an argument. This was previously not possible.
Example 2:
Of course it works with other datatypes too, not just integers. And there are probably bugs, just let me know of any problems 
http://www.zgameeditor.org/files/ZGameEditor_beta.zip
This allows you to return more than one value from a function.
Example 1:
Code: Select all
//notice the "ref" word in front of the arguments that are passed by reference
void splitColor(int color,ref int r, ref int g, ref int b) {
//..separate r,g,b from color and return back to caller
}
//call this function
int r,g,b;
splitColor(0xff8020,r,g,b);
Example 2:
Code: Select all
//OpenGL-function, generate a texture id and return it into the second argument
void glGenTextures(int n, ref int textureid) { }
//Delete a texture, pass the id using a reference
void glDeleteTextures(int n, ref int textureid) { }

http://www.zgameeditor.org/files/ZGameEditor_beta.zip
I chose the "ref" syntax over "&" because I've been using C# as main influence for the scripting so it is consistent with other language features. Arguably it is more easy to read when glancing over a piece of code too.
Yeah definitely, we need to be able to pass arrays to external functions. I will look into that next. I recently read a pretty good book called "OpenGL 4.0 Shading language cookbook" and thought it would be cool if it was possible to implement examples from that book in ZGE scripting. At the minimum, ref-parameters and array-passing are required for this to work.
Yeah definitely, we need to be able to pass arrays to external functions. I will look into that next. I recently read a pretty good book called "OpenGL 4.0 Shading language cookbook" and thought it would be cool if it was possible to implement examples from that book in ZGE scripting. At the minimum, ref-parameters and array-passing are required for this to work.
ZgeViz updated too: http://www.zgameeditor.org/files/ZGameE ... r_Beta.zip
Thanks Ville! - got it and it's working fine.VilleK wrote:ZgeViz updated too: http://www.zgameeditor.org/files/ZGameE ... r_Beta.zip
And here is an update on how to pass arrays to external functions:
A new datatype called "xptr" (pointer to be passed to external functions). At the moment only DefineArray components are valid xptr but other components may be added too if needed.
Example:
These functions can now be called with an DefineArray instance as the last parameter. This should open for lots of interesting possibilities when working with OpenGL-functions.
As usual, I've only done very basic testing of this myself, so let me know of any problems! If it works then I'll rebuild ZgeViz with this feature too.
http://www.zgameeditor.org/files/ZGameEditor_beta.zip
A new datatype called "xptr" (pointer to be passed to external functions). At the moment only DefineArray components are valid xptr but other components may be added too if needed.
Example:
Code: Select all
//OpenGL external library definitions, notice the last parameter "xptr pixels"
void glTexImage2D(int target, int level, int internalformat, int width, int height, int border, int format, int atype, xptr pixels) {}
void glGetTexImage(int target, int level, int format, int atype, xptr pixels) {}
As usual, I've only done very basic testing of this myself, so let me know of any problems! If it works then I'll rebuild ZgeViz with this feature too.
http://www.zgameeditor.org/files/ZGameEditor_beta.zip

Super nice! Attached is a bare-bone example that creates a floating-point texture from a 2D Array.
K
- Attachments
-
- Texture.zgeproj
- (1.43 KiB) Downloaded 1104 times
Last edited by Kjell on Tue Feb 14, 2012 6:05 pm, edited 1 time in total.
Cool 
Actually passing to internal functions doesn't really work yet, your function modifies the global Bar-array. But I'll be working on fixing that too.
I'm going to create a automated conversion of the OpenGL header files for ZGE so that most constants and functions can be included easily. I'm thinking this will make ZGE a great tool for experimenting with the OpenGL API.

Actually passing to internal functions doesn't really work yet, your function modifies the global Bar-array. But I'll be working on fixing that too.
I'm going to create a automated conversion of the OpenGL header files for ZGE so that most constants and functions can be included easily. I'm thinking this will make ZGE a great tool for experimenting with the OpenGL API.
Looking forward to that - I did convert the entire OpenGL header file for personal use - It was a quick - lazy conversion though using find and replace with notepad. it worked, until the last update - I get an "indent expected" error with this (come up in the visualizer). It must be a syntax error that previously went undetected for some reason, but I haven't been able to track it down.I'm going to create a automated conversion of the OpenGL header files for ZGE so that most constants and functions can be included easily.
With built in headers though - won't have to worry about this sort of thing anymore. A lot of functions that are commented out will probably work now too...Does that include the stencil buffer?
- Attachments
-
- OpenGlDefinitions.zip
- (10.25 KiB) Downloaded 1075 times
Good work Steven. The reason your header conversion do not work anymore is because there are a couple of parameters called "ref", like this:
void glAlphaFunc( int func, float ref ){}
But ZGE has now reserved the word "ref" to mean "reference to parameter". Changing the parameter name to something else will make it work again.
void glAlphaFunc( int func, float ref ){}
But ZGE has now reserved the word "ref" to mean "reference to parameter". Changing the parameter name to something else will make it work again.
Hi Steven,
Using the new "ref" feature it's ( probably ) possible to destroy the current rendering context and create a new one that does have a stencil buffer, but this is not exactly ideal nor cross-platform.
K
You could already call the stencil related functions .. but since ZGE doesn't use a stencil-buffer, they don't / shouldn't work.StevenM wrote:A lot of functions that are commented out will probably work now too...Does that include the stencil buffer?
Using the new "ref" feature it's ( probably ) possible to destroy the current rendering context and create a new one that does have a stencil buffer, but this is not exactly ideal nor cross-platform.
K