Jump to content
  • Advertisement
Sign in to follow this  
subi

OpenGL D3D9 rendering help

This topic is 4735 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry guys i am fairly new to d3d, i currently use OpenGL and i am jsut trying to learn a bit of D3D just to see how the other side lives :-) i am trying to render a small mesh with the size of 64x64 (basically like a brute force terrain minus the y value) data:
struct Vertex3f
{
  float x,y,z;
};


Vertex3f *Vertices;
here is my init function
vertexcount = (m_iSize-1)*(m_iSize-1)*6;
	Vertices = new Vertex3f[vertexcount];

    
	//Build our vertex array
			for(int z=0,int i=0; z<m_iSize-1; z++ )
					{
						for( int x=0; x<m_iSize-1; x++ )
						{
						//Triangle 1
						Vertices.x = x;
						Vertices.y = 0;
						Vertices.z = z;
						i++;

						Vertices.x = x;
						Vertices.y = 0;
						Vertices.z = z+1;
						i++;
						Vertices.x = x+1;
						Vertices.y = 0;
						Vertices.z = z+1;
						i++;
						//triangle 2
						Vertices.x = x+1;
						Vertices.y = 0;
						Vertices.z = z+1;
						i++;

						Vertices.x = x+1;
						Vertices.y = 0;
						Vertices.z = z;
						i++;

						Vertices.x = x;
						Vertices.y = 0;
						Vertices.z = z;
						i++;
						primitivecount+=2;
						}
						
					}

	if( FAILED( m_d3D9dev->CreateVertexBuffer( vertexcount*sizeof(Vertex3f),
                                                  0, D3DFVF_XYZ,
                                                  D3DPOOL_DEFAULT, &g_pVertexBuffer, NULL ) ) )
    {
        return E_FAIL;
    }

	VOID* pVertices;
    if( FAILED( g_pVertexBuffer->Lock( 0, sizeof(Vertices), (void**)&pVertices, 0 ) ) )
        return E_FAIL;
    memcpy( pVertices, Vertices, sizeof(Vertices) );
    g_pVertexBuffer->Unlock();


Render source:
m_d3D9dev->SetStreamSource( 0, g_pVertexBuffer, 0, sizeof(Vertex3f) );
m_d3D9dev->SetFVF(D3DFVF_XYZ);
m_d3D9dev->DrawPrimitive( D3DPT_TRIANGLELIST, 0, primitivecount );

I am using the april 05 SDK with .net2003 ..i am running it with direct3d debugging and it is not spitting out any error's at all but i can not see the mesh. If i try to render say a simple triangle i can see that on screen perfectly, i am using my own camera class and it appears to move around correctly too (just judging by the way i can fly around the triangle) any idea's what i have stuffed up?? i have tried to follow Microsoft's samples as close as i could but obviouslly i am doing something wrong

Share this post


Link to post
Share on other sites
Advertisement
just an update:

i didn't notice this flag in CreateVertexBuffer() "D3DUSAGE_WRITEONLY" ..so i put that in there and now i get something on screen, although it looks like the vertices are a mess and is drawing lines everywhere in random directions? ...in GL i create the vertex array with the exact same code in the loop

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!