Original Post
Hi,
I''m using the Dx 8.1 SDK with Dev-CPP, and have been following the Nexe tutorials.
I try to draw a quad on the screen with a texture (I''ve tried BMP''s and JPG''s) but the texture never gets drawn. I know the texture gets loaded however, else an error message would be displayed (the texture''s dimensions are both a power of two).
My vertex class looks like this:
class Vertex {
public:
float x, y, z;
float u, v;
DWORD colour;
void setVertexPosition (float X, float Y, float Z) {
z = Z;
y = Y;
z = Z;
}
void setUVCoords (float U, float V) {
u = U;
v = V;
}
void setColour (float R, float G, float B) {
colour = D3DCOLOR_XRGB ((BYTE) R * 255, (BYTE) G * 255, (BYTE) B * 255);
}
};
My FVF is like this:
const DWORD D3DFVF_Vertex = D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_DIFFUSE;And my texture / vertex parameter settings are like this:
g_vQuad [0].setColour (0.0, 0.0, 0.0);
g_vQuad [0].setUVCoords (0.0, 0.0);
g_vQuad [0].setVertexPosition (-1.0, 1.0, 0.0);
g_vQuad [1].setColour (0.0, 0.0, 0.0);
g_vQuad [1].setUVCoords (1.0, 0.0);
g_vQuad [1].setVertexPosition (1.0, 1.0, 0.0);
g_vQuad [2].setColour (0.0, 0.0, 0.0);
g_vQuad [2].setUVCoords (1.0, 1.0);
g_vQuad [2].setVertexPosition (1.0, 0.0, 0.0);
g_vQuad [3].setColour (0.0, 0.0, 0.0);
g_vQuad [3].setUVCoords (0.0, 1.0);
g_vQuad [3].setVertexPosition (-1.0, 0.0, 0.0);
g_pDevice->SetRenderState (D3DRS_CULLMODE, D3DCULL_NONE);
g_pDevice->SetRenderState (D3DRS_LIGHTING, FALSE);
g_pDevice->SetTextureStageState (0, D3DTSS_COLOROP, D3DTOP_MODULATE);
g_pDevice->SetTextureStageState (0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
g_pDevice->SetTextureStageState (0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
g_pDevice->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
g_hResult = D3DXCreateTextureFromFile (g_pDevice, "test.bmp", &g_texTexture);
And drawn like this, and called between BeginScene and EndScene:
g_pDevice->SetVertexShader (D3DFVF_Vertex);
g_pDevice->SetTexture (0, g_texTexture);
g_pDevice->DrawPrimitiveUP (D3DPT_TRIANGLESTRIP, 4, g_vQuad, sizeof g_vQuad [0]);
I''m sorry about the length of this post, but I''m new to D3D, having moved from OpenGL, and the whole thing with the FVF is pretty weird at first, not to mention having texture loading almost as part of the library :-)
Can anyone see my mistake?
g_vQuad is an array of Vertex.
Many thanks in advance.