Archived

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

Dwiel

simple texturing problem

Recommended Posts

I have been trying to al a round high poly circle with d3d, and have finaly goten all of the indices correct, But for some reason I cann''t get a texture to be put on it. there are no error messages, but that nasty "this program has caused an error in ......". I will try to refrain from posting to much code, but if it is nessasary, I''ll post more. Hopefully I am just screwing up the API calls in the render method. by the way I am using the common framework files. Here is my Render: // Begin the scene if( SUCCEEDED( m_pd3dDevice->BeginScene() ) ) { m_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 64, 64, 255), 1.0, 0); m_pd3dDevice->SetTexture( 0, m_pWoodTexture ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); m_pd3dDevice->SetStreamSource( 0, m_pVB, sizeof(CUSTOMVERTEX) ); m_pd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX ); m_pd3dDevice->SetIndices( m_pIB, 0); m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, NUM_OF_VERTICES, // num of vertices 0, NUM_OF_PRIMITIVES); // num of primitives m_pd3dDevice->EndScene(); } if there are any problems with the above code, could you plz reply w/ the problem. Thanx ahead! Tazzel3D ~ Zach

Share this post


Link to post
Share on other sites
Are you sure your texture is valid? Can you apply the texture to a different (simple) object that you know displays correctly?

Sorry, not the biggest help, but before you go after deeper issues, it's good to make sure the basics work! :-)

Edited by - onnel on July 25, 2001 4:47:12 AM

Share this post


Link to post
Share on other sites
I went back and commented out my mesh generation code, and replaced it with a simple square, and the texture appeared. So now I think the problem is my code to gen. the texture coordinates. Hopefully someone can help me figure out what I did wrong with my algo for creating the tu and tv values of the mesh. Here is the code I used for generating the vertices. I hope I commented it enough!

CUSTOMVERTEX cvVerticesBoard[NUM_OF_VERTICES];
float beta = 0; // angle of point incremented by theta
float theta = 0; // angle to incriment beta by... same as the number of 360 deg. / vertices used in ring
float x = 0; // x value of vertex
float y = 0; // y value of vertex
int vertices = 0; // num of vertices in current ring
int vertex = 0; // current vertex
// set first vertex in middle of hexaMesh
cvVerticesBoard[0].x = 150.0f;
cvVerticesBoard[0].y = 150.0f;
cvVerticesBoard[0].z = 1.0f;
cvVerticesBoard[0].rhw = 1.0f;
cvVerticesBoard[0].tu = 0.5f;
cvVerticesBoard[0].tv = 0.5f;
vertex++; // increment vertex number
for (int a = 1; a < NUM_OF_RINGS; a++)
{
vertices = a * 6; // number of vertices in ring
theta = float(360 / vertices); // angle between vertices
beta = 0; // start points at 0 dge.
// loop from first vertex of this ring to
// (first vertex of next ring - 1) or (last vertex of this ring
for (int b = FirstVertex(a - 1); b <= FirstVertex(a - 1) + vertices - 1; b++)
{
beta += theta; // increment beta by the angle inbetween each vertex
// compute x coordinate:
// sin(90 - beta) - use (90 - beta) so it retrieves the sin of the opposite angle
// (D3DX_PI / 180) - converts Degrees to radians
// (5 * a) * - moves point away from center by 5 * ring number
// 150 + - offset to move point away from upper left corner
x = float(150 + ((5 * a) * sin((90 - beta) * (D3DX_PI / 180))));
// compute x coordinate:
// sin(beta) - retrieve sin of beta
// (D3DX_PI / 180) - converts Degrees to radians
// (5 * a) * - moves point away from center by 5 * ring number
// 150 + - offset to move point away from upper left corner
y = float(150 + ((5 * a) * sin((beta) * (D3DX_PI / 180))));
cvVerticesBoard[vertex].x = x;
cvVerticesBoard[vertex].y = y;
cvVerticesBoard[vertex].z = 1.0f;
cvVerticesBoard[vertex].rhw = 1.0f;
// cvVerticesBoard[vertex].color = color;
// scales x and y values to numbers between 0 and 1
cvVerticesBoard[vertex].tu = (1 + (x - 150) / (5 * (NUM_OF_RINGS - 1))) / 2;
cvVerticesBoard[vertex].tv = (1 + (y - 150) / (5 * (NUM_OF_RINGS - 1))) / 2;
vertex++; // increment vertex number
}
}
I hope the lines aren''t to long. I hate formating the text in this box that isn''t even the same size that everyone will see it in! arg... Anyway.. I briefly looked over the tu and tv WORDs that the code output, and they were all inbetween 0.0 and 1.0 so thats not a problem... I just can''t figure it out. Hopefully it is just one of those problems that you must view from an angle that my brain doesn''t like viewing from. Anyway. I hope someone can figure it. cause I sure can''t!

Thanx ahead!

P.S. Even though onnel your post was basic, at least it pointed me in right direction!

Share this post


Link to post
Share on other sites
I just love Programming! Especially that great feeling you get that after spending hours trying to figure out what''s wrong with some code, and then realize that you forgot to put the path name in font of the texture you were trying to load. It is that urge to just go slam your head against the ground awhile so that maybe next time you''ll be stupid enough to catch the mistake!

actually I havn''t figured it all out. One problem I get is that the circle, or suposedly circle, has a chunk missing from one side. It''s not a strait cut, but a mostly strait cut with a little bump in the middle. A little hard to explain. anyway I think the problem is in the algo for creating the vertices even though it is unchanged from when I was just applying a color to it. I have no clue as to what I did. hopefully I can do some undoing.

thanx aheadto the person/s who can glance at the above code and try helping me what the heck''s wrong with it.

Share this post


Link to post
Share on other sites