19 posts
Day 053 - Trouble Drawing Walls with DrawRectangle()
Edited by echu on
I followed day 053 to around 48:10 when Casey disables generating the tilemap and uses DrawRectangle() at the end of the program to draw Entities that aren't of type Hero with DrawRectangle. I know the walls are there because my player can't pass through them directly head on. However, they don't appear at all. I suspect this is a problem with alpha blending because the bitmap shadow also looks a bit strange when I jump - it never disappears completely, no matter how high the player jumps. Instead, it just turns into a solid black ellipse.

Nonetheless, I've investigated the alpha blending implementation in DrawBitmap() and implementation of DrawRectangle() and haven't found any differences. Can someone help me solve this?

Please see the well-commented code and screenshot I've attached. Running the program should be as easy as running the .exe in the build/x64/ or build/x86/ directory.

My Code: https://www.filesharing.com/file/details/847791/hh-test.zip
Imgur: Invisible walls, but this area should be drawn in yellow.
19 posts
Day 053 - Trouble Drawing Walls with DrawRectangle()
Edited by echu on
I've solved the weird alpha blending issues with the shadow bitmap. It turns out I had some cruft left in in DrawBitmap() around line 147 of my handmade.cpp file.

 1 2 3 4 5 6 // Extract the alpha value of the source pixel and check if it is greater than some threshold. if ((*sourcePixel >> 24) > 128) { // Copy the source bitmap pixel to the destination buffer pixel. *destinationPixel = *sourcePixel; } 

This meant that since the alpha value of the shadow bitmap near the center was less than some threshold (approximately half), the pixel was never being updated - resulting in the permanent black ellipse.

I still need help with DrawRectangle() though!
19 posts
Day 053 - Trouble Drawing Walls with DrawRectangle()
Edited by echu on
Found the issue! It turns out that in creating the wall with the AddWall() function, the width property was not set correctly.

Casey had the following code.
 1 Entity.Dormant->width = Entity.Dormant->height; 

But, I instinctively typed the following code around line 343 in handmade.cpp.
 1 Entity.Dormant->width = Entity.Dormant->width; 

This wouldn't actually draw anything, because it wasn't set to anything. If I wrote the following, there wouldn't have been a problem.
 1 Entity.Dormant->width = GameState->World->TileMap->tileSideInMeters; 

Since the problem has been solved, I'll be taking down my code. The image demonstrating the original problems will still be available.