MiniB3D and SetVirtualResolution

BlitzMax Forums/MiniB3D Module/MiniB3D and SetVirtualResolution

AvestheFox(Posted 2012) [#1]
I'd like to be able to set the virtual resolution and for it to effect both the Max2D and Minib3d graphics output...

I've tried using grabimage to grab the 3d rendering and then drawing the image that was grabbed to the max2d field, but as we all know, grabimage reeks of snails when being used in a loop...

Help please!


Kryzon(Posted 2012) [#2]
Hi. We've worked this out in Blitz3D before: http://blitzbasic.com/Community/posts.php?topic=95702#1104692

The steps are:
• Create a graphics screen with any common resolution you want, like 800x600, 1920x1080 etc.
• Create a camera with a small viewport that has the same ratio as your game screen (this is your virtual resolution), and create another camera but don't change its viewport (so it'll be the same size of your screen).
• Render the scene with the small viewport camera, and use MiniB3D's BackBufferToTex() function (instead of GrabImage) to copy the contents of the small viewport to a certain texture to hold it.
• Use this texture on a specially mapped fullscreen quad like in the above example. You need to build the quad with the same UV values as the link I pointed you to, so the quad doesn't grab any empty texture space.
• After the quad is setup, render the scene with the normal game camera, start Max2D mode and draw your overlayed Max2D stuff.

• Optionally, go to TMesh.BMX Update() function and change the following:
' mipmapping texture flag
If tex_flags&8<>0
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR)
Else
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
EndIf
To this...
' mipmapping texture flag
If tex_flags&8<>0
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR)
Else
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST) 'Changed to "LINEAR".
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST) 'Changed.
EndIf
...and rebuild your mB3D module.
Every texture now that doesn't use MipMapping will use Nearest-Neighbour filtering, which gives textures a pixelized, jagged look kinda like PSOne games or MineCraft.
If your virtual resolution texture (the one rendered by the small-viewport camera) uses this 'nearest' filtering it'll look much, much better.

Last edited 2012


AdamRedwoods(Posted 2012) [#3]
I haven't used VirtualResolution() but looking quickly at the code for SetResolution in openGL my guess is that you need to SetResolution() first, then call GraphicsInit(), because that will save the state for you when you call BeginMax2D().

Is that what you are looking for?

EDIT: ah, thankfully someone who knows what you're talking about has stepped in.

Last edited 2012


AvestheFox(Posted 2012) [#4]
@Kryzon I've already set the mipmap settings to "NEAREST" a while back (because I want my games to have that old school jagged effect) so I'm good to go on that bit!

I'll try the other part of your suggestion later on today when I get around to my project. Thanks! :D

@AdamRedWoods thanks for the effort regardless :)