Beta release 2.0.1b

Information and change log about the latest ZGameEditor release.

Moderator: Moderators

Post Reply
StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

Post by StevenM »

Thanks - I like this a lot. I think setting up points and spot lights should be fairly easy now too - esp. with the example project as a reference. This is going to fun to experiment with.
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

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:

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);
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:

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) { }
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
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:shock:

Massive new feature! Guess the only thing remaining now is being able to reference Arrays .. for glTexImage2D and such ( tried it, but it says "Cannot get address of expression: ((int)Data)" ).

And, you're not a fan of the & prefix in C? Or is that more difficult to parse?

K
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

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.
StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

Post by StevenM »

That is a very good update that opens up a whole new level of functionality, especially when it come to using external libraries. - Is it too soon to update the visualizer?
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

Post by StevenM »

Thanks Ville! - got it and it's working fine.
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

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:

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) {}
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
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

:)

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 733 times
Last edited by Kjell on Tue Feb 14, 2012 6:05 pm, edited 1 time in total.
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

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.
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Oops,
VilleK wrote:Actually passing to internal functions doesn't really work yet, your function modifies the global Bar-array.
Silly mistake :oops: I've removed the example for now. Good to hear that your planning to support it though.

K
StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

Post by StevenM »

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.
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.

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 700 times
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

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.
StevenM
Posts: 149
Joined: Thu Jan 20, 2011 10:03 am

Post by StevenM »

OK, that is easy to fix - it usually takes me a while to notice things like that -so thanks for the quick reply.
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Steven,
StevenM wrote:A lot of functions that are commented out will probably work now too...Does that include the stencil buffer?
You could already call the stencil related functions .. but since ZGE doesn't use a stencil-buffer, they don't / shouldn't work.

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
Post Reply