-1

I am trying to get the EnvironmentMap using the function

bool SILVERLINING_API GetEnvironmentMap(void *&texture, int facesToRender = 6);

I am working with OpenSceneGraph which is a API over OpenGL. The function description says:

\param texture A pointer to the platform-specific texture handle containing the cube map. On OpenGL this is a GLuint; on DirectX9 it is a LPDIRECT3DCUBETEXTURE9; on DirectX10 it is a ID3D10ShaderResourceView *; on DirectX11 it is a ID3D11ShaderResourceView *.

So I am trying code like this:

GLuint id;
silverLining->atmosphere()->GetEnvironmentMap(id);

And I am getting the error: "cannot convert parameter 1 from 'GLuint' to 'void *&'" The same is with

GLuint *id;
silverLining->atmosphere()->GetEnvironmentMap(id);

So I suppose as I am doing it along with the description and it doesn't work, maybe there is some special way to handle parameters like "void*&"?

Any word of advice on which direction I should be looking?

Theresa
  • 3,515
  • 10
  • 42
  • 47
Stranger1399
  • 81
  • 2
  • 12

1 Answers1

0

C++ is strongly typed language, so you the types have to match. In the first try your supplying object of type GLuint to a fucntion that takes void*. In second example your supplying pointer to GLuint to the same function.

The only way to make this work is to supply GetEnvironmentMap function with something of Type void* (or something that may be implicitly cast to it).

EDIT: If you're using OpenGL, GetEnvironmentMap function will gladly accept pointer to GLuint as first parameter, but it has to be casted (to void*) and it has to be valid. The code that might help you is

GLuint myEnvironmentMapTex;
silverLining->atmosphere()->GetEnvironmentMap((void*)&myEnvironmentMapTex);

Void* is a pointer that points to some memory that no-one knows what holds (it looses any type information - 'void==no type'). Read more here: pointer to void

Community
  • 1
  • 1
Kissiel
  • 1,925
  • 1
  • 13
  • 11
  • Could you tell me what is this "void *" ? As i understood it's early thing that are now sort of overloaded by templates, no? How would I make the object of type void *? – Stranger1399 Dec 11 '13 at 22:16
  • @user3092979: You do not make an object of type `void`, that is precisely the point. The second you use a `void` pointer, you lose all information about what ***type of thing*** it points to. It is just an address in the purest sense of the word. You will eventually have to cast it to something else to make the address useful in most contexts, but passing a `void *` is a way of writing a function that can accept a pointer to anything. You are basically saying you do not care what it points to, you just want an address and you will figure out what it means later on. – Andon M. Coleman Dec 12 '13 at 00:13
  • Thanks a lot.Found a solution, as follows: `GLuint myEnvironmentMapTex; void * ptr = &myEnvironmentMapTex; silverLining->atmosphere()->GetEnvironmentMap(ptr);` Looks pretty much the same as the answer given but this doesnt work. `silverLining->atmosphere()->GetEnvironmentMap((void*)&myEnvironmentMapTex);` I wonder what is the difference? – Stranger1399 Dec 23 '13 at 19:27