Skip to main content
GameDev.net gamedev.net
🔒 Locked

a simple coding problem....

Started by Austrian Coder Oct 5, 2002 at 7:07 PM 2 replies 200+ views
Original Post
Austrian Coder
Austrian Coder
Hi... i am currently working on some texture-routines: // ================================== // loading routine for pcx''s bool CTextureFactory::LoadPcx(String Filename, CTexture* &texture) { assert(Filename); FILE *pFile; pcx_Header_t *pcxPtr; int imgWidth, imgHeight; int textureFileLen; int imgBufferPtr; int i, j; unsigned char *pImage; unsigned char *imgBuffer; unsigned char *texBuffer; unsigned char *pcxBufferPtr; unsigned char *paletteBuffer; // open File if((pFile = fopen(Filename, "rb")) == NULL) { // faild to open gLog->Message("File %s was not found", Filename); return false; } ... .. lot of stuff .. ... // cleanup delete [] texBuffer; delete [] paletteBuffer; delete [] imgBuffer; // Set infos texture->width = imgWidth; texture->height = imgHeight; texture->bpp = 3; texture->data = new unsigned char[sizeof(pImage)]; texture->data = pImage; texture->Name = Filename; texture->type = GL_RGB; delete [] pImage; return true; } Now how can i calculate the size of an pointer? Or how can i copy pImage to texture->data? Because my bad way dosen''t work. Thanks, Austrian Coder
Beer Hunter
Beer Hunter
c++ provides no way of querying a pointer to find out how much data it points to. You can either store that number alongside the pointer, or you can try to calculate it from any other values you have.
Austrian Coder
Austrian Coder
Thanks for this info... now i use it directly!

// convert
texture->data = new unsigned char[imgWidth*imgHeight*3];
for (j = 0; j < imgHeight; j++)
{
for (i = 0; i < imgWidth; i++)
{
texture->data[3*(j * imgWidth + i)+0] = paletteBuffer[ 3*imgBuffer[j*imgWidth+i]+0 ];
texture->data[3*(j * imgWidth + i)+1] = paletteBuffer[ 3*imgBuffer[j*imgWidth+i]+1 ];
texture->data[3*(j * imgWidth + i)+2] = paletteBuffer[ 3*imgBuffer[j*imgWidth+i]+2 ];
}
}
Neosmyle
Neosmyle
quote:
Now how can i calculate the size of an pointer?

You can''t. Read above post.
quote:
Or how can i copy pImage to texture->data? Because my bad way dosen''t work.

You should be able to use width*height to figure out how big the data is.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.