Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - aonyn

#76
GLBasic - en / Re: hello
2010-Sep-16
Hi sam.mark,

Welcome, and I am sure you will like it here.
I am relatively new here myself, and have found this to be the friendliest forum I have ever participated in.
MrTAToad who welcomed you first is among the most helpful users here, he has always been very quick to help me with questions (which are probably sometimes dumb questions as I am an amateur, but no-one here ever makes me feel as such  :) ).

#77
I am not positive whether the dll is unicode or ascii yet.
I searched the forum here and it appears that glbasic is simply does not support unicode.

In the purebasic documentation, it appears I can easily do a conversion using the built in ReadString and WriteString commands, with the appropriate flags.
So, I am thinking of writing a set of procedures to handle it in purebasic, compile it as a dll, and wrap that as well and call my own function from that dll as necessary.
I have never created a dll with purebasic, but I know it has the capability, and think this may be the easiest way for me to handle this.

If someone has a better approach I can try, I would of course love to hear any suggestions.

Thanks again everyone for your help.

regards,
Dave
#78
Hi Ocean,

No, I had not.
This is entirely new ground for me.

Thank you for the tip, that certainly makes sense as a possibility.
I will investigate that as well, and of course will post back.

regards,
Dave
#79
Hi All,

I just started to make a wrapper for Blitz3d SDK, not because I want it wrapped for GLBasic, but rather just to see if I have success with that engine dll, using the method I am already using.
It works perfectly, no trouble at all. Even strings are passed properly to const char* parameters.

Anyway, this definately confirms to me, something is being done differently in the xors3d engine with const char* types (as I already suspected based on seeing some reference to charsArray.
I will investigate further, and post back if/when I figure out the solution.

regards,
Dave
#80
Hi MrTAToad,

Thanks once again, at least now I understand what has happened, and just need to write my code accordingly, which of course the solution I already discovered.

regards,
Dave
#81
Hi Slydog,

Yes, I noticed your solution works as well, and had mentioned it in my original post.
I am sorry I forgot to add that solution with comments as well to the sample code.
And yes, it does seem to be a scope bug, fortunately in my case, not a showstopper, I can easily work around it, and I am still moving forward.
However, perhaps it could be a showstopper in a more sophisticated project than the one I am working on.
I just wanted to make sure Gernot is aware of it, since I stumbled on it, and did not know if it is a known issue.
Perhaps I can plant my flag and call it my discovery.  :giveup: (I know, wrong context for this emoticon, but it sort of works in a convoluted way  :S)

regards,
Dave
#82
OK, thanks for the tip MrTAToad,

That at least gives me a starting point to begin looking at.

Regards,
Dave
#83
Hi again MrTAToad,

Here is sample code, just a small sample from my project, but enough to demonstrate the bug.
Please notice a few things.

The offsetX% and screenWidth% LOCAL variables defined below the TYPE definition.
In both embedded functions, offsetX% is an argument. The function called testInput() has no problem using the argument name offsetX%.
However the next function called draw() will not allow it.
This is the compile error:
Code (glbasic) Select

_______________________________________
*** Configuration: WIN32 ***
precompiling:
GPC - GLBasic Precompiler V.8.044 SN:380c888f - 3D, NET
Wordcount:11 commands
compiling:
C:\DOCUME~1\jasonl\LOCALS~1\Temp\glbasic\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\DOCUME~1\jasonl\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:93: error: `screenWidth' was not declared in this scope
C:\DOCUME~1\jasonl\LOCALS~1\Temp\glbasic\gpc_temp0.cpp:97: error: `offsetX' was not declared in this scope
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Elapsed: 1.4 sec. Time: 17:28
Build: 0 succeeded.
*** 1 FAILED ***


Also, please note I duplicated the draw() function and commented it out again, but with the suspect argument names changed to new unique names.
If you comment the original draw(), and uncomment the altered draw(), you will see changing the names fixes the problem.
Note that the testInput() function is still using the original argument offsetX% successfully.

Here is the sample code:
Code (glbasic) Select

// --------------------------------- //
// Project: TypeBugSample
// Start: Wednesday, September 15, 2010
// IDE Version: 8.085

SYSTEMPOINTER TRUE

SETCURRENTDIR("Media")

TYPE bowl
file$
id%
id2%
chnInst% = 4
chn% = 0
chn2% = 0
vol# = 0.8
dur%
rep%
sTime%
cTime%
phase%
x%
y%
width%
height%
color%

FUNCTION testInput: touchX, touchY, offsetX%
IF (touchX >= (self.x% + offsetX%)) AND (touchX <= (self.x% + self.width% + offsetX%)) AND (touchY >= self.y%) AND (touchY <= (self.y% + self.height%))
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDFUNCTION

FUNCTION draw: screenWidth%, offsetX%
IF (self.x% + offsetX% + self.width% > 0) AND (self.x% + offsetX% < screenWidth%)
DRAWRECT self.x% + offsetX%, self.y%, self.width%, self.height%, self.color%
ENDIF
ENDFUNCTION

// FUNCTION draw: scrWidth%, offset_X%
// IF (self.x% + offset_X% + self.width% > 0) AND (self.x% + offset_X% < scrWidth%)
// DRAWRECT self.x% + offset_X%, self.y%, self.width%, self.height%, self.color%
// ENDIF
// ENDFUNCTION
ENDTYPE

LOCAL screenWidth% = 480
LOCAL offsetX% = 0


Regards,
Dave
#84
Hi MrTAToad,

Thanks again, I am hoping your comment about something else needs to be included may be the key.
I am wondering if perhaps a better approach may be to take another approach, and use the c++ headers and libraries which were included in the demo using inline c++, then import the functions to glbasic.
Unfortunately, I am not sure exactly how this is done, but I will begin looking through sample code from the forum to see if I can find an example, or if you have any advice how to try this, of course any help is appreciated.

regards,
Dave
#85
Hi,

I just encountered some strange behavior.

I have several LOCAL variables, defined in my program after my TYPE definitions.
These type definitions contain functions, some with arguments.

The strange thing is, I added many functions with arguments, using the same names as some of the local variables outside and after the types, without trouble.
However, I just added another function to the last defined type, using two argument names which had already been used in other functions, and the compiler began to complain that those variables were not defined in this scope.

I was able to correct the problem two ways, but still I think there is some bug in the compiler.
The first way to correct the problem was to define the LOCAL variables to the main program BEFORE my type definitions - compiler problem gone, program works as expected.
The second way to correct the problem was to change the names of the arguments in the embedded function which caused the problem to new and unique names. - compiler problem gone, program works as expected. The strange thing being that earlier embedded functions use the existing argument names without trouble.

I was able to work around the problem, so it is not a showstopper.
However the behavior seems odd, and perhaps suspect, so I decided to post about it here.

regards,
Dave
#86
Hi MrTAToad,

Thanks, your advice did help, and the dll seems to be mostly working.
Although I do have a lingering problem, well a couple, but one specific to the dll (I think the other I need to rethink something I translated from PB in the sample code)

The problem I am concerned with is any function from the dll which currently takes a const char*.
These functions are not working correctly, and are corrupting the strings I pass.

I checked the .h files provided with the dll for use with C++, and they are using charsArray instead of const char*, in xorsbind.h, and they are using const char * in xors3d.h (note the space before the pointer - not sure if that is significant).
GLBasic INLINE does not seem to even recognize charsArray.
Does anyone know what I can do to pass strings to charsArray, or is there something I can do to make a const char* pass in a compatible format for a charsArray?

regards,
Dave
#87
Thank you very much MrTAToad.

I was getting the function names from the html documentation which came with the dll.
In there, the extra characters were not included.

After seeing your explanation, I just dug into the dll with dependency walker, and lo and behold, you are correct.
I don't fully understand why the function names are different than the documented function names, but I guess sometimes it is important to just accept the magic.

Also how dumb do I feel now  :S but I guess it takes trying and making dumb mistakes to learn.  :)

Thank you for your very useful feedback.

regards,
Dave
#88
Hi MrTAToad,

Thanks for the quick reply!  :)

I may be completely misunderstanding, but I think I am loading the DLL implicitly, by naming it as the 2nd argument in the DECLARE_ALIAS call.
The dll is placed in the program (app) directory which is I think the first place it is searched for by order of precedence.

I am attaching the complete project to this post.
It also contains the demo version dll's, as well as the image file used in the sample code.

Thanks,
Dave

[attachment deleted by admin]
#89
Hi All,

I am attempting to wrap a dll, specifically, a new xors3d wrapper.
I am aware one exists, but I want to learn, and I understand the existing wrapper is no longer maintained anyway.
If I can successfully wrap xors3d, of course it will be my contribution to the community, and will be a nice compliment to bigsofty's ixors3d wrapper.

Anyway, I have one of the working samples from the purebasic version translated to glbasic, and necessary functions are wrapped to support the sample.
It compiles with no errors, but does not work as expected.
The wrapper file is added to the project, the dll files provided with the xors3d demo are place in the app folder inside the project, and the texture is placed in app's media folder, in a subfolder called textures

If someone sees what I am doing wrong, please provide me some feedback, so I can continue moving forward.
This is my first adventure with inline code, and I am working from Gernot's dll wrapping tutorial, as well as looking at how the purebasic wrapper is built for comparison.

Here is the sample code
Code (glbasic) Select

// --------------------------------- //
// Project: xors3d headers
// Start: Monday, September 13, 2010
// IDE Version: 8.085

// Sample xors3d usage

//GLOBAL KEY_ESCAPE% = 01
//GLOBAL KEY_W% = 17
//GLOBAL KEY_S% = 31
//GLOBAL KEY_A% = 30
//GLOBAL KEY_D% = 32

GLOBAL KEY_ESCAPE% = 27
GLOBAL KEY_W% = 87
GLOBAL KEY_S% = 83
GLOBAL KEY_A% = 65
GLOBAL KEY_D% = 68

// setup maximum supported AntiAlias TYPE
xSetAntiAliasType(xGetMaxAntiAlias())

// set application window caption
xAppTitle("Simple sample")

// initialize graphics mode
xGraphics3D(800, 600, 32, FALSE, TRUE)

// hide mouse pointer
xHidePointer()

// enable antialiasing
xAntiAlias(TRUE)

// create camera
LOCAL camera% = xCreateCamera(0)

// position camera
xPositionEntity(camera, 0, 0, -10)

// create cube
LOCAL cube% = xCreateCube(0)

// loading logo from file
LOCAL logoTexture% = xLoadTexture("Media\Textures\logo.jpg")

// texture cube
xEntityTexture(cube, logoTexture)

// for mouse look
xMoveMouse(xGraphicsWidth()*0.5, xGraphicsHeight()*0.5)
LOCAL mousespeed# = 0.5
LOCAL camerasmoothness# = 4.5

// main program loop
WHILE NOT xKeyDown(KEY_ESCAPE)
IF xKeyDown(KEY_W)
xMoveEntity(camera,  0,  0,  1)
ENDIF

IF xKeyDown(KEY_S)
xMoveEntity(camera,  0,  0, -1)
ENDIF

IF xKeyDown(KEY_A)
xMoveEntity(camera, -1,  0,  0)
ENDIF

IF xKeyDown(KEY_D)
xMoveEntity(camera,  1,  0,  0)
ENDIF

LOCAL mxs# = 0.0
LOCAL mys# = 0.0

mxs = CurveValue(xMouseXSpeed() * mousespeed, mxs, camerasmoothness)
mys = CurveValue(xMouseYSpeed() * mousespeed, mys, camerasmoothness)

LOCAL Fix% = MOD(FtoI(mxs),360) + (mxs - FtoI(mxs))

LOCAL camxa# = 0.0
LOCAL camya# = 0.0

camxa = camxa - Fix
camya = camya + mys

IF camya < -89
camya = -89
ENDIF

IF camya > 89
camya = 89
ENDIF

xMoveMouse(xGraphicsWidth()*0.5, xGraphicsHeight()*0.5)

xRotateEntity(camera, camya, camxa, 0.0)

// turn cube
xTurnEntity(cube, 0, 1, 0)

// render scene
xRenderWorld()

// switch back buffer
xFlip()
WEND

// for camera mouse look
FUNCTION CurveValue#: newValue#, oldValue#, increments%
IF increments% > 1
oldValue# = oldValue# - (oldValue# - newValue#) / increments%
ENDIF
IF increments% <= 1
oldValue# = newValue#
ENDIF
RETURN oldValue#
ENDFUNCTION

// float to integer
FUNCTION FtoI%: input#
LOCAL output% = input#
RETURN output%
ENDFUNCTION


And here is the wrapper code
Code (glbasic) Select

// --------------------------------- //
// Project: xors3d headers
// Start: Monday, September 13, 2010
// IDE Version: 8.085

// AntiAliasing Types
GLOBAL AANONE% = 0
GLOBAL AA2SAMPLES% = 1
GLOBAL AA3SAMPLES% = 2
GLOBAL AA4SAMPLES% = 3
GLOBAL AA5SAMPLES% = 4
GLOBAL AA6SAMPLES% = 5
GLOBAL AA7SAMPLES% = 6
GLOBAL AA8SAMPLES% = 7
GLOBAL AA9SAMPLES% = 8
GLOBAL AA10SAMPLES% = 9
GLOBAL AA11SAMPLES% = 10
GLOBAL AA12SAMPLES% = 11
GLOBAL AA13SAMPLES% = 12
GLOBAL AA14SAMPLES% = 13
GLOBAL AA15SAMPLES% = 14
GLOBAL AA16SAMPLES% = 15

// Texture Loading Flags
GLOBAL FLAGS_COLOR% = 1
GLOBAL FLAGS_ALPHA% = 2
GLOBAL FLAGS_MASKED% = 4
GLOBAL FLAGS_MIPMAPPED% = 8
GLOBAL FLAGS_CLAMPU% = 16
GLOBAL FLAGS_CLAMPV% = 32
GLOBAL FLAGS_SPHERICALENVMAP% = 64
GLOBAL FLAGS_CUBICENVMAP% = 128
GLOBAL FLAGS_R32F% = 256
GLOBAL FLAGS_RESERVED% = 512
GLOBAL FLAGS_VOLUMETEXTURE% = 1024
GLOBAL FLAGS_ARGB16F% = 2048
GLOBAL FLAGS_ARGB32F% = 4096

INLINE
extern "C"
{
// Camera Functions
DECLARE_ALIAS(glb_xCreateCamera, "xors3d.dll", "xCreateCamera", (int, int), int);

// Entity Control Functions
DECLARE_ALIAS(glb_xEntityTexture, "xors3d.dll", "xEntityTexture", (int, int, int, int), void);

// Entity Movement Functions
DECLARE_ALIAS(glb_xPositionEntity, "xors3d.dll", "xPositionEntity", (int, float, float, float, int), void);
DECLARE_ALIAS(glb_xMoveEntity, "xors3d.dll", "xMoveEntity", (int, float, float, float, int), void);
DECLARE_ALIAS(glb_xRotateEntity, "xors3d.dll", "xRotateEntity", (int, float, float, float, int), void);
DECLARE_ALIAS(glb_xTurnEntity, "xors3d.dll", "xTurnEntity", (int, float, float, float, int), void);

// Graphics Functions
DECLARE_ALIAS(glb_xRect, "xors3d.dll", "xRect", (int, int, int, int, int), void);
DECLARE_ALIAS(glb_xGetMaxAntiAlias, "xors3d.dll", "xGetMaxAntiAlias", (), int);
DECLARE_ALIAS(glb_xSetAntiAliasType, "xors3d.dll", "xSetAntiAliasType", (int), void);
DECLARE_ALIAS(glb_xAppTitle, "xors3d.dll", "xAppTitle", (const char*), void);
DECLARE_ALIAS(glb_xSetWND, "xors3d.dll", "xSetWND", (int), void);
DECLARE_ALIAS(glb_xSetRenderWindow, "xors3d.dll", "xSetRenderWindow", (int), void);
DECLARE_ALIAS(glb_xFlip, "xors3d.dll", "xFlip", (), void);
DECLARE_ALIAS(glb_xGraphicsWidth, "xors3d.dll", "xGraphicsWidth", (), int);
DECLARE_ALIAS(glb_xGraphicsHeight, "xors3d.dll", "xGraphicsHeight", (), int);
DECLARE_ALIAS(glb_xRenderWorld, "xors3d.dll", "xRenderWorld", (float, int), void);
DECLARE_ALIAS(glb_xAntiAlias, "xors3d.dll", "xAntiAlias", (int), void);
DECLARE_ALIAS(glb_xHidePointer, "xors3d.dll", "xHidePointer", (), void);
DECLARE_ALIAS(glb_xGraphics3D, "xors3d.dll", "xGraphics3D", (int, int, int, int, int), void);

// Input - Keyboard Functions
DECLARE_ALIAS(glb_xKeyDown, "xors3d.dll", "xKeyDown", (int), int);

// Input - Mouse Functions
DECLARE_ALIAS(glb_xMouseXSpeed, "xors3d.dll", "xMouseXSpeed", (), int);
DECLARE_ALIAS(glb_xMouseYSpeed, "xors3d.dll", "xMouseYSpeed", (), int);
DECLARE_ALIAS(glb_xMoveMouse, "xors3d.dll", "xMoveMouse", (int, int), void);

// Mesh Functions
DECLARE_ALIAS(glb_xCreateCube, "xors3d.dll", "xCreateCube", (int, int), int);

// Texture Functions
DECLARE_ALIAS(glb_xLoadTexture, "xors3d.dll", "xLoadTexture", (const char*, int), int);
}
ENDINLINE

// Camera Functions
FUNCTION xCreateCamera: entity%, parent%=0
INLINE
if(glb_xCreateCamera)
return glb_xCreateCamera(entity, parent);
ENDINLINE
ENDFUNCTION

// Entity Control Functions
FUNCTION xEntityTexture: entity%, texture%, frame%=0, index%=0
INLINE
if(glb_xEntityTexture)
glb_xEntityTexture(entity, texture, frame, index);
ENDINLINE
ENDFUNCTION

// Entity Movement Functions
FUNCTION xPositionEntity: entity%, x#, y#, z#, isGlobal%=FALSE
INLINE
if(glb_xPositionEntity)
glb_xPositionEntity(entity, x, y, z, isGlobal);
ENDINLINE
ENDFUNCTION

FUNCTION xMoveEntity: entity%, x#, y#, z#, isGlobal%=FALSE
INLINE
if(glb_xMoveEntity)
glb_xMoveEntity(entity, x, y, z, isGlobal);
ENDINLINE
ENDFUNCTION

FUNCTION xRotateEntity: entity%, x#, y#, z#, isGlobal%=FALSE
INLINE
if(glb_xRotateEntity)
glb_xRotateEntity(entity, x, y, z, isGlobal);
ENDINLINE
ENDFUNCTION

FUNCTION xTurnEntity: entity%, x#, y#, z#, isGlobal%=FALSE
INLINE
if(glb_xTurnEntity)
glb_xTurnEntity(entity, x, y, z, isGlobal);
ENDINLINE
ENDFUNCTION

// Graphics Functions
FUNCTION xRect: x%, y%, width%, height%, solid%=FALSE
INLINE
if(glb_xRect)
glb_xRect(x, y, width, height, solid);
ENDINLINE
ENDFUNCTION

FUNCTION xGetMaxAntiAlias:
INLINE
if(glb_xGetMaxAntiAlias)
return glb_xGetMaxAntiAlias();
ENDINLINE
ENDFUNCTION

FUNCTION xSetAntiAliasType: typeID%
INLINE
if(glb_xSetAntiAliasType)
glb_xSetAntiAliasType(typeID);
ENDINLINE
ENDFUNCTION

FUNCTION xAppTitle: title$
INLINE
if(glb_xAppTitle)
glb_xAppTitle(title_Str.c_str());
ENDINLINE
ENDFUNCTION

FUNCTION xSetWND: window%
INLINE
if(glb_xSetWND)
glb_xSetWND(window);
ENDINLINE
ENDFUNCTION

FUNCTION xSetRenderWindow: window%
INLINE
if(glb_xSetRenderWindow)
glb_xSetRenderWindow(window);
ENDINLINE
ENDFUNCTION

FUNCTION xFlip:
INLINE
if(glb_xFlip)
glb_xFlip();
ENDINLINE
ENDFUNCTION

FUNCTION xGraphicsWidth:
INLINE
if(glb_xGraphicsWidth)
return glb_xGraphicsWidth();
ENDINLINE
ENDFUNCTION

FUNCTION xGraphicsHeight:
INLINE
if(glb_xGraphicsHeight)
return glb_xGraphicsHeight();
ENDINLINE
ENDFUNCTION

FUNCTION xRenderWorld: twin#=1.0, renderShadows%=FALSE
INLINE
if(glb_xRenderWorld)
glb_xRenderWorld(twin, renderShadows);
ENDINLINE
ENDFUNCTION

FUNCTION xAntiAlias: state%
INLINE
if(glb_xAntiAlias)
glb_xAntiAlias(state);
ENDINLINE
ENDFUNCTION

FUNCTION xHidePointer:
INLINE
if(glb_xHidePointer)
glb_xHidePointer();
ENDINLINE
ENDFUNCTION

FUNCTION xGraphics3D: width%=640, height%=480, depth%=16, mode%=FALSE, vsync%=FALSE
INLINE
if(glb_xGraphics3D)
glb_xGraphics3D(width, height, depth, mode, vsync);
ENDINLINE
ENDFUNCTION

// Input - Keyboard Functions
FUNCTION xKeyDown: key%
INLINE
if(glb_xKeyDown)
return glb_xKeyDown(key);
ENDINLINE
ENDFUNCTION

// Input - Mouse Functions
FUNCTION xMouseXSpeed:
INLINE
if(glb_xMouseXSpeed)
return glb_xMouseXSpeed();
ENDINLINE
ENDFUNCTION

FUNCTION xMouseYSpeed:
INLINE
if(glb_xMouseYSpeed)
return glb_xMouseYSpeed();
ENDINLINE
ENDFUNCTION

FUNCTION xMoveMouse: x%, y%
INLINE
if(glb_xMoveMouse)
glb_xMoveMouse(x, y);
ENDINLINE
ENDFUNCTION

// Mesh Functions
FUNCTION xCreateCube: entity%, parent%=0
INLINE
if(glb_xCreateCube)
return glb_xCreateCube(entity, parent);
ENDINLINE
ENDFUNCTION

// Texture Functions
FUNCTION xLoadTexture: path$, flag%=9
INLINE
if(glb_xLoadTexture)
return glb_xLoadTexture(path_Str.c_str(), flag);
ENDINLINE
ENDFUNCTION


Thanks in advance,
Dave
#90
Triped  :good: