PDA

View Full Version : VisualBasic and GL matrices



Punchey
12-02-2000, 08:13 PM
Does anyone know why the following VB code doesn't work?

Dim modelview(16) as GLfloat

glGetFloatv glgModelViewMatrix, modelview

It says it's a "ByRef argument type mismatch". Am I defining the matrices incorrectly? How do you pass the matrix to a GL function? Anyway, thanks in advance!

Bob
12-03-2000, 06:04 AM
I'm no BASIC-guru, in fact, last time I ever touched BASIC was like 7+ years ago or so, so I'm just guessing, and got no tip how to solve it (let's say it's an exercise for the reader http://www.opengl.org/discussion_boards/ubb/rolleyes.gif )

The second parameter takes a pointer to an array as argument. Maybe you simply pass the value of the first element or so. Could be that that causes the compiler to complain about type mismatch (wants a pointer but gets a value). But as I said, i don't know.

Deiussum
12-03-2000, 06:28 AM
Try calling it like so..

glGetFloatv glgModelViewMatrix, ByVal(modelview)

It might be that it needs to be called like this...

glGetFloatv glgModelViewMatrix, ByRef(modelview)

I think the first one is the correct one, though. It seems to me that whenever using strings in API functions that return a value, you need to use ByVal. (Yeah, that's backwards of what you'd think it would be, but VB is kind of weird that way.) http://www.opengl.org/discussion_boards/ubb/smile.gif

Punchey
12-04-2000, 07:43 AM
That is strange because the "original" C++ implementation of the function uses a pointer to the first element of the array. (obviously) And it seems as though that would be REALLY stupid to pass a full 16-element array of 32bits every time! How inefficient! Anyway, I'll give it a try and let you know if it worked. Thanks!

Punchey
12-04-2000, 07:45 AM
Oh, one more thing, usually, when filling out the arguments to a function, VB shows you the little pop-up thing that shows the names and types of the arguments. Usually, when an array is needed, I thought VB showed something like this:
array() as Single
But in this case, it shows:
params as Single
I would have expected it to show params() instead since I would expect an array...

Deiussum
12-04-2000, 08:43 AM
Originally posted by Punchey:
That is strange because the "original" C++ implementation of the function uses a pointer to the first element of the array. (obviously) And it seems as though that would be REALLY stupid to pass a full 16-element array of 32bits every time! How inefficient! Anyway, I'll give it a try and let you know if it worked. Thanks!

The way I interpret the use of ByVal with arrays is that it is passing a "value" of the address of the first element of the array. (So basically, a pointer to the array)

Anyway, it's worth a try.

Punchey
12-04-2000, 01:46 PM
Well, it didn't work. I first used ByVal(modelview) and it didn't work. Although instead of saying: "ByRef type mismatch" it just said "type mismatch". Since it says "ByRef" I'd imagine it's trying to pass the thing by reference. But since it says "type mismatch" in both cases, I'm at a loss as to what do. And since it usually indicates arrays in the function prototype thingie with a set of () after the name of the array, it looks as if the function is not asking for an array. Which doesn't make any sense because the function is ALL about arrays! It's starting to look to me like this is an incomplete OpenGL implementation. Does else anyone out there have experience in using matrices with OpenGL in VB?

Deiussum
12-05-2000, 04:03 AM
What are you using to do OpenGL in VB? Is it a type-library or are you importing the functions from the OpenGL DLL yourself? I can probably take a closer look at it for you as soon as I get the time. I've never really tried to do OpenGL in VB before.

Punchey
12-05-2000, 05:27 AM
Well, I'm a bit embarassed to say this, but I think it's whatever comes with the Microsoft Platform SDK. I'll have to check to be more specific.

Deiussum
12-07-2000, 07:06 AM
I finally got around to getting a TypeLibrary for using OpenGL in VB and tried it out. I got it to compile with just passing in the first element of the array for the last parameter like so...

glGetFloatv(GL_MODELVIEW_MATRIX, MatrixVals(0))

I didn't setup a full OpenGL program and test if this actually returns the values correctly, but I would assume it does.

Punchey
12-07-2000, 09:07 AM
Cool! Thanks alot, man! I would never have thought of that since I'm a C++ minded kinda guy.

Deiussum
12-07-2000, 10:26 AM
Same here. I saw something in the documentation for the type-library that said that for passing arrays, you should pass the first element of the array like that. http://www.opengl.org/discussion_boards/ubb/smile.gif

Punchey
12-07-2000, 07:05 PM
I'm here to tell you, VisualBasic is one screwed up backwards language in many ways. Still, it's good for some things.