You are not logged in.

#1 2009-07-23 01:50:06

BlueChip
Moderator

[DONE] Faster way to create new textures

As the entire texture is filled completely with 0x00's when created:

This:

Code:

        // Initialize the texture
        for (y = 0; y < h; y++) {
            for (x = 0; x < w; x++) {
                GRRLIB_SetPixelTotexImg(x, y, my_texture, 0x00000000);
            }
        }

can be replaced with this:

Code:

  bzero(my_texture->data, (h *w) <<2);

I can be found on efnet, freenode, msn, gtalk, aim, ychat & icq ...PM me for details

Offline

 

#2 2009-07-23 16:55:04

Crayon
Bad Mother Fucker

Re: [DONE] Faster way to create new textures

That's a good  idea. But to make it more standard I think I'll use memset instead of bzero:

Code:

memset(my_texture->data, '\0', (h * w) << 2);

Offline

 

#3 2009-07-23 21:22:42

BlueChip
Moderator

Re: [DONE] Faster way to create new textures

*Just Asking* ...NOT criticising !

'\0' means "the character with an octal value of 0" (used to terminate strings)
0 means "the (octal) number 0"

Other than '\0' taking longer to compile they are otherwise identical

Why do you (and many others) use '\0' instead of 0 when dealing with numbers-not-strings?


I can be found on efnet, freenode, msn, gtalk, aim, ychat & icq ...PM me for details

Offline

 

#4 2009-07-23 21:32:48

Crayon
Bad Mother Fucker

Re: [DONE] Faster way to create new textures

'\0' means character zero. It's like '\32' means the space character.

I'm so lazy I did a copy/paste from a Web site talking about bzero:

The memset() function is preferred over this function.

For maximum portability, it is recommended to replace the function call to bzero() as follows:

#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)

But your right they are exactly the same thing, and since my_texture->data is not a string maybe 0 would be less confusing.

Offline

 

Board footer

Powered by FluxBB