Hi all, I am trying to load a texture my screen using Open GLES and here are my codes . Well , it is crashing ,I may be getting my graphics code wrong .Any sujjestions ?
Code :_LIT(KTextureBitmap,"z:\\system\\apps\\Mobile\\Mobile.mbm"); /* Macro for changing the input texture coordinate values from GLubyte [0,255] to GLbyte [-128,127]. See more info below. */ #define tex(u,v) (GLbyte)( (u) - 128 ) , (GLbyte)( (v) - 128 ) static const GLbyte skinvertices[4 *2] = { /* top */ -1, -1, 1, -1 , 1, 1, -1, 1 }; /* Define indices for drawing the triangles. The color of the square * is determined by the color of the last vertex of the square.*/ static const GLubyte triangles[2* 3] = { /* up */ 0,1,2, /*down*/ 1,2,3 }; static const GLbyte nokTexCoords[4 * 2] = { /**** */ tex(0,0), tex(255,0), tex(255,255), tex(0,255) };Code :GLuint CMobileContainer::BindTextures(const TRect& aRect,TBool aWrap,CFbsBitmap& aTextureBitmap) const { GLuint texture; // allocate a texture name glGenTextures( 2, &texture ); // select our current texture // glBindTexture( GL_TEXTURE_2D, texture ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, aRect.Width(), aRect.Height(), 0, GL_RGB, GL_UNSIGNED_BYTE, aTextureBitmap.DataAddress() ); /**************Texture environment parameters are set using glTexEnvf().*/ glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ); // if wrap is true, the texture wraps over at the edges (repeat) // ... false, the texture ends at the edges (clamp) glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,aWrap ? GL_REPEAT : GL_CLAMP_TO_EDGE ); return texture; }Code :void CMobileContainer::GenSkin(const TRect& aRect) const { CFbsBitmap* TextureBitmap= new (ELeave)CFbsBitmap; TBool wrap=EFalse; TextureBitmap->Load(KTextureBitmap,0,ETrue); /***Enable Texturing*/ glEnable( GL_TEXTURE_2D ); /***an appropriate texture matrix has to be initialized*/ glMatrixMode( GL_TEXTURE ); glLoadIdentity(); glScalef( 1.f / 255.f, 1.f / 255.f, 1.f ); glTranslatef( 128.f, 128.f, 0.f ); glMatrixMode( GL_MODELVIEW ); /********texture coordinate array should then be enabled and * the texture coordinate pointer set****/ glEnableClientState( GL_TEXTURE_COORD_ARRAY ); glBindTexture( GL_TEXTURE_2D, BindTextures(aRect,wrap,*TextureBitmap) ); glVertexPointer( 3, GL_SHORT, 0, skinvertices ); glTexCoordPointer( 2, GL_BYTE, 0, nokTexCoords ); glDrawElements( GL_TRIANGLES, 10 * 3, GL_UNSIGNED_BYTE, triangles ); }
Code :void CMobileContainer::Draw(const TRect& aRect) const { /**************************Set the correct step of OpenGl renderer*/ /* Set the screen background color to black */ glClearColor( 0.f, 0.f, 0.f, 1.f ); /* Initialize viewport */ glViewport( 0, 0, aRect.Width(), aRect.Height()); //**************draw the object to made it translucent /* Set the projection matrix */ glMatrixMode( GL_PROJECTION ); glFrustumf( -1.f, 1.f, -1.f, 1.f, 3.f, 1000.f ); TRAPD(err,GenSkin(aRect);) if(err!=KErrNone) User::Panic(_L("Panic due to"),err); // GenSelector(aRect); /* Call eglSwapBuffers, which blit the graphics to the window */ eglSwapBuffers( iEglDisplay, iEglSurface ); }



.