Problem with glGenTexture(). Need Help :D

Started by
13 comments, last by tvsct456 12 years, 3 months ago
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 ?


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
Make sure that you have an active rendering context before calling any OpenGL functions.

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.

[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.
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).

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.


[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 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.
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.

[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]);


This topic is closed to new replies.

Advertisement