Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

type casting error, please help

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 cMADsc   Members   

122
Like
Likes
Like

Posted 30 July 2001 - 09:19 AM

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[i] = rgba[1 + 2];
rgba[1 + 2] = temp;
}

texFormat = GL_RGBA;
return rgba;
}
===============================================================
When i rewrite it to rgba =(unsigned char *) malloc(size * 4); the error goes away. Although, malloc uses a void * 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.



-----------------------------
"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."



#2 mittens   Members   

1323
Like
Likes
Like

Posted 30 July 2001 - 03:17 PM

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

#3 zedzeek   Members   

528
Like
Likes
Like

Posted 31 July 2001 - 09:56 AM

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




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.