Texture don't seem to work

Hi, I am trying to port an application from gl4java to jogl and I am having a probelm with getting textures to work.

I had read somewhere (I don’t remember where) that texture at one point wern’t working in jogl. However I note from the recent postings that they seem to be working.

I have tried the hwShadowmapsSimple demo but that dosen’t do anything after opening up the frame and I have to kill it to get it to go away.

My test code looks like:

Inside init:
int[] terrainTextureId = new int[1];
gl.glGenTextures(1, terrainTextureId);
gl.glEnable(GL_TEXTURE_2D);
gl.glBindTexture(GL_TEXTURE_2D, terrainTextureId[0]);
gl.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
gl.glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);

where image is a byte array filled with one color.

Inside display I bind it and display it but the texture dosen’t show. Now this is code which works perfectly in gl4java so I feel sure that it’s procedurally correct.

Is there something that I’m missing?

Thanks.

Hi,

make sure that you load your textures with the same thread, which executes the display() method. You should check the texture ID generated by glGenTexture. If it is 0, this is an indecator, that you use the wrong thread to load your texture.

ciao torsten

Have you enabled textures?

OK. I found the problem. Actually the code I listed above was what I was trying after the original code that used a pbuffer didn’t work.

I went back to the pbuffer code which was modelled after the hwShadowmapsSimple example and found that a call to set the doublebuffering off of the pffer created from the drawable was causing textures not to work.

When I re-tried the most basic texture stuff it worked now. Why does this always seem to happen.

Thanks all.

[quote]Hi,

make sure that you load your textures with the same thread, which executes the display() method. You should check the texture ID generated by glGenTexture. If it is 0, this is an indecator, that you use the wrong thread to load your texture.

ciao torsten
[/quote]
That’s really a good point!
This happened to me and it took a while to solve it…