Xojo database tutorial
RGBABitmap is a memory block that stores the pixel color data of the texture.
The OGLName property stores the Integer that OpenGL assigned to the texture. The Width and Height properties stores the dimensions of the texture. X3Texture is a class that makes working with textures easier. X3Core.X3_LoadRGBATexture returns an integer that is used to bind to the texture during the mapping of the texture onto polygons. The X3Core.X3_LoadRGBATexture helper method is used load RGBA texture bitmaps into OpenGL memory. OpenGL.glClear(OpenGL.GL_COLOR_BUFFER_BIT + OpenGL.GL_DEPTH_BUFFER_BIT)
#XOJO DATABASE TUTORIAL CODE#
Add the following code to the Surface.Render event handler: Add the following code to the end of the X3Core.X3_Initialize method:Ģ7. Add the following code to the SurfaceWindow.Open event handler: Import the picture into your project and rename it to "imgTexture".Ģ5.
#XOJO DATABASE TUTORIAL DOWNLOAD#
Download texture.png and save it next to your project file.Ģ4. Add the following property to SurfaceWindow:Ģ3. Import the X3Test module into your project.Ģ2. OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, 0) OpenGL.glVertex3d poly.Vertex(j).X, poly.Vertex(j).Y, poly.Vertex(j).Z OpenGL.glTexCoord2d poly.UVMap(j).U, poly.UVMap(j).V OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, ) Replace the code in the X3Core.X3_RenderModel method with the following: Add the following properties to X3Polygon:Ģ0. Sub Constructor(initU As Double, initV As Double)ġ9. Add the following method to X3UVCoordinate. Add the following properties to X3UVCoordinate:ġ8. Add a new class named "X3UVCoordinate" to module X3Core.ġ7. Add the following method to X3Texture.ġ6. OGLName = X3_LoadRGBATexture(RGBABitmap, Width, Height)ġ5. RGBABitmap.Byte(offset + 2) = textCol.Blue RGBABitmap.Byte(offset + 1) = textCol.Green TextMaskCol = (x, y)Īlpha = 255 - (textMaskCol.Red + textMaskCol.Green + textMaskCol.Blue) / 3 RGBABitmap = new MemoryBlock(Height * Width * 4) Add the following properties to X3Texture:ġ4. Add a new class named "X3Texture" to module X3Core.ġ3. OpenGL.glTexImage2d(OpenGL.GL_TEXTURE_2D, 0, 4, width, height, 0, OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE, RGBABitmap)ġ2. OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR) OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR) OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, OGLName)
IMPORTANT: Image dimensions must be in power of 2 (e.g. Add the following method to module X3Core:įunction X3_LoadRGBATexture(RGBABitmap As MemoryBlock, width As Integer, height As Integer) As Integer Add the following code to the Surface.Resized event handler:ġ1. X3_EnableLight OpenGL.GL_LIGHT0, new X3Core.X3Light(0, 0, 1)ġ0. Add the following code to the Surface.Open event handler: Import the X3Core module, created in the previous tutorial.ĩ. Add the following code to the SurfaceWindow.Paint event handler:Ĩ. Position and size Surface to fill the whole window, and set its locking to left, top, bottom and right.ħ. Enter "Tutorial011" as the Application Name, and click OK.Ħ. Using the above coordinate system as a reference, we can now easily map a texture, or part thereof, to a polygon as shown below.Ģ. The diagram below illustrates the UV-coordinate system, or UV Map, that we use when mapping texture bitmaps to polygons. The image below illustrates how the coordinates of a texture bitmap might be matched with the vertices of polygons. OpenGL will automatically handle the drawing of the texture onto the polygon. We simply need to match the coordinates on a texture bitmap to the vertices of a polygon. The mapping of texture bitmaps onto polygons is a very straightforward process. Power-of-two dimensions ensure backward compatibility with older hardware and in certain cases improve the rendering speed. It is best practice to ensure that the dimensions of your textures are power-of-two (e.g.
#XOJO DATABASE TUTORIAL FULL#
PNG supports loss-less data compression (high quality images) and has full alpha channel support (transparency). The PNG file format is the recommended format for storing texture bitmaps. Consider the following image that could potentially be used as a texture bitmap. Texture mapping is a technique used to "paint" an image, or part thereof, onto a polygon.