![]() |
Direct Pixel Manipulation (looking for an example of TLN_GetBitmapPtr) - Printable Version +- Tilengine - The 2D retro graphics engine forum (http://tilengine.org/forum) +-- Forum: English forums (http://tilengine.org/forum/forumdisplay.php?fid=3) +--- Forum: Support (http://tilengine.org/forum/forumdisplay.php?fid=7) +--- Thread: Direct Pixel Manipulation (looking for an example of TLN_GetBitmapPtr) (/showthread.php?tid=359) |
Direct Pixel Manipulation (looking for an example of TLN_GetBitmapPtr) - alanhdiniz - 08-27-2019 Hey everyone, I've just started to learn how to use Tilengine, and I was checking ou how to do direct pixel manipulation with the TLN_GetBitmapPtr function, but when changed the value of the pointer the program segfaulted (obviously). And since I could not find any examples of that function (well, not easily at least) I decided to ask some one over here to see if I can get some help. This is my noob code: Code: #include <stdio.h> Already thanking the support, Alan. RE: Direct Pixel Manipulation (looking for an example of TLN_GetBitmapPtr) - megamarc - 08-27-2019 Hi Alan, Welcome here and thanks for your interest! There isn't any problem with your direct pixel manipulation code. The problem is that any layer requires having a palette assigned. When you load a bitmap with TLN_LoadBitmap() and assign it with TLN_SetLayerBitmap(), it's own palette gets loaded and attached. But you're creating an empty bitmap without a palette. Of course the renderer shouldn't crash, just refuse to draw it. I have to fix this behavior. To fix your code, you have to manually create and assign a palette with TLN_CreatePalette() and TLN_SetBitmapPalette(): Code: TLN_Bitmap bitmap = TLN_CreateBitmap(400, 240, 8); You should get a black window because the default palette is black. To modify it, you can use TLN_SetPaletteColor(). Let me know if it works! RE: Direct Pixel Manipulation (looking for an example of TLN_GetBitmapPtr) - alanhdiniz - 08-27-2019 Thanks, marc, it worked (well, at least it didn't segfaulted...), However, I tried to use TLN_SetPaletteColor, and the background is still black. My doubt here is that if I can draw something in runtime in the bitmap layer, or I actually need to use a tileset so I can manipulate that with the bitmap layer I've created. My current code: Code: #include <stdio.h> RE: Direct Pixel Manipulation (looking for an example of TLN_GetBitmapPtr) - megamarc - 08-28-2019 Hi again! You can -in fact you must- draw something to the bitmap you're using in order to see anything. Just setting pixels or color entries won't give any result, you must set both. Be aware that a pixel value of 0 means fully transparent. You don't have to use tilesets: bitmap layers and tiled layers are totally independent, which one to use depends on your game needs. In your example, your call to TLN_SetLayerPalette(0, palette); is redundant: as you've already attached the palette to the bitmap with TLN_SetBitmapPalette(), calling TLN_SetLayerBitmap() automatically sets the palette too. You can set bitmap pixels and/or palette colors at any time, the effect will be visible on the next call to TLN_DrawFrame(). Keep going! |