Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Mulligan

Obtaining texture data

This topic is 5534 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!