Obtaining texture data

Started by
-1 comments, last by Mulligan 20 years, 10 months ago
I have an array of unsigned ints which hold data for a picture. I know the origional data is correct and actually contains the image. When I create a texture out of it and then try to re-obtain the data from the texture to put it back into an unsigned int array via: glTexImage2D( GL_TEXTURE_2D, 0, 3, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, pTexture ); The left half of the image is black. Its 256x256. Any idea of why its only getting the right side of the picture? Heres some more detailed code for your viewing pleasure: CREATING THE TEXTURE FROM THE DATA
        
//-----------------------------------------------------------------------------

// Name: CreateLightmap()

// Desc:

//-----------------------------------------------------------------------------

bool CLightmapManager::CreateLightmap( const unsigned char* pData, const int iIndex )
{
    TRACE_ENTER_FN( CLightmapManager::CreateLightmap )

    // Free whatever may be in use

    if( !ReleaseLightmap( iIndex ) ) LOG_ERR_RET( false )

    unsigned char *pTexture = NULL;
    const int iLen = BLOCK_WIDTH * BLOCK_HEIGHT * 3;

    // Must be a power of 2

    //if( BLOCK_WIDTH & ( BLOCK_WIDTH - 1 ) ) LOG_ERR_RET( false )


    // Data cant be null

    if( pData == NULL ) LOG_ERR_RET( false )

    // Create memory to hole the texture

    pTexture = new unsigned char[ iLen ];

    // Be sure it was created

    if( pTexture == NULL ) LOG_ERR_RET( false )

    // Copy the data passed in into the new data holder

    memcpy( pTexture, pData, iLen * sizeof( unsigned char ) );

    // Create the texture

    glGenTextures( 1, &m_pLightmapBlocks[ iIndex ] );    

    // Bind it

    glBindTexture( GL_TEXTURE_2D, m_pLightmapBlocks[ iIndex ] );
    
  //  glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 0, 0, BLOCK_WIDTH, BLOCK_HEIGHT, 0 );


    // COpy the pixel data to the texture

    glTexImage2D( GL_TEXTURE_2D, 0, 3, BLOCK_WIDTH, BLOCK_HEIGHT,
                  0, GL_RGB, GL_UNSIGNED_BYTE, pTexture );    
    
    // Set stuff for this texture

    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

    // Clean up

    if( pTexture != NULL ) delete[] pTexture;

    RET( true )
}
  
  
GETTING THE TEXTURE DATA AND PUTTING IT INTO AN ARRAY
  
glBindTexture( GL_TEXTURE_2D, m_pLightmapBlocks[ 0 ] );                
        glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 0, 0, BLOCK_WIDTH, BLOCK_HEIGHT, 0 );
        glGetTexImage( GL_TEXTURE_2D,    0, GL_RGB, GL_UNSIGNED_BYTE, pPic ); 

        if( !GenerateScreenShot( "Lightmap.tga", BLOCK_WIDTH, BLOCK_HEIGHT, true, pBlock ) )
        {
            LOG_ERR_RET( false )
        }
      
[edited by - Mulligan on May 28, 2003 8:28:09 PM]

This topic is closed to new replies.

Advertisement