Handmade Network»Forums
2 posts
Day 008 - the window graphics is not moving anymore
Edited by shuravi on Reason: Initial post
I unzipped the archive of Day 008 (the Day 007 file works fine).
In Casey's tutorial, inside the window the "blocks" were moving,
but when I run this file, the window opens and the sound starts to play,
but the "graphical blocks" doesn't move.

I have a Windows 10.

Does anyone know why this does happen and how to fix this?
Joshua Donahue
7 posts
None
Day 008 - the window graphics is not moving anymore
Edited by Joshua Donahue on
I have the exact same issue on my machine. The problem is that the gradient function renders the gradient based on the offset passed in.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
internal void
RenderWeirdGradient(win32_offscreen_buffer *Buffer, int BlueOffset, int GreenOffset)
{
    // TODO(casey): Let's see what the optimizer does

    uint8 *Row = (uint8 *)Buffer->Memory;    
    for(int Y = 0;
        Y < Buffer->Height;
        ++Y)
    {
        uint32 *Pixel = (uint32 *)Row;
        for(int X = 0;
            X < Buffer->Width;
            ++X)
        {
            uint8 Blue = (X + BlueOffset);
            uint8 Green = (Y + GreenOffset);

            *Pixel++ = ((Green << 8) | Blue);
        }
        
        Row += Buffer->Pitch;
    }
}

The BlueOffset and GreenOffset parameters control the horizontal and vertical scaling of the gradient, respectively. RenderWeirdGradient is being called in the main loop here, after the XInput handling:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// NOTE(casey): Graphics test
int XOffset = 0;
int YOffset = 0;

...

while(GlobalRunning)
            {
            ...

// TODO(casey): Should we poll this more frequently
                for (DWORD ControllerIndex = 0;
                     ControllerIndex < XUSER_MAX_COUNT;
                     ++ControllerIndex)
                {
                    XINPUT_STATE ControllerState;
                    if(XInputGetState(ControllerIndex, &ControllerState) == ERROR_SUCCESS)
                    {
                        // NOTE(casey): This controller is plugged in
                        // TODO(casey): See if ControllerState.dwPacketNumber increments too rapidly
                        XINPUT_GAMEPAD *Pad = &ControllerState.Gamepad;

                        /* more button stuff */

                        int16 StickX = Pad->sThumbLX;
                        int16 StickY = Pad->sThumbLY;

                        XOffset += StickX >> 12;
                        YOffset += StickY >> 12;
                    }
                    else
                    {
                        // NOTE(casey): The controller is not available
                    }

            RenderWeirdGradient(&GlobalBackbuffer, XOffset, YOffset);
            ...
            }


XOffset and YOffset are initialized to zero, and are updated based on the analog stick input. If you don't have a controller plugged in, or if XInput failed to register for whatever reason, XOffset and YOffset will remain 0, and the gradient won't move.
2 posts
Day 008 - the window graphics is not moving anymore
Thank you, now it works.