Search code examples
c#openglesri

glBindTexture invalid value possibly due to glLineWidth


In C#, inside the OpenGL context of Esri ArcMap dynamic display (immediate mode), I try to create textures:

GL.glEnable(GL.GL_TEXTURE_2D);
uint[] textures = new uint[1];
GL.glBindTexture(1, textures[0]);
uint error = GL.glGetError();

The value of error is 1281 (invalid value).

I've checked - it's not in between glBegin/glEnd calls, and the context is valid. I also used GLIntercept to check the calls and errors, but it seems to give me false negatives (I compare the full call list to the errors and the errors just doesn't match - only things like glEnd called before glBegin while the full function lists shows nothing like that ever happened).

I suspect it's a driver problem. I run an ATI Radeon 2400 Pro on a Win7 64 (the app is 32bit). The ESRI version I use is 9.3.1 sp1.

I've Google'd it quite a lot and even looked at http://www.opengl.org/wiki/Common_Mistakes but I can't find anything that resembles my problem.

It doesn't seem to happen in all programs that base on that code, but it happens constantly on some, so I'm really confused about it.

What should I check next?

EDIT:

I started eliminating code that was running before that error (long before, actually) and found that if when drawing a polygon, (a polygon that has nothing to do with that texture and that is drawn using glVertexPointer and glDrawArrays, no texture related at all), I remove the glLineWidth that is found before drawing that polygon, I get no error when binding the texture.

Now I know that's silly, and it makes no sense, and it's either a huge problem in the driver or in my understanding of OpenGL, but I can't figure out which :-)

I was very careful with the elimination and it's really just that line in that specific function:

GL.glDisable(GL.GL_TEXTURE_2D);
GL.glPushMatrix();
GL.glLoadIdentity();

GL.glLineWidth(someWidthParameter); // <-- The only line I comment.

GL.glEnableClientState(GL.GL_VERTEX_ARRAY);

GL.glTranslate(...);
GL.glScale(...);

GL.glVertexPointer(...);
GL.glDrawArrays(...)

GL.glDisableClientState(GL.GL_VERTEX_ARRAY);

GL.glPopMatrix();
GL.glEnable(GL.GL_TEXTURE_2D);

So now I'm even more confused than before... Any ideas?


Solution

  • Found the problem:

    Apparently, one of the values passed to the glLineWidth was zero, which is not allowed. The first glGetError I used was after setting that value to zero was at the bind texture, so I thought it was related to that.

    I'm ashamed it took me that long to figure that out :-)

    And I certainly need better OpenGL debugging tools - apparently GLIntercept could have detect it but didn't, but since it was the only usable tool for me it had to do.

    Sorry I had to bother you all and thank you for your help.