PDA

View Full Version : glColor3fv



matthew
18-03-2007, 20:17
Hi Petr, I'm trying to use 'glColor3fv' to read a set of Colours from an Array.

But I keep getting this Error Message... ???

"Expected a parameter passed BYREF but found something else."

ErosOlmi
18-03-2007, 20:29
Declaration of glColor3fv is the following:


DECLARE FUNCTION glColor3fv LIB "opengl32.dll" ALIAS "glColor3fv" (v AS DWORD) AS LONG


Has it has been declared, v is a DWORD variable passed by reference and not by value.
It means you have to declare a DWORD variable and pass it to glColor3fv directly and not as an expression.
So something like:


DIM MyDWord as DWORD
glColor3fv(MyDWord)


I do not know what glColor3fv does so do not know if v is just a DWORD variable receiving a number or is a pointer to some data structure.

Do you have some code to show where the error occurs?

Eros

Petr Schreiber
18-03-2007, 20:33
Hi,

Eros thanks for the help but this is probably bug in my headers, as I said I am reworking them now.

Correct declaration ( hehe, or working ) should be:


DECLARE SUB glColor3fv LIB "opengl32.dll" ALIAS "glColor3fv" ( BYREF v() AS SINGLE )


Now lets presume we have this array to hold values:


dim arr(3) as single
arr(1) = 255
arr(2) = 128
arr(3) = 64


Then correct call ( passing array ) seems to be like:


glColor3fv arr


My apologies for headers bug ( and there are many ), I will correct them as promised.


Bye,
Petr

matthew
18-03-2007, 20:39
Thank's for your help, I'll try that.

I'm currently working on NeHe Lesson 12. ;)

ErosOlmi
18-03-2007, 20:40
Petr, I think it is the same.
Not tested but passing a VARPTR to the first element of the array is like passing the whoole array.

So original declaration was almost ok. Only change to:

DECLARE FUNCTION glColor3fv LIB "opengl32.dll" ALIAS "glColor3fv" (BYVAL v AS DWORD) AS LONG

and usage is:


dim arr(3) as single
arr(1) = 255
arr(2) = 128
arr(3) = 64
glColor3fv VARPTR(arr(1))


In any case glColor3fv expects a pointer to an array of 3 elements of singles

Always remember that best option for pointers to anything is to pass them BYVAL.

Ciao
Eros

Petr Schreiber
18-03-2007, 20:48
Hi Eros,

you are right.
I like your version better :)

Please don't forget the values are in range [0,1] not [0,255] for this function


Bye,
Petr

ErosOlmi
18-03-2007, 21:08
Petr,

which values?
Which DECLARE do you prefer to distribute with official thinBasic?

Eros

Petr Schreiber
18-03-2007, 22:12
Hi Eros,

just those in array :)

Regarding which one... your version is logical, mine maybe more secure when trying to pass array of other type ( if other type thinBASIC will stop ? ).

I am sorry but I am too tired for decisions now :)
Using my way I am also passing pointer but byref ?


Thanks,
Petr

ErosOlmi
18-03-2007, 22:40
OK Petr,

I will use your version. It is more evident to users.
In any case thinBasic will intepret it in correct way that is:


BYVAL MySingleArray AS SINGLE PTR


Ciao
Eros