Hands On DarkBASIC Pro - Digital Skills
Hands On DarkBASIC Pro - Digital Skills
Hands On DarkBASIC Pro - Digital Skills
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
LISTING-32.1<br />
Adding Texture to an<br />
Object<br />
Mipmaps<br />
For example, we could apply image 1 to object 2 using the line<br />
TEXTURE OBJECT 2,1<br />
The program in LISTING-32.1 demonstrates how a cube can be textured with a<br />
wood image to create the impression of a wooden crate.<br />
REM *** Set display resolution ***<br />
SET DISPLAY MODE 1280,1024,32<br />
REM *** Load texture image ***<br />
LOAD IMAGE "textureWood.jpg",1<br />
REM *** Create cube ***<br />
MAKE OBJECT CUBE 1,40<br />
REM *** Add texture to cube ***<br />
TEXTURE OBJECT 1,1<br />
REM *** Position cube ***<br />
POSITION OBJECT 1,25,0,100<br />
REM *** Rotate cube continuously ***<br />
DO<br />
TURN OBJECT LEFT 1, 1.0<br />
LOOP<br />
REM *** End program ***<br />
END<br />
Activity 32.1<br />
Type in and test the program in LISTING-32.1 (texture01.dbpro).<br />
Change the texture image to eyecol.bmp.<br />
We can see quite clearly from the results of the last Activity that the image is applied<br />
separately to each face of the cube. For other shapes, the image may be applied<br />
differently.<br />
Activity 32.2<br />
Modify your last program so that eyecol.bmp is applied as a texture to a box,<br />
cylinder, cone and sphere (any dimensions will do). Create a separate program<br />
for each shape.<br />
How often is the image repeated on each of the shapes?<br />
Texturing a 3D object can be quite time consuming. It may be easy enough to map<br />
a 300 by 300 pixel image onto a flat surface which occupies exactly 300 by 300<br />
pixels on the screen, but if the 3D object moves off into the distance, the computer<br />
has to work much harder to map the same 300 by 300 image onto an object which<br />
now occupies just 23 by 23 pixels on the screen.<br />
To help with this problem <strong>DarkBASIC</strong> <strong>Pro</strong> creates more than one copy of any image<br />
that is loaded, with each copy being exactly half the size of the last (see FIG-32.3).<br />
<strong>DarkBASIC</strong> <strong>Pro</strong>: Texturing 799