×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Oct 2004
    Posts
    52

    problems with texturing - OpenGL ES on Symbian

    Hi,
    I'm not sure how many of you out there can help me with this, but I have my fingers crossed!

    I am trying to texture a simple plane using OpenGL ES for Symbian. I have been trying to replicate the "texture" example provided with the SDK, and as far as I can see I have integrated this exactly (although I could obviously be wrong, as it isn't working!!!). I have placed the image in all the correct folders, but it just won't show up!

    The plane shows up ok, but it doesn't have a texture on it.

    I can't really post all the code because there is a lot of it, so I'll just post some snippets from my main file.

    My texture is called "grass.jpg" and is 256 * 256.

    Code:
    // INCLUDE FILES
    #include <e32std.h>
    #include <e32math.h>
    #include "game01.h"
    
    
    GLbyte nokTexCoords[4 * 2] = 
    {
        255,255,
        255,0,
        0,0,
        0,255
    };
    
    CGame01* CGame01::NewL( TUint aWidth, TUint aHeight )
        {
    
        CGame01* self = new (ELeave) CGame01( aWidth, aHeight );
        CleanupStack::PushL( self );
        self->ConstructL();
        CleanupStack::Pop();
    
        return self;
        }
    
    CGame01::CGame01( TUint aWidth, TUint aHeight ) : iScreenWidth( aWidth ),iScreenHeight( aHeight )
        {
        }
    
    
    CGame01::~CGame01()
        {
        }
    
    void CGame01::ConstructL( void )
        {
        }
    
    void CGame01::ToggleLighting( void )
        {
    
        }
    
    void setLighting (void) {
    
    	//lighting code
    
    }
    
    
    void CGame01::AppInit( TUint8 *tex1 )
    {	
    	const GLvoid *texPtr = tex1;
    
        	// Set the screen background color. 
        	glClearColorx( 0<<16, 0<<16, 0<<16, 1<<16 );
    
        	//glEnable( GL_CULL_FACE  );
        	glEnable( GL_TEXTURE_2D );
        	glEnable( GL_NORMALIZE  );
    	glEnable( GL_DEPTH_TEST );
    
    	glEnableClientState( GL_VERTEX_ARRAY );
    	glEnableClientState( GL_TEXTURE_COORD_ARRAY );
    	glEnableClientState( GL_NORMAL_ARRAY );
    
    	glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
    
    	glViewport( 0, 0, iScreenWidth, iScreenHeight );
    
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	glFrustumf( -2.f, 2.f, -2.f, 2.f, 3.f, 1000.f );
    
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    
    	setLighting();
    	iLightingMode = 1;
    
    	glShadeModel( GL_SMOOTH );
    
    	glGenTextures( 1, iNokTexObjects );
    
        glBindTexture( GL_TEXTURE_2D, iNokTexObjects[0] );
        glTexImage2D(  GL_TEXTURE_2D, 0, GL_RGB, TEX_WIDTH, TEX_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, texPtr );
        glTexEnvx( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );	
    	
    }
    
    void CGame01::AppExit( void )
        {
    	glDeleteTextures( 1, iNokTexObjects );
        }
    
    void drawGround(void) {
    
    	GLbyte groundVerts[4 * 3] =
    		{
    			40,   -2,  -40,  
    			-40,  -2,  -40,  
    			-40,  -2,  40,   
    			40,	 -2,  40  	
    		};
    
    	GLbyte groundTris[2 * 3] =
    		{
    			1,0,3,
    			1,3,2,
    		};
    
    	GLbyte groundNorms[4 * 3] =
    		{
    		0,1,0,
    		0,1,0,
    		0,1,0,
    		0,1,0,	
    		};
    
    	GLbyte texCoords[4 * 2] =
    		{
    			0,1,
    			0,0,
    			1,1,
    			1,0
    		};
    
    	glVertexPointer(   3, GL_BYTE, 0, groundVerts );
        	glTexCoordPointer( 2, GL_BYTE, 0, texCoords   );
        	glNormalPointer(   GL_BYTE, 0, groundNorms    );	
    	glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, groundTris );
    	
    }
    
    
    void drawCube(void) {
    	//draw cube code here - no texturing
    }
    
    void createWorld(void) {
    	glColor4f(0.f, 1.f, 0.f, 1.f);
    	drawGround();
    
    	//other cubes drawn here	
    }
    
    void CGame01::AppCycle( TInt iFrame )
        {	
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    	TReal xtrans = -xpos;
    	TReal ztrans = -zpos;
    	TReal ytrans = -0.25;
    
    	TReal sceneroty = 360.0 - yrot;
    
    	glMatrixMode( GL_MODELVIEW );		
    	glLoadIdentity();
    
    	glRotatef((GLfloat)sceneroty,0,1.0f,0);
    	glTranslatef((GLfloat)xtrans, (GLfloat)ytrans, (GLfloat)ztrans);
    
    	glBindTexture(  GL_TEXTURE_2D, iNokTexObjects[0] );
    	//drawGround();
    	createWorld();
    	glLoadIdentity();
    
    	//player	
    	glTranslatef( 0.f, -1.5f, -8.0f );
    	glScalef(0.4f, 0.3f, 0.4f);
    	glColor4x(1<<16, 0<<16, 0<<16, 1<<16);
    	glRotatex(lean<<16, 0<<16, 0<<16, 1<<16);
    	drawCube();
    
    }
    If anyone needs to see the code form the appUI or container class let me know.

    Any help would be greatly appreciated!
    Miranda

  2. #2
    Nokia Developer Expert
    Join Date
    Mar 2003
    Posts
    68
    Hi Miranda.

    I see you have made couple of choices to the texture coordinate ranges, but you at the same time removed the use of texture matrix for the downscaling so everything should be ok.

    I can't find a bug directly from your code. Usual reasons why texturing is not visible:

    - texture is actually not loaded (did you check somehow that texturedata given to glTexImage2D is actually valid data?)

    - texturing is not enabled (glEnable... this is ok your code)

    - texture is not bound (in your code this is ok)

    - texture format and type are not supported

    - data behind texture coordinate pointer is not valid

    - border is not zero (OpenGL ES does not support borders at the moment)

    - texture width and height is not power of two (are TEX_WIDTH and TEX_HEIGHT 256?)

    - mipmapping is enabled, but not all of the texture levels are complete exactly to the OpenGL specification (all mipmap levels specified ; all power of two ; all consecutive levels 1/2 of the size, expect for the last sizes other dimension may be 1 for many levels ; internal formats for textures in all levels should be the same) .. In your code I didn't see any enables for mipmapping -> it should be ok.

    - texture coordinate pointer not specified

    - texture coordinate array not enabled (this is OK)

    I hope this helps. Try with a 2x2 test texture defined in a header file to see if it is the texture loading that fails.


    Jani Vaarala
    Graphics Architect
    Nokia

Posting Permissions

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