PocketMatrix forums

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

Bad textures in gles..

RapchikProgrammer · 09 Jan 2010, 13:29 UTC
Hey, i am using edgelib for my game and have coded the 3d part of the game myself but managing textures using edgelib with upload and bind commands.. now the problem im facing is that the textures look perfect under windows but on device the textures are really messed up.. here are the screenshots:

under windows:
Image

on n95 8gb (GLES):
Image

it looks to be a problem with projection but im not sure what im doing wrong.. i am changing my projection matrix each frame using this code:

Code:
glMatrixMode( GL_PROJECTION );

glLoadIdentity();
GLfloat aspectRatio = (GLfloat)(Ecd->dsp->GetWidth()) / (GLfloat)(Ecd->dsp->GetHeight());
#ifdef EGL_USEGLES
glFrustumf( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio, FRUSTUM_BOTTOM, FRUSTUM_TOP, FRUSTUM_NEAR, FRUSTUM_FAR );
#else
glFrustum( FRUSTUM_LEFT * aspectRatio, FRUSTUM_RIGHT * aspectRatio, FRUSTUM_BOTTOM, FRUSTUM_TOP, FRUSTUM_NEAR, FRUSTUM_FAR );
#endif


and i call this after a call to perspective3d.. btw i am using a 256x256 texture which is tiled across the surface, but that shouldnt matter i think.. i have tried increasing the tiling but the problem still persists of the messed up texture.. any help would be appreciated..
Hi,

The perspective shouldn't have influence on texture coordinates. Can you tell me if you're rendering your models manually or through an E3DSurface object?

The first thing I notice is that the first render uses linear interpolation when rendering the texture, while the second uses nearest neighbor interpolation. Is that intentional? If not, make sure the min and mag filters are set up properly for that texture.
RapchikProgrammer · 12 Jan 2010, 03:06 UTC
Im rendering manually.. i am using shorts for vertices and texture coordinates.. i am then scaling the texture matrix by 1/32767 for the light map and XTiling/32767 and YTiling/32767 for the mesh texture to tile the texture.. i am using linear for min and mag filter.. you can see the difference between nearest and linear:

Linear:
Image

Image

Nearest:
Image

Image
Hi,

Alright, to solve your problem use different texture coordinates for OpenGL ES. It uses fixed point in 16:16 format which means you need to multiply each texture coordinate by 65536 (or shift 16 bits to the left). Pass GL_FIXED as the second parameter to glTexCoordPointer.
RapchikProgrammer · 17 Jan 2010, 05:26 UTC
Hey, now a few questions.. firstly i fail to understand why this should help.. the only thing that this improves is the precision of the texture coordinates, and i have the same precision using shorts because i assign textures in -32767 and 32767 and translate and scale the matrix to get the same precision.. and just so you know it didnt help, even using floating point texture coords didnt help..

now another question, i have my own routines to render the code but nothing very fancy.. now the thing is, as far as i was using shorts for texture coords i could use vbo's on my n95 just fine.. but as soon as i use 4 byte data types, fixed/float my vbo overflows.. i have to render manually without vbos due to that, any clue why this might be happening? i thought when the space on the gpu fills up it pages the data on to ram..

any help would be appreciated, thanks..
Hi,

Can you tell me exactly how the VBO overflows? Perhaps it's doing calculations which doesn't fit inside a 4-byte int (for example, multiplying high values).

I hope you can show me how you're transforming the texture coordinates. As far as I know those can only range from 0 to 1 (with the exception being fixed point for OpenGL ES)?
RapchikProgrammer · 23 Jan 2010, 08:53 UTC
when i debug, my app crashes after it binds the buffer.. i am assuming my buffers must be overflowing..

and i transform the texture coordinates using this code:

Code:
glMatrixMode(GL_TEXTURE);

glLoadIdentity( );
glScalef(1.0f/65535.0f, 1.0f/65535.0f, 1.0f);
glTranslatef(32767.0f,32767.0f,0);


and am using signed shorts.. so it scales 32767 to the right making the values b/w 0-65535 and then divide it with 65535 to make it between 0-1.. and when i am using floats i am not scaling the texture matrix.. and all the remaining texture code is edgelibs that is:

create surface
upload surface
bind surface

and i create with this code:

Code:
if (Ecd->dsp->CreateSurface(&texSurf;, texName, EST_READONLYPATH) == E_OK)
{
Ecd->dsp->UploadTexture(&texSurf;);

glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
}
Hi,

Perhaps it's a better idea to start with something simple, and see where the problem comes from.

For example, start by rendering a textured cube (using your custom code). Then modify the texture matrix and finally set your own projection. This is the only way to find out where exactly it goes wrong.