Not long ago, I mentioned that it would be great to draw in 3D using native elements, in the simplest possible way, without needing OpenGL knowledge.
I have replicated the essential parts of 3D rendering.
The module is called bitmapcreator3d. That’s the name I gave it, but since you’ll be copying it into your own empty code module, you can name it whatever you like.
This code module contains the following methods:
Initialize (width As Int, height As Int, focusX As Int, texturesMax As Int, minDis As Float, maxDis As Float)
Creates a BitmapCreator object with the given size and prepares the module for use.
Add_Texture(index As Int, filename As String)
Provide the name of an image file and assign it an index (must not be higher than texturesMax).
This stores the image in a BitmapCreator object, allowing for fast pixel access later.
DrawMap (Public BitmapCreator object)
All drawing happens on DrawMap. Since it’s a BitmapCreator object, you can manipulate it freely. After rendering, this object should be drawn to the screen, for example, using a Canvas.
depth_test (Public Boolean)
Enables or disables depth testing during rendering. When enabled, it checks whether pixels should be drawn in front of or behind others. Normally set to TRUE.
depth_write (Public Boolean)
Controls whether pixel depth values are stored in the depth buffer during rendering. Normally set to TRUE.
DepthBuffer_Clear
Clears the depth buffer (sets all pixels to the farthest depth). This must be done before every render pass.
DrawTriangle3D (x0, y0, z0, x1, y1, z1, x2, y2, z2, texture, tx0, ty0, tx1, ty1, tx2, ty2)
Important Note:
Rotations and transformations must be handled manually.
This concept is simply meant to allow 3D drawing on a BitmapCreator object with a minimal set of methods.
Perfect for things like a simple 3D scene, a little house, or anything else you dream up.
I have replicated the essential parts of 3D rendering.
The module is called bitmapcreator3d. That’s the name I gave it, but since you’ll be copying it into your own empty code module, you can name it whatever you like.
This code module contains the following methods:
Initialize (width As Int, height As Int, focusX As Int, texturesMax As Int, minDis As Float, maxDis As Float)
Creates a BitmapCreator object with the given size and prepares the module for use.
- width, height: the dimensions. It’s important to choose an aspect ratio matching how the image will later appear on the screen. If you want full screen, use something like (Activity.Width x some ratio) and (Activity.Height x some ratio).
- focusX: this is the scale factor of the 3D space. It helps scale your 3D vertices into the ideal range.
- texturesMax: how many textures you plan to load. Use a higher number just to be safe — it doesn’t hurt.
- minDis, maxDis: define the nearest and farthest visible depth range. Pixels closer than minDis or farther than maxDis will not be drawn. Avoid setting these values unnecessarily small or large, as they define the range for depth buffer storage. A large range reduces depth precision.
Add_Texture(index As Int, filename As String)
Provide the name of an image file and assign it an index (must not be higher than texturesMax).
This stores the image in a BitmapCreator object, allowing for fast pixel access later.
DrawMap (Public BitmapCreator object)
All drawing happens on DrawMap. Since it’s a BitmapCreator object, you can manipulate it freely. After rendering, this object should be drawn to the screen, for example, using a Canvas.
depth_test (Public Boolean)
Enables or disables depth testing during rendering. When enabled, it checks whether pixels should be drawn in front of or behind others. Normally set to TRUE.
depth_write (Public Boolean)
Controls whether pixel depth values are stored in the depth buffer during rendering. Normally set to TRUE.
DepthBuffer_Clear
Clears the depth buffer (sets all pixels to the farthest depth). This must be done before every render pass.
DrawTriangle3D (x0, y0, z0, x1, y1, z1, x2, y2, z2, texture, tx0, ty0, tx1, ty1, tx2, ty2)
- The first nine values define the 3D coordinates of the triangle’s vertices.
- texture: the index of the texture previously added via Add_Texture.
- The last six values are the texture coordinates. The triangle formed by these coordinates will be sampled from the texture and drawn onto the triangle formed by the 3D vertices on DrawMap.
Important Note:
Rotations and transformations must be handled manually.
This concept is simply meant to allow 3D drawing on a BitmapCreator object with a minimal set of methods.
Perfect for things like a simple 3D scene, a little house, or anything else you dream up.
