×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    110

    Unhappy Need help with skinning

    I am into my first sample game programming and my code suddenly exits . I am a total newbie regarding this and have started after downloading "Series 60 Developer Platform: Introduction To 3-D Graphics In C++" . I am writing the codes given therein into one sample container .
    Code:
    #include "MobileContainer.h"
    #include <fbs.h>
    #include <eiklabel.h>  // for example label control
    
    _LIT(KTextureBitmap,"z:\\system\\apps\\MobileMail\\MobileMail.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 )
    // ================= MEMBER FUNCTIONS =======================
    /* Define vertice coordinates for the cube containing square*/
    static const GLbyte vertices[4 * 3] = //row major 
    	{
    	-1, 0, 0,
    	1, 0, 0,
    	-1, 2, 0,
    	1, 2, 0
    	};
    
    /* 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)
    	};
    // ---------------------------------------------------------
    // CMobileContainer::ConstructL(const TRect& aRect)
    // EPOC two phased constructor
    // ---------------------------------------------------------
    //
    void CMobileContainer::ConstructL(const TRect& /*aRect*/)
    	{
    	CreateWindowL();
    	SetExtentToWholeScreen();                // Take the whole screen into use
    	ActivateL();
    //    iScreenSize=aRect.Size();
    	/* Get the display for drawing graphics */
    	iEglDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY );
    	/* Initialize display */
    	eglInitialize( iEglDisplay, NULL, NULL );
    	
    	EGLConfig config; // config describing properties of EGLSurface
    	EGLConfig *configList = NULL; // pointer for EGLConfigs
    	int configSize = 0; // num of configs we want EGL to
    	// return
    	int numOfConfigs = 0; // num of configs actually returned
    	/* Get the number of all possible EGLConfigs */
    	eglGetConfigs( iEglDisplay, configList, configSize, &numOfConfigs );
    	configSize = numOfConfigs;
    	/* Allocate memory for configList */
    	configList = (EGLConfig*)User::Alloc( sizeof(EGLConfig)*configSize );
    	/* Define properties for the wanted EGLSurface.
    	To get the best possible performance, choose
    	an EGLConfig with a buffer size matching
    	the current window's display mode*/
    	TDisplayMode DMode = Window().DisplayMode();
    	TInt BufferSize = 0;
    	switch(DMode)
    	{
    	case(EColor4K):
    	BufferSize = 12;
    	break;
    	case(EColor64K):
    	BufferSize = 16;
    	break;
    	case(EColor16M):
    	BufferSize = 24;
    	break;
    	case(EColor16MU):
    	BufferSize = 32;
    	break;
    	default:
    	_LIT(KDModeError, "unsupported displaymode");
    	User::Panic( KDModeError, 0 );
    	break;
    	}
    	const EGLint attrib_list[] = { EGL_BUFFER_SIZE,BufferSize,
    	EGL_DEPTH_SIZE,16,
    	EGL_NONE };
    	/* Choose configs that fulfill the requirement in attrib_list */
    	eglChooseConfig( iEglDisplay, attrib_list, configList, configSize,&numOfConfigs );
    	/* Choose the ‘best’ config and use that in the future */
    	config = configList[0]; // Choose the best EGLConfig. EGLConfigs
    	// returned by eglChooseConfig are sorted so
    	// that the best matching EGLconfig is first in
    	// the list.
    	User::Free( configList ); // free configList, not used anymore
    	/* Create a surface where the graphics are blitted */
    	iEglSurface = eglCreateWindowSurface( iEglDisplay, config, &Window(),NULL );
    	/* Create a rendering context */
    	iEglContext = eglCreateContext( iEglDisplay, config, NULL, NULL );
    	/* Make the context current. Binds to the current rendering thread and surface. Use the same surface for both drawing and reading */
    	eglMakeCurrent( iEglDisplay, iEglSurface, iEglSurface, iEglContext );
    	
    	}
    
    // Destructor
    CMobileContainer::~CMobileContainer()
    	{
    	eglMakeCurrent( iEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE,
    			EGL_NO_CONTEXT );
    	eglDestroySurface( iEglDisplay, iEglSurface );
    	eglDestroyContext( iEglDisplay, iEglContext );
    	eglTerminate( iEglDisplay ); // release resources associated with EGL
    			// & OpenGL ES
    
    	}
    
    // ---------------------------------------------------------
    // CMobileContainer::SizeChanged()
    // Called by framework when the view size is changed
    // ---------------------------------------------------------
    //
    void CMobileContainer::SizeChanged()
    	{
    
    	}
    
    // ---------------------------------------------------------
    // CMobileContainer::CountComponentControls() const
    // ---------------------------------------------------------
    //
    TInt CMobileContainer::CountComponentControls() const
    	{
    	return 0; // return nbr of controls inside this container
    	}
    
    // ---------------------------------------------------------
    // CMobileContainer::ComponentControl(TInt aIndex) const
    // ---------------------------------------------------------
    //
    CCoeControl* CMobileContainer::ComponentControl(TInt /*aIndex*/) const
    	{
    
    	return NULL;
    	}
    
    // ---------------------------------------------------------
    // CMobileContainer::Draw(const TRect& aRect) const
    // ---------------------------------------------------------
    //
    void CMobileContainer::GenSkin(const TRect& /*aRect*/) const
    {
    	GLuint texture;
    	CFbsBitmap* TextureBitmap= new (ELeave)CFbsBitmap;
    	TBool wrap=EFalse;
    	
    	TextureBitmap->Load(KTextureBitmap,0,ETrue);
    	#define TEX_WIDTH 180
    	#define TEX_HEIGHT 240//320    
    	
    	// allocate a texture name
    	glGenTextures( 2, &texture );
    	
    	/***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 );
    	glTexCoordPointer( 2, GL_BYTE, 0, nokTexCoords );
    	//	glGenTextures( 2, iNokTexObjects);
    	// select our current texture
    	glBindTexture( GL_TEXTURE_2D, texture );
    	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, TEX_WIDTH, TEX_HEIGHT,
    			0, GL_RGB, GL_UNSIGNED_BYTE, TextureBitmap->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,wrap ? GL_REPEAT : GL_CLAMP_TO_EDGE );
    	/****************For skinning effect***************/
    	//	glEnable( GL_BLEND );
    	//	glBlendFunc( GL_ONE, GL_ONE );
    	/********************************/
    	glDrawElements( GL_TRIANGLES, 10 * 3, GL_UNSIGNED_BYTE, triangles );
    }
    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) //My code exiting here 
    		User::Panic(_L("Panic due to"),err);
    //	GenSelector(aRect);
    	/* Call eglSwapBuffers, which blit the graphics to the window */
        eglSwapBuffers( iEglDisplay, iEglSurface );
    	}
       
    void CMobileContainer::GenSelector(const TRect& /*aRect*/) const
    	{
    	/************************Codes to make the next object translucent **/
    	//draw the background
    	glEnable(GL_BLEND); //activate blending mode
    	glBlendFunc(GL_SRC_ALPHA/*GL_ONE*/, GL_ONE); //define blending factors
    	glMatrixMode( GL_MODELVIEW );
    	/* Enable vertex array */
    	glEnableClientState( GL_VERTEX_ARRAY );
    	/* Set vertex array pointer */
    	glVertexPointer( 3, GL_BYTE, 0, vertices );
    	/* Set the shading model */
    	glShadeModel( GL_FLAT );
        /*********************draw the actual scene***************/
    	/* Clear the color buffer */
    	glClear( GL_COLOR_BUFFER_BIT );
    	
    	
    	
    	/* Move the camera, MatrixMode == GL_MODELVIEW */
    	glLoadIdentity();
    	glTranslatex(0, 0, -100 << 16 ); //or glTranslatef(0.0, 0.0, -100.0)
    	/* Set current color for the triangle (red) */
    	glColor4f( 1.f, 0.f, 0.f, 0.25f );//RGBA	
    	/* Scale the geometry */
    	glScalex( 15 << 16, 15 << 16, 15 << 16 ); // or glScalef( 15.0, 15.0,
    	// 15.0 )
    //	/* Draw the triangle */
    //	glDrawElements( GL_TRIANGLES, 1* 3, GL_UNSIGNED_BYTE, triangles );
    	
    	/* Draw the square */
    		glDrawElements( GL_TRIANGLES, 2* 3, GL_UNSIGNED_BYTE, triangles );
    		
    	/* Call eglSwapBuffers, which blit the graphics to the window */
    	}
    // ---------------------------------------------------------
    // CMobileContainer::HandleControlEventL(
    //	 CCoeControl* aControl,TCoeEvent aEventType)
    // ---------------------------------------------------------
    //
    void CMobileContainer::HandleControlEventL(
    	CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
    	{
    	// TODO: Add your control event handler code here
    	}

  2. #2
    Super Contributor
    Join Date
    Mar 2004
    Location
    Czech Republic
    Posts
    2,037

    Re: Need help with skinning

    Hi,

    so ar you newbie to C++ or only to Symbian and OpenGL? The example you have selected is probably not a good starting point to get more familiar with Symbian as it expecte the OpenGL knowledge.

    Anyway, what it mean that the program exits? Did you debug the code? On which line it crash? Any error code?

    BR
    STeN

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    110

    Re: Need help with skinning

    Right now I have changed my codes ,so the crash is gone but still no texture .
    Code:
    START BITMAP Mobile.mbm
    	HEADER
    	TARGETPATH \system\apps\Mobile
    	SOURCEPATH ..\gfx
    	SOURCE c24 screen.bmp //pic size 128,340
    	SOURCE c24 screen1.bmp //pic size 128,128
    END
    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;
    	TInt TextureSize=aTextureBitmap.SizeInPixels().iHeight*aTextureBitmap.SizeInPixels().iWidth;
    	// allocate a texture name
    	glGenTextures( 2, &texture );
    	/* The data in the texture are in RGB order but is read in BGR order. 
    	   So we have to swap the 1st and 3rd bytes. */
    	TUint8 * TextureData = (TUint8 *) aTextureBitmap.DataAddress();
    	for ( TInt i = 0; i < TextureSize; i++ )
    		{
    		TUint8 t = TextureData[i*3];
    		TextureData[i*3] = TextureData[i*3+2];
    		TextureData[i*3+2] = t;
    		}	
    	 /* Enable back face culling, texturing, and normalization. */   
        glEnable( GL_TEXTURE_2D );
    	 /***an appropriate texture matrix has to be initialized*/
    	glMatrixMode( GL_TEXTURE );
    	glLoadIdentity();
    	glScalef( 1.f / 128.f, 1.f / 128.f, 1.f );
    	glTranslatef( 128.f, 128.f, 0.f );
    	glMatrixMode( GL_MODELVIEW );
    	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
    	// select our current 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 */GL_DECAL);
    	// 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=ETrue;	
    	TextureBitmap->Load(KTextureBitmap,EMbmMobileScreen1,ETrue);
    	glBindTexture( GL_TEXTURE_2D, BindTextures(aRect,wrap,*TextureBitmap) );
    	/* Enable vertex array */
    	glVertexPointer( 2, /*GL_SHORT*/GL_BYTE, 0, skinvertices );//no of cocordinates per vertex,type,byte offset between consecutive vertexes,first vertex in array
    	glTexCoordPointer( 2, GL_BYTE, 0, nokTexCoords );
    	glShadeModel( GL_FLAT );
       	glClear( GL_COLOR_BUFFER_BIT );
    	glLoadIdentity();
    	glDrawElements( GL_TRIANGLES, 2* 3, GL_UNSIGNED_BYTE, triangles );
    }
    Last edited by sudeepa2005; 2008-12-17 at 09:18.

  4. #4
    Regular Contributor
    Join Date
    Apr 2004
    Posts
    96

    Re: Need help with skinning

    It looks like you havn't specified min and mag filters for texture. For OpenGL ES 1.1 it's mandatory IIRC

Similar Threads

  1. Application Skinning
    By antjan77 in forum Symbian User Interface
    Replies: 3
    Last Post: 2008-06-03, 13:52
  2. CAknSearchField skinning problem
    By parisn in forum Symbian
    Replies: 0
    Last Post: 2008-01-02, 22:27
  3. skinning in landscape mode.
    By ravinder007 in forum Symbian
    Replies: 0
    Last Post: 2007-01-24, 11:01
  4. Skinning in landscape mode.
    By ravinder007 in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2007-01-11, 10:24
  5. Skinning a listbox on N70
    By shandrew in forum Symbian User Interface
    Replies: 2
    Last Post: 2006-07-17, 11:36

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×