type casting error, please help
greetings, I am usiing Nate Miller''s tga file loading code. When I try to compile it I keep getting type casting errors.
i.e.''='': cannot convert from ''void *'' to ''unsigned char*''
================================================================
//getRGBA
//reads in rgba data for a 32bit image
unsigned char *getRGBA (FILE *s, int size)
{
unsigned char *rgba;
unsigned char temp;
int bread;
int i;
// rgba =(unsigned char *) malloc(size * 4);
rgba = malloc(size * 4);
if (rgba == NULL)
return 0;
bread = fread(rgba, sizeof(unsigned char), size * 4, s);
//tga is stored in bgra, make it rgba
if (bread != size * 4)
{
free (rgba);
return 0;
}
for (i = 0; i < size * 4; i+=4)
{
temp = rgba;
rgba = rgba[1 + 2];
rgba[1 + 2] = temp;
}
texFormat = GL_RGBA;
return rgba;
}
===============================================================
When i rewrite it to <font color="yellow"> rgba =(unsigned char *) malloc(size * 4);</font> the error goes away. Although, malloc uses a <font color="yellow">void *</font> and a void pointer is able to point to any type of object. Why do I get the error? Or maybe I just copied the code down wrong. Thanks in advance.
</i>
<font color="yellow">
—————————–
"There are ones that say they can and there are those who actually do."
"…u can not learn programming in a class, you have to learn it on your own."
</font>
rgba = malloc(size * 4);
Hmmm, if its anything like some of the wierd stuff I"ve been experiencing try doing it like this:
rgba= (unsigned char) (malloc(size*4));
I have no idea if that will work... I prefer using ''new'' (which in case you want to know, is easier,
and here is how you do it:
rgba= new unsigned char [size*4];
------------------------------
Trent (ShiningKnight)
E-mail me
OpenGL Game Programming Tutorials
its cause youre using c++. the above error won''t happen with c. c++ has more rigorous type checking, so stick a cast before it
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement