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.

DarkBASIC Professional Discussion / Need help with MemBlock to Image

Author
Message
punkyb
7
Years of Service
User Offline
Joined: 8th Sep 2016
Playing: PC and Android Games
Posted: 28th Oct 2016 02:50
I found an interesting plugin that reads rar and zip files and loads the assets directly to memblocks. The problem is I don't know how to load them from memblock as images.

I'm attaching the plugin that I found somewhere in the older posts.

Appreciate any help.

Attachments

Login to view attachments
punkyb
7
Years of Service
User Offline
Joined: 8th Sep 2016
Playing: PC and Android Games
Posted: 28th Oct 2016 02:56
Just a note: This totally unrelated to the mipmapping post which I used Enhancements Pack's builtin zip reader and resolved this problem.

open file block "Myassets.zip", 1

Maybe this one does not discard mipmapping I have to find out. I just need an asset packer that does not stick to my main executable (media mode) and I'm having trouble finding one.
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 30th Oct 2016 02:33
I saw you in the other thread also asking about this.
or more specifically how to get the images to have mip-maps.
I'll try and post something helpful in a few hours.
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 30th Oct 2016 07:21 Edited at: 30th Oct 2016 07:36
I have never used a plugin that loads images into memblocks from zip files.
However I can probably give you the information that you need.

For a game I've been working on I texture characters with their skin. I then lay a clothing texture down on top of that. This allows for many different skin types and clothing without exponential numbers of textures.
This is done by taking the skin texture and merging the partially transparent clothing texture down on top of it into a single dbpro image.

The following function does this merging process.
However it also demonstrates 2 important things. How to create an image from a memblock and how to do it where it generates new mipmaps.



The key parts in this I am moving the data into a third memblock not created by make memblock from image and I am deleting the first image rather than relying on make image from memblock to overwrite it itself.
Before I implemented these details what was happening was the merged clothed texture was overwriting the first image (originally just the body/skin) and the original mipmaps remained.
This caused people to look naked at a distance, forcing me to turn off mipmapping.
punkyb
7
Years of Service
User Offline
Joined: 8th Sep 2016
Playing: PC and Android Games
Posted: 30th Oct 2016 12:44
Ok thanks a lot Mage! So, can you give me some hints on would I go about this?

I'm kinda confused with the 2 textures stuff as I would like to just retain the mipmapping information.

WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 30th Oct 2016 21:25 Edited at: 30th Oct 2016 21:34
Internally the function Make Image From Memblock calls the internal function MakeFormat in CimageC.cpp. This snippet lists the function MakeFormat. The fourth parameter in the call to the DirectX function D3DXCreateTexture is the miplevel, which is set to one creating only one level. The only way I'm aware of to generate mipmaps is to save the image and then reload it.

WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 30th Oct 2016 22:38
Here is a PDF of the DBPro Memblock Reference, I beleive was found at Chris Tate's binarymodular.com website.

Attachments

Login to view attachments
punkyb
7
Years of Service
User Offline
Joined: 8th Sep 2016
Playing: PC and Android Games
Posted: 30th Oct 2016 22:58
Quote: " The only way I'm aware of to generate mipmaps is to save the image and then reload it."


Thanks WickedX, that was some great additional info there. Apparently the whole point of loading directly from zip file is to do without writing it to disk. I was looking forward to media and alone option but with media you have to merge your assets and your exe will inflate like crazy. I'm planning to use a lot of high res textures so this one got my attention from the start. The alone option is great but I did not know that it was only for dbp dlls converted.

I was also just wondering why it was not taken into account with memblocks and mipmapping. It's DarkBasic (Pro) which is primarily 3D and then you got this Enhancement Pack which is great btw, saves the trouble doing this kind of stuff. The only missing part is maybe they forgot about mipmapping? I thought forcing mipmapping flag would do it but it I read somewhere that it still does not work and gets discarded.

Enhancement pack is perfect and just what I need, this mipmapping is just the only problem that I need to sort out. Good thing Mage here has a solution that I'm still trying to wrap my head around it. :/


WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 31st Oct 2016 00:32 Edited at: 31st Oct 2016 00:34
If it's only image files you're wanting to pack externally, look at the image block functions. After opening an image block you use Load Image just as if the image was loaded individually from your drive and will load as such with mipmap levels intact.
punkyb
7
Years of Service
User Offline
Joined: 8th Sep 2016
Playing: PC and Android Games
Posted: 31st Oct 2016 02:00 Edited at: 31st Oct 2016 02:01
Thanks, that seems easy to do but can you give a basic example? The last block experiments with images that I did went out of hand and I have to restart my pc a couple of times due to lockups. :/
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 31st Oct 2016 02:35
WickedX wrote: "The only way I'm aware of to generate mipmaps is to save the image and then reload it."


I must remember back several years for all of this. But I remember I think Lee saying that there was no reason why mipmaps would not be created from MAKE IMAGE FROM MEMBLOCK command.
Perhaps this has changed since then or some other matter or confusion.

I will attempt to test my function listed above. it is possible that no mipmap is generated at all and the system simply corrects automatically by not using mipmaps even when enabled.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 31st Oct 2016 03:00 Edited at: 31st Oct 2016 03:01
@ Mage:

In your code you delete the image before Make Image From Memblock. If the image was not deleted mipmap level 1 is replaced with the new image retaining the other mipmap levels from the original image. This is why the clothed texture disappears at a distance.

The first snippet creates an imageblock file. Notice after we open the image block in write mode something needs to be excluded for this to work. The second snippet just loads the images from the image block.

CreateImageBlock:


LoadFromImageBlock:
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 31st Oct 2016 03:59
WickedX wrote: "In your code you delete the image before Make Image From Memblock. If the image was not deleted mipmap level 1 is replaced with the new image retaining the other mipmap levels from the original image. This is why the clothed texture disappears at a distance."


If I take the result of the merger and then merge the skin over top again this time without using the correction it should produce the (hilarious) effect I mentioned in reverse.
That is to say up close the character would appear naked like a ken doll, and at a distance clothed

If it does then it will demonstrate that beyond any doubt that the mipmaps are working. If it does not then it will demonstrate beyond any doubt that they are not.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 31st Oct 2016 04:28 Edited at: 31st Oct 2016 04:29
Let me know how that turns out. It will definitely give us a definitive answer.
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 31st Oct 2016 06:14
You were right.
punkyb
7
Years of Service
User Offline
Joined: 8th Sep 2016
Playing: PC and Android Games
Posted: 31st Oct 2016 09:27 Edited at: 31st Oct 2016 09:42
Thanks WickedX! This is perfect and kind of the solution that I was looking for all along! Just like normal image load but you can pack them up, I did read some docs that you can only max up to 64mb which is not a big issue. I tried searching this on keywords but it does not show up, built-in commands I guess?

Awesome, problem solved!
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 31st Oct 2016 17:23
Great! I have never noticed this 64mb limit. I suppose you can convert the images to formats with more compression such as DDS or PNG to get more images in a single image block file and if your images require more memory, just use multiple image block files. No, not a big issue.
punkyb
7
Years of Service
User Offline
Joined: 8th Sep 2016
Playing: PC and Android Games
Posted: 1st Nov 2016 00:06 Edited at: 1st Nov 2016 00:50
Yes, I got it from here.

So I have tested it and it seems it's a size per image limit and not per file which is even awesome!

Login to post a reply

Server time is: 2024-04-17 00:13:21
Your offset time is: 2024-04-17 00:13:21