PowerVR Series1

Up QuickStart1 QuickStart2 QuickStart3 QuickStart4 QuickStart5 |  | ### PowerVR SGL Direct Quickstart Tutorial - Step 5
| Texturing is easily done by defining the u,v coordinates for each vertex and loading a bitmap image containing the texture.
    #include "sgl.h"
    #define RGB(r, g, b) ((sgl_uint32) (((r) << 16) | ((g) << 8) | (b)))

    SGLCONTEXT     SGLContext;
    SGLVERTEX      Vertices[] =	{
    /*                 x      y     z  (1/W)     col       spec.col (u/W) (v/W) */
    	        {  0.0f,240.0f,0.0f,0.1f,RGB(255,0,0),RGB(0,0,0),0.0f,0.0f},
    	    	{320.0f,479.0f,0.0f,0.8f,RGB(255,0,0),RGB(0,0,0),0.4f,0.8f},
    		{639.0f,240.0f,0.0f,0.1f,RGB(255,0,0),RGB(0,0,0),0.1f,0.0f},
    		{320.0f,  0.0f,0.0f,0.8f,RGB(0,255,0),RGB(0,0,0),0.4f,0.8f}
| The (u/W) and (v/W) are set such that the texture map will cover each triangle.
    			        };
    int	       TriFaceData[][3] = {{0,1,2},{3,0,2}};
    int            Device,frame,run;

    void main ()
    {
    	Device = sgl_create_screen_device (0,640,480, sgl_device_16bit, TRUE);
    	if (Device >= 0)
    	{
    	    SGLContext.nTextureName=LoadBMPTexture("tex.bmp",FALSE,TRUE,TRUE);
    	    SGLContext.u32Flags=SGLTT_TEXTURE | SGLTT_MIPMAP;
| This loads a texture (from bitmap file "tex.bmp") using the LoadBMPTexture function, the three Booleans define translucency, auto mipmapping and dithering. The u32Flags parameter in SGLContext is set to include texturing and mipmapping.
    	    SGLContext.bFogOn=TRUE;
    	    SGLContext.fFogR=0.5f;
    	    SGLContext.fFogG=0.5f;
    	    SGLContext.fFogB=1.0f;
    	    SGLContext.u32FogDensity=16;
    	    for(run=1; run<5 ; run++)
    	    {
    	      for(frame=1; frame<128; frame++)
    	      {
    		Vertices[0].fX=(64-abs(frame-64))*10.0f-5.0f;
    		Vertices[2].fX=645.0f-(64-abs(frame-64))*10.0f;
    		sgltri_startofframe (&SGLContext);
    		sgltri_triangles    (&SGLContext, 2, TriFaceData, Vertices);
    		sgltri_render       (&SGLContext);
    	      }
                }
    	    sgl_delete_device(Device);
    	}
    }
You may view this source code. Go to PowerSGL Direct QuickStart Page 1 - 2 - 3 - 4 You may download this example (source and executable) [75 KB]

Confidential / provided under Non-Disclosure Agreement Copyright © 1999-2000, PowerVR Technologies and partners. PowerVR Technologies is a division of Imagination Technologies Limited.