PocketMatrix forums

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

OpenGL ES issues

Hey,

I'm writing an EdgeLib based application for a Nokia N97 device.
I have a couple of questions regarding OpenGL and Edge.


1. I've read in one of the posts that due to Texture size limitation, the Fontmap size is limited. What is the that limit in width ? ( using RGBA fontmap )


2. In one point in the application I need to take a snapshot of the display, and use this snapshot as a background for future blt operations.
My problem is that I don't get the same behavior in the PC emulator ( where everything works just fine ) and in the device.

Here is how I perform the snapshot:
I read the pixel data from the display into a buffer, and blt it back to the screen using a surface.

Here is the code I'm using in order to read the pixel data:
Code:


//get the height and width of the display
int nHeight = m_pESSharedData->m_pDisplay->GetHeight();
int nWidth = m_pESSharedData->m_pDisplay->GetWidth();
unsigned char * pPixelData = (unsigned char*)ClassEMemory::Alloc(nHeight*nWidth*3);
if (!pPixelData)
return IERR_NO_MEMORY;
//read the pixel data of the entire display
glPixelStorei(GL_PACK_ALIGNMENT,4);
glPixelStorei(GL_UNPACK_ALIGNMENT,4);
glReadPixels((GLint)0, (GLint)0,
(GLint)nWidth-1, (GLint)nHeight-1,
GL_RGB, GL_UNSIGNED_BYTE, pPixelData);


After reading the pixel data I create a new surface, the size of the display, and manually put the pixel data I've got in the buffer into the surface buffer.
Here is the code I use for this task (still not optimized)
Code:
//init the new snap shot surface
unsigned char * pTmpPixelData = pPixelData;
m_pSnapShotSurface = new E2DSurface();
m_pDisplay->CreateSurface(m_pSnapShotSurface, nWidth, nHeight);
E2DSURFACEINFO lockinfo;
unsigned char* pBufferInfo = NULL;
pBufferInfo = m_pSnapShotSurface->Lock(&lockinfo);
if(pBufferInfo)
{
/*
the pixel data is from the bottom up so we point the pixel target in the surface
to the first pixel of the last row
*/
pBufferInfo+=lockinfo.bufferoffset;
pBufferInfo+= lockinfo.ypitch * (nHeight-1);
int x, y;
//iterate over the pixels and copy each pixel to its target pixel to create the surface
for(y = 0 ; y < nHeight ; y++)
{
for(x = 0 ; x < nWidth ; x++)
{
*((unsigned char *)(pBufferInfo)) = *((unsigned char*)(pTmpPixelData));
*((unsigned char *)(pBufferInfo+1)) = *((unsigned char*)(pTmpPixelData+1));
*((unsigned char *)(pBufferInfo+2)) = *((unsigned char*)(pTmpPixelData+2));
pTmpPixelData += 3;
pBufferInfo += lockinfo.xpitch;
}
//move the target pointer to the previous row and to the first pixel of that row
pBufferInfo -= lockinfo.ypitch + x * lockinfo.xpitch;
}
if(pPixelData)
{
ClassEMemory::DeAlloc(pPixelData);
}
m_pSnapShotSurface->Unlock();
m_pDisplay->SetShading(E3D_TEXTURE);
m_pDisplay->UploadTexture(m_pSnapShotSurface);
}


Well... this works just fine under the PC emulator, but on the device I get a black screen with some dirty pixels at the bottom.

What am I doing wrong ?

Is there a different, more efficient way to do draw back the pixel data?
OpenGLES and OpenGL are slightly different. While the former is based on the latter they don't share all functionality. The OpenGLES version of glReadPixels mandates GL_RGBA format and an implementation specific format which can be obtained through glGetInteger with argument GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES. Nothing else.

From your description it looks like glReadPixels failed (GL_RGB not supported -> undefined buffer content, just check glGetError response). I can't say off the top of my head what the usual implementation response to the extra format is. I suggest you find out or stick with GL_RGBA.

See also http://www.khronos.org/opengles/documentation/opengles1_0/html/glReadPixels.html

Also, why do you decrement width and height by 1 for reading? You don't specify a coordinate but dimensions, unless you have a specific reason to do so :)
kuroneko wrote:OpenGLES and OpenGL are slightly different. While the former is based on the latter they don't share all functionality. The OpenGLES version of glReadPixels mandates GL_RGBA format and an implementation specific format which can be obtained through glGetInteger with argument GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES. Nothing else.

From your description it looks like glReadPixels failed (GL_RGB not supported -> undefined buffer content, just check glGetError response). I can't say off the top of my head what the usual implementation response to the extra format is. I suggest you find out or stick with GL_RGBA.

See also http://www.khronos.org/opengles/documentation/opengles1_0/html/glReadPixels.html

Also, why do you decrement width and height by 1 for reading? You don't specify a coordinate but dimensions, unless you have a specific reason to do so :)


Thank you, Thank you, Thank you! :)

Now the only question left is my first question.
What is the max width for a custom font map image ?
Is there a way to deal with this issue other than breaking a large font map into bits and pieces and drawing the text, letter by letter.

kuroneko - 10x again :)
Hi Pinhassi,

You can query the maximum texture size on your device using:

Code:

int maxsize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxsize;);


The maximum size will probably be 512 pixels (or 256 pixels if you're unlucky). For fonts I recommend using images with multiple rows, in EDGELIB call SetFontSheetLayout (with the amount of rows) before calling BuildFont.