View Full Version : Glu...
I'm trying to use the following Code in my Programme...
quadratic = glunewquadric
gluQuadricNormals quadratic, %glu_smooth
gluquadrictexture quadratic, %gl_true
But I keep getting this Error message...
'Expected a parameter passed BYREF but found something else.'
Mathew you are a brave sole, venturing into lands I know not of. I thought I would master openGl but got so confused by GLU, GLUT, GL itself. I admire your venturing into it and tackling it all as Petr and I think Mike have done. I am sure one of those guys will have the answer for you when they get online later today.
^^
I hope they've got the answer. :D
ErosOlmi
20-03-2007, 04:39
The problem is in the following declare in thinbasic_GLU.inc include file:
DECLARE FUNCTION gluQuadricTexture LIB "glu32.dll" ALIAS "gluQuadricTexture" (BYVAL quadObject AS DWORD, textureCoords AS DWORD) AS LONG
textureCoords parameters is declared to be passed BY REFERENCE so it is not possible to to pass a constant like %gl_true but some kind of pointer must be passed. I do not know the meaning of those functionalities so I cannot reply about what information gluQuadricTexture is expecting. Googling around it seems it is just a flag so try to change declaration to the following:
DECLARE FUNCTION gluQuadricTexture LIB "glu32.dll" ALIAS "gluQuadricTexture" (BYVAL quadObject AS DWORD, BYVAL textureCoords AS DWORD) AS LONG
Petr will reply if I'm right or not.
In general, passing a parameter by reference means passing a pointer the that parameter.
For example passing a DWORD by reference (like in first above declare here) means passing a pointer to a DWORD variable. So it is not possible to pass %gl_true because it is a value.
Ciao
Eros
Eros, I am confused. So unless you see ByVal you always assume it is ByReference when you see declarations like that?
ErosOlmi
20-03-2007, 08:55
In general yes, but you have to think language by language.
In thinBasic when you use DECLARE statement to tell thinBasic you are using an external function, if parameter has no BYREF/BYVAL it is assumend to be BYREF. We followed the same syntax of Power Basic language. In other languages it can be different.
But when you create a script function is not the same. For example
function MyFunction(MyLong as long) as long
'---Do whatever
'...
end function
in this case MyLong is passed BYVAL because default behave in thinBasic script is BYVAL. If you want to pass a LONG variable by reference you have to precede parameter name with BYREF statement.
You can change default behave in thinbasic using #DEFAULT PARAMETERS (http://www.thinbasic.com/public/products/thinBasic/help/html/parameters.htm) directive. But this will effect only script functions and not external DECLARE functions that will contonue to act the same.
So the best is always indicate BYREF or BYVAL in all script functions parameters.
Ciao
Eros
Thanks and whenever we see byRef, that means it is a pointer it is expecting.
Is there a dereferencing command in thinBasic as in C++?
So that pointer ptr which points to the address of variable var, can also be derefenced as &var instead of using ptr?
ErosOlmi
20-03-2007, 09:19
Ken,
no there is no dereferencing commands in thinBasic but you can use POKE/PEEK to assign or get data using pointers. In any case we are thinking about it.
Also consider that when you see a BYREF parameters you do not need pass a pointer but a single variable of exact that type. thinBasic will do the job to pass a pointer. So when you see something like
... BYREF MyVar as DWORD ...
just be sure to pass a variable of type DWORD and thinBasic will internally pass a pointer to that variable automatically.
Eros
That is very sweet Eros and so logical. And good old poke and peek, I missed those and forgot about them. Things sounds perfect the way they are. Just maybe a good explanation of these concepts in the help would help. For example people wanting to convert programs from c to thinBasic it would help knowing this stuff for sure.
Thanks, got a good idea now of how it works in thinBasic and it is very logical how you guys set it up. Really nice!!
Petr Schreiber
20-03-2007, 10:44
Hi Mathew,
I should found some "Bug breeding station", I would be good at it :)
Try this code, should work:
'
' Quadric sphere
'
Uses "TBGL"
Dim hWnd As Dword
%GLU_SMOOTH = 100000
%GL_TRUE = 1
DECLARE FUNCTION gluNewQuadric LIB "glu32.dll" ALIAS "gluNewQuadric" () AS dword
DECLARE FUNCTION gluSphere LIB "glu32.dll" ALIAS "gluSphere" (BYVAL qobj AS DWORD, BYVAL radius AS DOUBLE, BYVAL slices AS LONG, BYVAL stacks AS LONG) AS LONG
DECLARE FUNCTION gluQuadricNormals LIB "glu32.dll" ALIAS "gluQuadricNormals" (BYVAL quadObject AS DWORD, BYVAL normals AS DWORD) AS LONG
DECLARE FUNCTION gluQuadricTexture LIB "glu32.dll" ALIAS "gluQuadricTexture" (BYVAL quadObject AS DWORD, BYVAL textureCoords AS DWORD) AS LONG
DECLARE FUNCTION gluDeleteQuadric LIB "glu32.dll" ALIAS "gluDeleteQuadric" (BYVAL quadricobj AS DWORD) AS LONG
hWnd = TBGL_CreateWindowEx("Quadric sphere - press ESC to quit", 640, 480, 32, 0)
TBGL_ShowWindow
TBGL_GetAsyncKeyState(-1)
' Here we initialize our quadric sphere
dim quadratic as dword
quadratic = glunewquadric
gluQuadricNormals (quadratic, %glu_smooth)
gluquadrictexture (quadratic, %gl_true )
tbgl_UseLighting 1
tbgl_UseLightSource %GL_LIGHT0, 1
' This is for TBGL sphere
tbgl_SetPrimitiveQuality 48
While TBGL_IsWindow(hWnd)
tbgl_ClearFrame
tbgl_camera 5,5,5,0,0,0
tbgl_color 128,0,0
gluSphere (quadratic, 1, 24, 24)
tbgl_Translate 2,0,0
tbgl_color 0,128,0
tbgl_Sphere 1
tbgl_DrawFrame
If TBGL_GetWindowKeyState( hWnd, %VK_ESCAPE) Then Exit While
Wend
' We must destroy quadric object
gluDeleteQuadric(quadratic)
TBGL_DestroyWindow
... and sorry for late reply,
Petr
Excellent, thank's Petr. :)
Petr Schreiber
20-03-2007, 16:51
Hi Matthew,
I'm happy you like it.
To protect you from life in fear what other feature won't work in headers I created new release (http://community.thinbasic.com/index.php?topic=725.msg4245) of them, which should be less buggy. I used 2 best headers I have + MS documentation from Win32 to get most accurate translation.
They should be part of thinBASIC from next release.
Bye,
Petr