PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Textures in OpenGL ES

This is something of a follow-up to the thread on E2DSurfaces. I'm using OpenGL ES instead of Edgelib's internal renderer and I find that my texture loading code does not work correctly anymore.

For instance, the code below shades only some faces of the cube and even then, only partially.

Code:

E2DSURFACEINFO lockinfo;
unsigned char *bufptr;
bufptr = texture.Lock(&lockinfo);
if (bufptr)
{
int x, y;
bufptr += lockinfo.bufferoffset;
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
{
if (lockinfo.pixelformat == EDSP_INDEXED8)
*bufptr = 255;
else if (lockinfo.pixelformat == EDSP_TRUE12 || lockinfo.pixelformat == EDSP_TRUE16)
*((unsigned short *)(bufptr)) = 255;
else if (lockinfo.pixelformat == EDSP_TRUE32)
*((unsigned long *)(bufptr)) = 255;
bufptr += lockinfo.xpitch;
}
bufptr += lockinfo.ypitch - texture.GetWidth() * lockinfo.xpitch;
}
texture.Unlock();
}


However, when I use the code to directly load a texture from a file, the textures are mapped perfectly. I'm using an N95 and the Symbian OpenGL ES examples work perfectly. What could be the difference between the edge renderer texture format and that of OpenGL ES?

Another thing that I noticed was that while using the Edgelib renderer, I was able to lock the texture, change its contents and the cube would show those chanegs. When I switched to OpenGL ES however, I'm not able to change the texture after the 1st binding.

Any help would be greatly appreciated :)

Cheers!
CountZero wrote:Another thing that I noticed was that while using the Edgelib renderer, I was able to lock the texture, change its contents and the cube would show those chanegs. When I switched to OpenGL ES however, I'm not able to change the texture after the 1st binding.


IIRC, you'd have to rebind the texture after you changed it. Usually, when you use h/w for rendering, binding a texture means copying the data from the client buffer to some server location (i.e. graphics memory). Changing your buffer content doesn't affect the server side.

HTH
Hi Countzero,

Kuroneko is correct, you need to re-upload the texture after it is changed. Also, you need to set the cleardata parameter to false when using UploadTexture().

I'm afraid it will have a negative impact on performance, because the uploading takes some time. While uploading, the texture is converted to an optimized layout which is one of the reasons texture uploading is slow.
Thanks, that fixed the problem but hit the framerates signficantly. What causes the overhead in the UploadTexure method? Is it just a wrapper for glTexImage2d() ?

Cheers!
Hi Countzero,

Yes, the overhead is caused by glTexImage2D, because it needs to re-arrange the pixel layout (for render optimization purposes).

The speed of texture uploading can also differ between OpenGL (ES) implementations.
fuzzychicken · 14 Sep 2007, 03:16 UTC — OpenGLES texture disappears
Hi all,

I am also trying to use Opengles (glGenTextures & glTexImage2D) just to load and render my own texture on N95. It works fine just a first few seconds. After that, when the small Edgelib introduction window (at the bottom) disappears, my texture disappears at the same time, and there is nothing more on the screen.

Another problem is that the edgelib characters change to blocks on screen, with their texture updated to my own texture.

I don't know how to make Opengles work with Edgelib properly. What could be the problems?

Thank you in advance.
Hi,

Can you tell me if you're binding the texture before rendering?
fuzzychicken · 14 Sep 2007, 14:08 UTC
Thank you very much for the reply.

I've found the problem of disappearing already. It happens if I enable this code on OnDisplayInit():

Code:

#if defined(EGL_USEGL)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
#endif


So I have to temporarily comment this code for now.

However, the font is still wrong.

Yes, I did bind the texture before rendering. That's how I can see my texture on the screen.
Hi,

I think the initial problem is caused by the blending option. The OpenGL renderer sees your texture as 100% transparent and doesn't render it.

I recommend turning the blending option on before rendering the font, and turning it off when rendering your own models.