I’ve been having a bit of trouble and think I can trace it to a misuse of pointers.
I want to copy the data from one pointer (call it pointer1) to another pointer (pointer2) and then adjust the data referenced by pointer2 without adjusting the data referenced by pointer1.
More specifically…
I am assigning two pointers to arrays:
pointer1 = new unsigned char [imageWidth * imageHeight * 3];
pointer2 = new unsigned char [imageWidth * imageHeight * 3];
Then I am referencing image data to pointer1:
pointer1 = image.getPixels();
I then want to assign pointer2’s reference with the data from pointer1. Then I want to alter that data and use pointer2 to display the new image. (the following just shows me altering pointer2’s referenced variables)
for (int y = 0; y < scnHeight; y++){
for (int x = 0; x < scnWidth; x++){
//set RGB pixel data count
int pixR = (y * scnWidth * 3) + (x*3);
int pixG = (y * scnWidth * 3) + (x*3) + 1;
int pixB = (y * scnWidth * 3) + (x*3) + 2;
tempR = pointer2[pixR] + 10;
if(tempR > 255){tempR = 255;}
if(tempR < 0){tempR = 0;}
pointer2[pixR] = tempR;
tempG = pointer2[pixG] + 10;
if(tempG > 255){tempG = 255;}
if(tempG < 0){tempG = 0;}
pointer2[pixG] = tempG;
tempB = pointer2[pixB] + 10;
if(tempB > 255){tempB = 255;}
if(tempB < 0){tempB = 0;}
pointer2[pixB] = 10;
}
}
newImage.loadData(pointer2, imageWidth, imageHeight, GL_RGB);
newImage.draw(0, 0, imageWidth, imageHeight,);
and lastly I want to reset pointer2 to reference the original image data. Any ideas?