Skip to main content
gamedev.net
🔒 Locked

SetTexture - P.I.T.A. issue

Started by Zern Apr 22, 2003 at 8:34 PM 5 replies 900+ views
Original Post
Zern
Zern
Hello, first I''d like to refer you to this image P.I.T.A. Problem Now the problem is, I use SetTexture( 0, m_pTexture ) and use that image for both quads (see image above) now the problem is ... I SetTexture before drawing either of the items, and SetTexture( 0, NULL ); ONLY after both are drawn ... both have the same exact code for drawing and same offsets in the image ... however as you can see the second quad is not textured and is transparent grey which is a bit odd as the vertices color is white (255,255,255,255) ... anyone ever run across this problem before? Any insight is thanked, and thanks in advanced. ~
sporff
sporff
looks like texture coords aren''t set right
Zern
Zern
Exactly my thoughts until I changed the order of which was rendered first .... if I flip them around one is textured and the other isn''t :/ big pain in the *** if you ask me. thanks though for your thoughts!


~
Peon
Peon
I just textured my first quad yesterday (Woohoo!) so no guarantee on my suggestion I assume you use D3DXCreateTextureFromFile() or D3DXCreateTextureFromFileEx () to create your tecture... do you use make only one call to the function, and then use that same texture for both images? Or do you make separate calls? If the answer is the latter, perhaps you should check that the image you''re loading is actually there.

Maybe you could post some code as well?
Peon
Zern
Zern
Congratulations Small task but one to be very proud of your first time doing it (I was!) :D.


And yes, I''m using D3DXCreateTextureFromFileEx(). As for code there is just way too much to post :/. All I am doing is creating a normal quad, four vertices, 6 indices, setting the TU and TV correctly (shown in the image above, as both quads use the same code - it is not a texture coord problem - or I think it''s not ) and just rendering them. Guess DX hates me >



Thanks for your input Peon.


~
S1CA
S1CA

1) Try removing all SetTexture( n, NULL ); just to make sure (its not necessary every frame anyway)...

2) Could anything be releasing one of the textures ?

3) Whether a "white" vertex colour has any affect depends on what you''ve done in your SetTextureStageState() calls.

4) Do you do ANYTHING with D3D in between the rendering of the two - change any matrices, enable projected textures etc?.

5) If the vertices are D3DFVF_XYZRHW style, then make sure the RHW for the second set isn''t coming out as 0 - that''d have that effect.

6) Does the debug D3D runtime tell you anything ?

7) Does the FVF code for the two quads differ at all ? - if so, make sure the elements of the structure you use are a)of the correct sizes (i.e. a colour is a DWORD, not 4 floats) and b)in the correct order (i.e. position first, then normals, then colours, then texture coords etc).

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
Zern
Zern
Simon, thank you for your awesome in depth thoughts for everyone you attempt to help, very greatful for your time, however .... the problem was none of those you stated or any of those that others stated ...


For those curious here was the problem.


The quads in the image above are part of my GUI I'm creating, and both were of a type CGUIButton. Inside CGUIButton I have a function: "SetTextureOff(void)" which is called right before the rendering of the vertices. Now inside that SetTextureOff the code was like this:



    
HRESULT CGUIButton::SetTextureOffset(void)
{

static ButtonState LastState = Invalid;
//: Calculate the size of the button

static float fButtonWidth = float(m_rectWindow.right - m_rectWindow.left) / 256.0f;
static float fButtonHeight = float(m_rectWindow.bottom - m_rectWindow.top) / 256.0f;

HRESULT hr = 0;

//: Prevent from locking/unlocking vertices

//: every frame

if( LastState == m_nState )
return S_OK;
else
LastState = m_nState;


switch( m_nState )
{
case Up:
//: Top left point

m_Vertices[0].tu = m_fXTexelOff;
m_Vertices[0].tv = m_fYTexelOff;

// ...etc other states Down:Mouseover:Disabled etc.





As you can see ... I have a static variable which holds the last state of the button to prevent redudant calls to changing the texture-offsets and only to update if the state of the control changes. Now somehow I thought each button created from CGUIButton would call it's "own" SetTextureOffset and each have it's own LastState ... however this was not the case as when the first SetTextureOff was called, it would change the Invalid(state) of the variable to Up and would presist this state even when other Buttons I created called this function which I found out unfortunitly ... Upon creating the vertices I set the TU and TV both to 0.0 for each corner so I could say for example create a button that is "Disabled" upon created etc . Simple mistake but isn't it always the smallest ones that bite you in the arse and cause the most trouble?


Thanks again for all that gave their thoughts/input, happy coding.

~


Edit: Typos



[edited by - zern on April 23, 2003 10:43:50 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.