Thread: i`m comfused please help

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    2

    Exclamation i`m comfused please help

    hello there everybody
    i`m new to game programming and directx please can anyone tell what do this sentence mean ?

    int index = i * lockRect.Pitch / 4 + j;

    imageData[index] = 0xffff0000;

    what i cant understand why did i multiplyed lockedrect.pitch with i and then divide it by 4+j ?

  2. #2
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    We're going to need to see more than those two lines. Post us the full program / function.
    EDIT: Oh and code tags plskkkthxbai
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  3. #3
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Maybe, you should learn the English language before you move onto C++!

    What are you trying to accomplish with that code? It does nothing from what I can see.

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    int index = i * lockRect.Pitch / 4 + j;

    imageData[index] = 0xffff0000;
    The divide by 4 is to convert bytes into DWORDs or UINTs.. Pitch is expressed in bytes. 1 UINT or DWORD is 4 bytes.
    You should group your operations with parentheses to make for easier reading of the code.

    Code:
    int index = i * (lockRect.Pitch >> 2) + j;
    
    imageData[index] = 0xffff0000;
    Shift right is same as dividing by 2^shift.
    Shift left is same as multiplying by 2^shift.

    I would say your code worked as planned because multiplication is first, then division, then addition, etc, etc. But it's always a good idea to group the operations for clarity and to ensure the operations are being done in the correct order.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    2
    thanks everybody for the replays
    bubba thanks for the explanation

  6. #6
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Ah, so we didn't need it all. Rather, Bubba didn't. Good ol' Bubs
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  7. #7
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I'm here for ya's all.

    So don't go posting stuff I don't know anything about and we'll get along just fine. The stuff I don't know is pretty much everything John Carmack knows....so no John Carmack threads.

  8. #8
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    What are Mega-Textures(tm)?

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Those crazy things he talked about for terrain and such which I still don't quite understand how they work or would work. I read the article but it was quite sparse and didn't make sense.
    I think it means generating a huge texture and then using it on a surface. The texture is so big that you would not get any repeating or tiling.

Popular pages Recent additions subscribe to a feed