Jump to content
  • Advertisement
Sign in to follow this  
tvsct456

Problem with glGenTexture(). Need Help :D

This topic is 2541 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys, I got a problem with the method glGenTexture().
Here is the code:

GLuint sky[5];
glGenTexture(5,&sky);

When I putted these lines in a class's construction function, they didn't work.
The values in the array sky[5] are all 0 after the code above being runed.
But They supposed to be 0,1,2,3,4 as the indexes of textures right ?


Share this post


Link to post
Share on other sites
Advertisement
Isn't it "glGenTexture(5, sky)" instead of "glGenTexture(5, &sky)"?

or you may use glGetError or something similar to see if something wrong happened

Share this post


Link to post
Share on other sites

But They supposed to be 0,1,2,3,4 as the indexes of textures right ?


Actually {1,2,3,4,5}. '0' is undefined/null index.


GLuint sky[5];
glGenTextures(5,&sky);




You have done C++ bug which causes your application to do something wrong. Solve this as excali said.

Share this post


Link to post
Share on other sites

[quote name='50CoL' timestamp='1324524678' post='4896391']
GLuint sky[5];
glGenTexture(5,&sky);




You have done C++ bug which causes your application to do something wrong. Solve this as excali said.
[/quote]
There is nothing wrong with his code. You can get a pointer to the first element of an array either by the name of the array alone like excali did, or by raking the address of the array as in his code. Both are the same.

Share this post


Link to post
Share on other sites
Nope, glGenTextures(5,&sky) is definitely wrong here if "sky" is a GLuint[5]. It should be glGenTextures(5,sky). See http://www.opengl.org/sdk/docs/man/xhtml/glGenTextures.xml - "specifies an array in which the generated texture names are stored", note that it's an array, not the address of an array (which "&sky" would be).

Share this post


Link to post
Share on other sites

[quote name='FXACE' timestamp='1324548775' post='4896462']
[quote name='50CoL' timestamp='1324524678' post='4896391']
GLuint sky[5];
glGenTexture(5,&sky);




You have done C++ bug which causes your application to do something wrong. Solve this as excali said.
[/quote]
There is nothing wrong with his code. You can get a pointer to the first element of an array either by the name of the array alone like excali did, or by raking the address of the array as in his code. Both are the same.
[/quote]

- If it was "glGenTextures(5,&sky[0])". But it wasn't.


Share this post


Link to post
Share on other sites

[quote name='Brother Bob' timestamp='1324549066' post='4896463']
[quote name='FXACE' timestamp='1324548775' post='4896462']
[quote name='50CoL' timestamp='1324524678' post='4896391']
GLuint sky[5];
glGenTexture(5,&sky);




You have done C++ bug which causes your application to do something wrong. Solve this as excali said.
[/quote]
There is nothing wrong with his code. You can get a pointer to the first element of an array either by the name of the array alone like excali did, or by raking the address of the array as in his code. Both are the same.
[/quote]

- If it was "glGenTextures(5,&sky[0])". But it wasn't.
[/quote]
sky, &sky and &sky[0] all give you the same well-defined thing; a pointer to the first element of the array.The actual types of the expressions are different though, but when decomposed into a pointer like we're talking about here, the results are the same pointer.

If sky was a pointer or a scalar type, then they would be different, but sky is an array.

Share this post


Link to post
Share on other sites
sky, &sky and &sky[0] all give you the same well-defined thing; a pointer to the first element of the array.[/quote]

[font="Courier New"]int sky[5] [/font]is an array of 5 elements. [font="Courier New"]sky [/font]or [font="Courier New"]&sky[0][/font] is the address of the first element (equivalent). [font="Courier New"]&sky[/font] is the address-of-address-of-the-first-element. In other words, it is not the same and not what you want.

I'm not sure what exactly the compiler makes of that expression, but it probably creates an extra value on the stack for the address that normally most likely lives in a register, which means glGenTextures will overwrite some random portion of the stack...or something... in any case it does not write the values to the array, except by accident.

Share this post


Link to post
Share on other sites

[quote name='FXACE' timestamp='1324551514' post='4896472']
[quote name='Brother Bob' timestamp='1324549066' post='4896463']
[quote name='FXACE' timestamp='1324548775' post='4896462']
[quote name='50CoL' timestamp='1324524678' post='4896391']
GLuint sky[5];
glGenTexture(5,&sky);




You have done C++ bug which causes your application to do something wrong. Solve this as excali said.
[/quote]
There is nothing wrong with his code. You can get a pointer to the first element of an array either by the name of the array alone like excali did, or by raking the address of the array as in his code. Both are the same.
[/quote]

- If it was "glGenTextures(5,&sky[0])". But it wasn't.
[/quote]
sky, &sky and &sky[0] all give you the same well-defined thing; a pointer to the first element of the array.The actual types of the expressions are different though, but when decomposed into a pointer like we're talking about here, the results are the same pointer.

If sky was a pointer or a scalar type, then they would be different, but sky is an array.
[/quote]

I'm afraid you are right (I have done a test program of code which outputs addresses of different style access to array which we are discussing here).






int sky[5];
printf("sky : %p\n"
"&sky : %p\n"
"&sky[0]:%p\n",
sky,
&sky,
&sky[0]);


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!