To get a “realistic” look for your objects, the best approach is to wrap an image around your shapes. To do this, you must create a texture and then tell Blitz3D what object you would like to wrap that texture around. In the following example, we will create a sphere and then wrap an image around it.
Note: Texture Location
It is very important to note that the file that contains your texture must be saved in the same location as your program file or you must specify the folder where it is located. After you have entered the following code, save it to a location and then copy the texture file to the same location as the program file.
; demo05-05.bb - Putting a texture on a sphere ; ------------------ Graphics3D 640,480 SetBuffer BackBuffer() Const ESC_KEY = 1 ; Create camera camera = CreateCamera() ; Create a light light = CreateLight() ; Create our sphere sphere=CreateSphere(32) PositionEntity sphere,0,0,5 ScaleEntity sphere, 2,2,2 ; Create the texture tex=LoadTexture( "texture.bmp" ) EntityTexture sphere, tex ; This following code makes our program run While Not KeyDown(ESC_KEY) RenderWorld Flip Wend End
Run the program and you should see the same textured sphere shown in Figure 5.20.
Let’s take a closer look at the code that loaded and applied the texture:
; Creating the texture tex = LoadTexture( "texture.bmp" ) EntityTexture sphere, tex
The first part tex= is just a name. You can name your texture anything, but in this case, we called it tex. LoadTexture is the actual command that tells Blitz3D to load a specific texture. Within the brackets, you tell Blitz3D which file to load. In this case, the file is called texture.bmp.
Note that the file that you choose to load must be in the same folder that your program is saved in. In this example, texture.bmp would have to be in the same folder that your saved program is in, unless you specify another folder.
The next line, EntityTexture followed by sphere, tex, tells Blitz3D to put the texture, in this case called tex, onto the shape called sphere.
18.218.59.168