Jump to content
  • Advertisement
Sign in to follow this  
RIZAX

DevIL problem(maybe?) or is it just a casting thing?

This topic is 3632 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Basically simple problem. I have an assignment that goes like this: (I'm at work otherwise I'd link the real source but this is the basic idea) ///////////////////// byte *data; float *mydata, clamp = 20.0f; //allocation stuff data = ilGetData(); for(int x = 0; x < image.size; x++) mydata[x] = (data[x]/255.0f) * clamp; ////////////////////// The problem is that mydata is always zero in every entry. However if i remove clamp and replace it with a hardcoded float everything works. i.e. for(int x = 0; x < image.size; x++) mydata[x] = (data[x]/255.0f) * clamp; ---> yields a zero array for(int x = 0; x < image.size; x++) mydata[x] = (data[x]/255.0f) * 20.0f; ---> yields a properly scaled array. What am I missing? Thanks for any replies, this thing is starting to drive me crazy... [Edited by - RIZAX on July 15, 2008 9:33:50 AM]

Share this post


Link to post
Share on other sites
Advertisement
Very strange! Could you try it with this line:
mydata[x] = (static_cast<float>(data[x])/255.0f) * clamp;

However, (data[x]/255.0f) should actually yield a floating point result without any additional casting ...

Share this post


Link to post
Share on other sites
I've tried using c-style casts,
i.e ((float)(data[x]/255.0f))*clamp ... as far as I know that maps to a dynamic_cast in vs2008 I believe, but that doesnt work. It compiles and runs fine, just with the same problem. Ill try the static_cast when I get back.
Thanks for the reply.

Share this post


Link to post
Share on other sites
Quote:
Original post by RIZAX
I've tried using c-style casts,
i.e ((float)(data[x]/255.0f))*clamp ... as far as I know that maps to a dynamic_cast in vs2008 I believe, but that doesnt work. It compiles and runs fine, just with the same problem. Ill try the static_cast when I get back.
Thanks for the reply.
C-style casts are reinterpret_cast's. dynamic_cast is used with RTTI.

Share this post


Link to post
Share on other sites
you declare 'clamp' as a float pointer, is this really what you wanna do ?

float* mydata, clamp = 20.0f;

since a pointer is an unsigned integer, and 20.0f is the type of float..
the result maybe looks like this...
clamp = 20 * 0x00001000L;

Share this post


Link to post
Share on other sites
Beware of C and its pointer declarations! clamp is a plain float and no pointer to a float because the * is associated with "mydata" and not with the type of the declaration. So mydata is a pointer, clamp is not, and the code looks correct.

In D the situation would be different and clamp would indeed be a pointer to a float.

[Edited by - Stereo on July 15, 2008 9:59:47 AM]

Share this post


Link to post
Share on other sites
Thanks for the replies guys.

Molle85:
Yes I mean for clamp to be a plain float not a pointer

Stereo:
Thanks for that explanation, honestly I've always that the way Molle85 explained, but I guess dumb luck saved me here. Usually when I declare them
in real code I seperate out all the pointers from the plain types.

Share this post


Link to post
Share on other sites
Quote:
Original post by Molle85
you declare 'clamp' as a float pointer, is this really what you wanna do ?

float* mydata, clamp = 20.0f;

since a pointer is an unsigned integer, and 20.0f is the type of float..
the result maybe looks like this...
clamp = 20 * 0x00001000L;

Incorrect. It is declared correctly as a float object not a pointer.

float * mydata, * clamp;

This is declaring clamp as a float pointer.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!