#### Archived

This topic is now archived and is closed to further replies.

# Texturing problems

## Recommended Posts

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_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);

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.

##### Share on other sites

g_pDevice->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

I''m not sure if this will fix it, but that line is illegal.

You can''t disable the alpha for an active stage. Try:

g_pDevice->SetTextureStageState (0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
g_pDevice->SetTextureStageState (0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);

Stay Casual,

Ken
Drunken Hyena

##### Share on other sites
You should also be using the Debug runtime which will kick out informative info to the debugger. Make sure the debug runtime is installed, and go to the control panel and crank up the D3D debug level.

Stay Casual,

Ken
Drunken Hyena

##### Share on other sites
From the dx8 docs... "One significant requirement that the system places on how you format your vertices is on the order in which the data appears."

I think you''re placing the texCoords before the diffuse colour...

float x, y, z;
float u, v;
DWORD colour

should be...

float x, y, z;
DWORD colour
float u, v;

##### Share on other sites
Spoof: I think you''re wrong there I think that you define the order in which the components are sent to the 3dcard in the FVF and since his FVF is D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_DIFFUSE and he orders his components as

float v1,v2,v3
float tu,tv
dword colour

it should work... my guess would be that you might have done something wrong with your matrices have you managed to draw a colored shape before so you know that that''s not the problem... more info please

// fredrik

##### Share on other sites

Having not tried it any other way, I can only quote the Microsoft docs:

"One significant requirement that the system places on how you format your vertices is on the order in which the data appears. The following illustration depicts the required order for all possible vertex components in memory, and their associated data types."

And the illustration lists the components as:
Position
RHW
Weights (...)
Normal
Diffuse
Specular
TexCoords (1..8)

An FVF code is just a bitmask made up from predefined values, so it doesn''t matter what order you put them in - they always produce the same result. Only the D3DFVF_TEXCOORDSIZE macros produce order-dependant flags.

##### Share on other sites
quote:
Spoof: I think you''re wrong there I think that you define the order in which the components are sent to the 3dcard in the FVF and since his FVF is D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_DIFFUSE and he orders his components as

float v1,v2,v3
float tu,tv
dword colour

it should work... my guess would be that you might have done something wrong with your matrices have you managed to draw a colored shape before so you know that that''s not the problem... more info please

// fredrik

Yeah, I''ve had a spinning triangle on the screen just before I tried changing the code to allow texturing. DrunkenHyena, that didn''t work, although now I''ve tried taking all my texturing code out the quad isn''t drawn at all anyway, leading me to believe that the problem is elsehwere, perhaps in a line I changed by accident.

*sigh* - You may here from me again soon.

• ### Forum Statistics

• Total Topics
628401
• Total Posts
2982463

• 9
• 10
• 9
• 19
• 24