Original Post
Hello all, I have a question about the void pointer, which is best described by what I am trying to do:
// allocate memory for image data
unsigned char *imageData = new unsigned char[imageSize];
// copy the SDL_Surface void* pixel array into imageData
memcpy(imageData, surf->pixels, imageSize);
// change BGR to RGB so OpenGL can use the data
for (int imageIdx = 0; imageIdx < imageSize; imageIdx += image->nBPP)
{
// Is there a way to NOT copy the data, and simply cast
// surf->pixels to access its data?
colorSwap = imageData[imageIdx];
imageData[imageIdx] = imageData[imageIdx+2];
imageData[imageIdx + 2] = colorSwap;
}
I would like to think there is a way to cast surf->pixels from a void* to unsigned char* so I don't have to waste time doing a memcpy. So my question is, is there a way I can cut out imageData from this picture, and just use surf-pixels? thanks, Tony