1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
const DWORD D3DFVF_TLVERTEX = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1;
struct TLVERTEX
{
float x;
float y;
float z;
D3DCOLOR colour;
float u;
float v;
};
IDirect3DTexture9* Texture::LoadTexture(char *fileName) {
IDirect3DTexture9 *d3dTexture;
D3DXIMAGE_INFO SrcInfo;
D3DCOLOR colorkey = 0xFFFF00FF;
// Load image from file
if (FAILED(D3DXCreateTextureFromFileEx (d3dDevice, fileName, 0 , 0, 0, 0,
D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, D3DX_FILTER_LINEAR, D3DX_DEFAULT,
colorkey, &SrcInfo, NULL, &d3dTexture)))
{
return NULL;
}
imageWidth = SrcInfo.Width;
imageHeight = SrcInfo.Height;
//Return the newly made texture
return d3dTexture;
}
void TexturedRectangleView::draw() {
//TLVERTEX* vertices;
//Lock the vertex buffer
textureVertexBuffer->Lock(0, 0, (void **)&vertices, NULL);
D3DCOLOR vertexColour = D3DCOLOR_XRGB( 255, 255, 255);
//Setup vertices
//A -0.5f modifier is applied to vertex coordinates to match texture and screen coords
//Some drivers may compensate for this automatically, but on others texture alignment errors are introduced
//More information on this can be found in the Direct3D 9 documentation
float decal = 0.5f;
position.z = 0;
vertices[0].colour = vertexColour;
vertices[0].x = position.x- decal;
vertices[0].y = position.y+height- decal;
vertices[0].z = position.z;
vertices[0].u = 0.0f;
vertices[0].v = 0.0f;
vertices[1].colour = vertexColour;
vertices[1].x = position.x+width- decal;
vertices[1].y = position.y+height- decal;
vertices[1].z = position.z;
vertices[1].u = texture->width;
vertices[1].v = 0.0f;
vertices[2].colour = vertexColour;
vertices[2].x = position.x+width- decal;
vertices[2].y = position.y- decal;
vertices[2].z = position.z;
vertices[2].u = texture->width;
vertices[2].v = texture->height;
vertices[3].colour = vertexColour;
vertices[3].x = position.x- decal;
vertices[3].y = position.y- decal;
vertices[3].z = position.z;
vertices[3].u = 0.0f;
vertices[3].v = texture->height;
//Unlock the vertex buffer
textureVertexBuffer->Unlock();
//Set texture
d3dDevice->SetTexture (0, texture->data);
//Draw image
d3dDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 );
} |
Partager