User forums > General (but related to Code::Blocks)
Compile error
sethjackson:
Hi I get this error
error: incompatible types in assignment of `int' to `unsigned char*[((unsigned int)((int)imageSize))]'
with this code......
--- Code: (cpp) ---if (image.HasAlpha())
{
unsigned long imageSize = image.GetWidth() * image.GetHeight() * 4;
unsigned char* imageData = image.GetData();
unsigned char* imageAlpha = image.GetAlpha();
unsigned char* data[imageSize];
for (unsigned long index = 0; index < imageSize; index += 4)
{
memcpy(data, imageData, 3);
imageData += 3;
memcpy(data + 3, imageAlpha, 1);
imageAlpha++;
data += 4;
}
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.GetWidth(), image.GetHeight(),
GL_RGB, GL_UNSIGNED_BYTE, data);
}
--- End code ---
Help me please...... Sorry for the beginner question? I just don't get it I used to do stuff like increaseing the ptr with += all the time.....
EDIT:
Let me say that it fails on the line
--- Code: (cpp) ---data += 4;
--- End code ---
:P
sethjackson:
Ok I fixed it now could someone tell me why this works???
--- Code: (cpp) ---*(data) += 4;
--- End code ---
polygon7:
Hi,
this should work
--- Code: ---if (image.HasAlpha())
{
unsigned long imageSize = (image.GetWidth() * image.GetHeight()) << 2;
unsigned char* imageData = image.GetData();
unsigned char* imageAlpha = image.GetAlpha();
unsigned char* data[imageSize];
for (unsigned long index = 0; index < imageSize; index += 4)
{
memcpy(data, imageData, 3);
imageData += 3;
memcpy(data + 3, imageAlpha, 1);
++imageAlpha;
(*data) += 4;
}
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, image.GetWidth(), image.GetHeight(),
GL_RGB, GL_UNSIGNED_BYTE, data);
}
--- End code ---
// Edit: Ah, you're faster :P
--- Code: ---char* array[size]
--- End code ---
is the same as
--- Code: ---char** array
--- End code ---
sethjackson:
:lol: :lol: Read my post above. Exactly why does it work though? Thanks. :D
Michael:
--- Quote from: sethjackson on February 05, 2006, 10:40:22 pm --- :lol: :lol: Read my post above. Exactly why does it work though? Thanks. :D
--- End quote ---
You tried to assign an int to an unsigned char*. This does not work for sure. What do did is to de-reference the pointer. Then it works.
Why you cast before int and then unsigned int?
Anyway, do not use C-cast style. This is not a good idea in C++. You should use C++ cast style or better no cast at all (if possible).
Best wishes,
Michael
Navigation
[0] Message Index
[#] Next page
Go to full version