41
glGenTextures(1, &textureid);

Assuming that the texture was created succesfully, could textureid be 0?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Tal Pressman
  • 7,199
  • 2
  • 30
  • 33

4 Answers4

38

The manual page for glGenTextures says see also glIsTexture; the latter will (according to that) always return GL_FALSE for a texture name of 0. So, 0 can't be a valid texture name.

bw1024
  • 1,138
  • 12
  • 15
Chris Boyle
  • 11,423
  • 7
  • 48
  • 63
  • 8
    The last sentence is incorrect, you will never _generate_ name **0**, but it is a very real name in OpenGL. It has a rather unique property in that texture **0** is every type of texture target all at once! To put this another way, there is a texture with name **0** for `GL_TEXTURE_2D`, there is another texture with name **0** for `GL_TEXTURE_3D`. **0** references a different texture depending on where you bind it and may not have valid state setup, but is always a valid name -- just not one that will ever be generated by calling `glGenTextures (...)` – Andon M. Coleman Oct 06 '16 at 21:10
12

From the OpenGL Spec 3.1: on page 157:

If a texture object is deleted, it as if all texture units which are bound to that texture object are rebound to texture object zero.

It seems to me that the zero named texture is a special one

Christoph
  • 794
  • 1
  • 7
  • 19
2

The correct way to do error checking in OpenGL is generally to call glGetError. You can then check for both of the error conditions listed in the description of glGenTextures. As also mentioned, you can call glIsTexture to check if a given texture is valid.

Eric
  • 6,364
  • 1
  • 32
  • 49
  • I know, but I'm stuck debugging code on an embedded device where it takes around an hour to build and burn the ROM, so anything I can figure out without having to actually change the code and run it is good. :) – Tal Pressman Jul 10 '09 at 09:39
  • You may do better looking at the new stuff in GL_KHR_Debug rather than glGetError. If you have support for it anyway. [Tutorial here](http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-ARB_debug_output.pdf) – David C. Bishop Aug 16 '12 at 08:33
1

Absolutely not.

Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200