Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Can't seem to make image from memblock correctly? (Tier 2)

Author
Message
SmokedFeesh
7
Years of Service
User Offline
Joined: 2nd Apr 2017
Location:
Posted: 13th May 2018 05:37
Hey there, I'm working on making an old fashioned raycaster and I really enjoy the portability and functions that come with AGK. I'm trying to use the memblock functions to create some sort of pixel buffer to display to the screen each frame. Now I've got it drawing and its still running at 60FPS but the problem is its drawing at a strange skew and squashed down (shown in the image attatched). The colors also move around when I use WASD meaning its somewhat trying to work. My project is here on github https://github.com/williamsonlogan/agk-raycaster and most of the code I'm using for the memblock pixel buffer is in graphics.h while the rest of the game code is in template.cpp. I'm really confused whats happening but I imagine it has to be with the way I'm addressing the memory in the memblock. I used this example for a lot of it https://www.appgamekit.com/documentation/Reference/Memblock/CreateImageFromMemblock.htm so I'm not exactly sure what I'm doing wrong. Any help would be wonderful.

Attachments

Login to view attachments
SmokedFeesh
7
Years of Service
User Offline
Joined: 2nd Apr 2017
Location:
Posted: 13th May 2018 07:36
Figured out what was wrong, this can be closed or deleted or however that gets handled.
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th May 2018 11:35
Not seen the project but for images you basically have two loops. The image data offset starts at 12, then it's 1 byte per colour (rgba).

So the way I do it you would have two nested loops, the first running 0 to height-1, the second to 1 to width. To get the position for each pixels it's done as such:
Offset=12+(height loop x width x 4) + (width loop x 4)

I've had the same results as you and it's for me been because of miscalculating the y offset......I started it at 1 to height, but that needs to start at 0 for how I do it.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th May 2018 11:31
Quote: ", then it's 1 byte per colour (rgba)."

4 bytes per color/pixel (32-bit), it's 1 byte per color channel
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 14th May 2018 12:41
Which i meant as 1 byte for red, 1 byte for green etc... but thanks for clarifying.

Login to post a reply

Server time is: 2024-11-18 12:16:01
Your offset time is: 2024-11-18 12:16:01