×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Mar 2007
    Posts
    235

    Question Need Help with Texturing

    I tried creating my own texture using the following codes . Problem is
    the emulator is exiting abruptly without any panic code . I am new in OpenGles . Please Help .

    Code:
    static const GLbyte vertices[4 * 3] = //row major 
    	{
    	-1, 0, 0,
    	1, 0, 0,
    	-1, 2, 0,
    	1, 2, 0
    	};
    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)
    	};
    
    /* Define normals for the cube */
    static const GLbyte normals[4 * 3] =
    {
        /* top */
        0,0,1,
        /* right */
        0,1,0,
        /* left */
        0,-1,0,
        /* back */
        -1,0,0,
      
    };
    #define LIGHT_MAX    (1 << 16)
    #define LIGHTCOLOR(r, g, b, a)       \
           (GLfixed)(r * LIGHT_MAX),     \
           (GLfixed)(g * LIGHT_MAX),     \
           (GLfixed)(b * LIGHT_MAX),     \
           (GLfixed)(a * LIGHT_MAX)
    /* Define global ambient light. */
    static const GLfixed globalAmbient[4]      = { LIGHTCOLOR(0.0, 0.0, 0.0, 1.0) };
    
    /* Define lamp parameters. */
    static const GLfixed lightDiffuseLamp[4]   = { LIGHTCOLOR(1.0, 1.0, 1.0, 1.0) };
    static const GLfixed lightAmbientLamp[4]   = { LIGHTCOLOR(0.3, 0.3, 0.3, 1.0) };
    static const GLfixed lightSpecularLamp[4]  = { LIGHTCOLOR(0.5, 0.5, 0.5, 1.0) };
    static const GLfixed lightPositionLamp[4]  = { 0, 0, 10, 0 };
    Code:
    GLuint CMobileEMailContainer::BindTextures(const TRect& aRect,TBool aWrap) const
    {
    GLuint texture;	
    TRAPD(err,	
    	// allocate a texture name
    	glGenTextures( 2, &texture );
    //	glBindTexture( GL_TEXTURE_2D,texture );//in here to test texture
    	
    	 /* Enable back face culling, texturing, and normalization. */   
        glEnable( GL_TEXTURE_2D );
        glEnable( GL_NORMALIZE  );    
    	 /***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 );	
    	glEnableClientState( GL_NORMAL_ARRAY);
    	// 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, iImageEngine->TextureData());
    	/**************Texture environment parameters are set using glTexEnvf().*/
    	glTexEnvx( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
    	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    	// 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 );
        
    	)
    	Panic(err);	
    	return texture;
    }
    
    void CMobileEMailContainer::SetLight() const
    	{
    	/* Set up global ambient light. */
        glLightModelxv( GL_LIGHT_MODEL_AMBIENT, globalAmbient );
    
        /* Set up lamp. */
        glEnable(   GL_LIGHT0 );
        glLightxv( GL_LIGHT0, GL_DIFFUSE,  lightDiffuseLamp  );
        glLightxv( GL_LIGHT0, GL_AMBIENT,  lightAmbientLamp  );
        glLightxv( GL_LIGHT0, GL_SPECULAR, lightSpecularLamp );
        glLightxv( GL_LIGHT0, GL_POSITION, lightPositionLamp );
        
        /* Set shading mode*/
    	glShadeModel( GL_FLAT );
       
    	}
    // ---------------------------------------------------------
    // CMobileEMailContainer::Draw(const TRect& aRect) const
    // ---------------------------------------------------------
    //
    
    void CMobileEMailContainer::GenSkin(const TRect& aRect) const
    {
    TRAPD(err,
    //	CFbsBitmap* TextureBitmap= new (ELeave)CFbsBitmap;
    	TBool wrap=ETrue;	
    	
    	glBindTexture( GL_TEXTURE_2D, BindTextures(aRect,wrap) );
    //	BindTextures(aRect,wrap,*TextureBitmap);//while bind texture is in Bindtextures 
    //	 
    	/* Enable vertex array */
    //	glMatrixMode( GL_MODELVIEW );
    	glEnableClientState( GL_VERTEX_ARRAY );		
    	glLoadIdentity();
    	SetLight();
    	glClear( GL_COLOR_BUFFER_BIT );
    	)
    	Panic(err);	
    
    	glTexCoordPointer( 2, GL_BYTE, 0, nokTexCoords );
    	glNormalPointer( GL_BYTE, 0, normals );
    	glVertexPointer( 2, /*GL_SHORT*/GL_BYTE, 0, skinvertices );
    	glDrawElements( GL_TRIANGLES, 2* 3, GL_UNSIGNED_BYTE, triangles );
    //	glDeleteTextures(2, &texture);
    }

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,567

    Re: Need Help with Texturing

    You can still check the end of the logfile (http://wiki.forum.nokia.com/index.php/Epocwind.out)

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

    Exclamation Re: Need Help with Texturing

    GLuint texture;
    glGenTextures( 2, &texture );

    Wrong size. You have buffer overflow here.
    Should be either GLuint texture[2] or glGenTextures(1, &texture );

    Advice - if you are new to OpenGL start with simple OpenGL example from textbook and work you way from it to more complex. Copy-pasting complex code without understanding what does it do is risky - you may have a lot of problem with debugging.

Similar Threads

  1. Need help with texturing in OpenGLES
    By sudeepa2005 in forum Symbian C++
    Replies: 3
    Last Post: 2008-12-17, 05:26
  2. problems with texturing - OpenGL ES on Symbian
    By miranda2112 in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2005-04-05, 11:20

Posting Permissions

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