Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Briskon

Lesson 36

This topic is 5454 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

Lesson 36: In the EmptyTexture function, the following line is used to allocate space for an empty texture of size 128*128 width 4 color components: data = (unsigned int*)new GLuint[((128*128) * 4 * sizeof(unsigned int))]; Can someone tell me why "4*sizeof(unsigned int)" is used? Shouldn''t the new operator automatically allocate "4*sizeof(unsigned int)" bytes of memory per pixel when GLuint is specified? Or is it an error?

Share this post


Link to post
Share on other sites
Advertisement
4 the color depth and sizeof(unsignedint) for number of bytes (the size of the values) being placed in it

Share this post


Link to post
Share on other sites
Briskon:

You''re right in that the new operator should automatically include the "sizeof(unsigned int)". However, you still need the 4 to allocate space for the 4 color components of the texture (RGBA). As it is it should allocated 4 times as much space as is needed (assuming that an unsigned int is 4 bytes). Take out the "sizeof(unsigned int)" and it should work just fine.

BGCJR:
If we were using malloc, you''d be correct. However, since lesson 36 uses the new operator, we don''t need to specify the number of bytes, only the number of elements in the array.

My guess is that the code may have been written in C (using malloc) orginally and that clause was simply missed when converting to C++ memory operations.



"Back to the code mines... ka-chink... ka-chink..."
Tachyon Digital - Down for the summer, be back in the fall.

Share this post


Link to post
Share on other sites
Are you sure you need to use the "4" for the RGBA components?

Ie. How come you need four ints per component when the max a component can have is one byte? Therefore 4 bytes for a whole pixel which is one int.

Try and make myself clearer:
"new GLuint[128*128]" should allocate enough memory for 128*128 pixels, each with four components (RGBA). So why the need for the 4?



Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!