Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


DXUT Can not get anything rendered


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 monkeyboi   Members   -  Reputation: 188

Like
0Likes
Like

Posted 11 August 2012 - 03:59 PM

I am quite new to DXUT and all I want to do is just build up a sphere and render it, but there is nothing on the screen.

void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    HRESULT hr;
    // Clear the render target and the zbuffer
    V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 0, 0, 0 ), 1.0f, 0 ) );
	 pd3dDevice->SetRenderState(D3DRS_ZENABLE, true);
	 pd3dDevice->SetRenderState( D3DRS_LIGHTING, false );

    // Render the scene
    if( SUCCEEDED( pd3dDevice->BeginScene() ) )
    {
 
  	 D3DMATERIAL9 Mtrls;
 
  	 Mtrls.Diffuse.r = 0.3;
	   Mtrls.Diffuse.g = 0.1;
  	 Mtrls.Diffuse.b = 0.5;
  	 Mtrls.Diffuse.a = 0.9;
	   Mtrls.Ambient = Mtrls.Diffuse;
	   pd3dDevice->SetMaterial(&Mtrls);
 
  	 hr = pd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CW);
	  
	   D3DXMATRIX matWorld;
  	 D3DXMatrixRotationY(&matWorld, g_mThetaY);
	   pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
  	 g_Objects.at(0)->Draw();
	    V( pd3dDevice->EndScene() );
  	 g_mThetaY+=0.1;
    }
}

HRESULT hr;
hr = m_pDevice->SetStreamSource(0,m_pVB,0,sizeof(MESHVERTEX));
hr = m_pDevice->SetFVF(D3DFVF_MESHVERTEX);
hr = m_pDevice->SetIndices(m_pIB);
hr = m_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,iVQuantity,0,iTQuantity);

HRESULT CALLBACK OnD3D9CreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,
									 void* pUserContext )
{
HRESULT result;
g_pCamera = new CFirstPersonCamera();
// Setup the camera's view parameters
D3DXVECTOR3 vecEye( -20, 10.0f, 0.0f );
D3DXVECTOR3 vecAt ( 0.0f, 0.0f, 0.0f );
g_pCamera->SetViewParams( &vecEye, &vecAt );

// Setup the camera's project parameters
g_pCamera->SetProjParams(D3DX_PI/2.0,4.0/3.0,1.0,2000);//fov,aspect,near,far


pd3dDevice->SetTransform(D3DTS_VIEW, g_pCamera->GetViewMatrix());
pd3dDevice->SetTransform(D3DTS_PROJECTION,  g_pCamera->GetProjMatrix());

SphereMesh* Sphere01 = new SphereMesh(4,4,30,D3DXVECTOR3(0,0,0), pd3dDevice);
g_Objects.push_back(Sphere01);
}

#define D3DFVF_MESHVERTEX (D3DFVF_XYZ| D3DFVF_NORMAL| D3DFVF_DIFFUSE)
struct MESHVERTEX
{
float x, y, z;
float nx, ny, nz;
D3DXCOLOR rgba;
};

SphereMesh::SphereMesh(int iYSamples, int iRadialSamples, float fRadius, D3DXVECTOR3 Pos, IDirect3DDevice9* pDevice){
m_pDevice = pDevice;
m_Pos = Pos;
int iYSm1 = iYSamples-1, iYSm2 = iYSamples-2, iYSm3 = iYSamples-3;
int iRSp1 = iRadialSamples+1;
iVQuantity = iYSm2*iRSp1 + 2;
iTQuantity = 2*iYSm2*iRadialSamples;

MESHVERTEX* SphereVerts = new MESHVERTEX[iVQuantity];

// Generate geometry
float fInvRS = 1.0f/(float)iRadialSamples;
float fYFactor = 2.0f/(float)iYSm1;
int iR, iY, iYStart, i;
// Generate points on the unit circle to be used in computing the mesh
// points on a cylinder slice.
float* afSin = new float[iRSp1];
float* afCos = new float[iRSp1];
for (iR = 0; iR < iRadialSamples; iR++)
{
  float fAngle = 2*D3DX_PI*fInvRS*iR;
  afCos[iR] = cos(fAngle);
  afSin[iR] = sin(fAngle);
}
afSin[iRadialSamples] = afSin[0];
afCos[iRadialSamples] = afCos[0];
// Generate the cylinder itself
for (iY = 1, i = 0; iY < iYSm1; iY++)
{
  float fYFraction = -1.0f + fYFactor*iY;  // in (-1,1)
  float fY = fRadius*fYFraction;
  // Compute center of slice
  D3DXVECTOR3 kSliceCenter(0.0f,fY,0.0f);
  // Compute radius of slice
  float fSliceRadius = sqrt(fabs(fRadius*fRadius-fY*fY));
  // Compute slice vertices with duplication at end point
  D3DXVECTOR3 kNormal;
  int iSave = i;
  for (iR = 0; iR < iRadialSamples; iR++)
  {
   //float fRadialFraction = iR*fInvRS;  // in [0,1)
   D3DXVECTOR3 kRadial(afCos[iR],0.0f,afSin[iR]);
   SphereVerts[i].x = kSliceCenter.x + fSliceRadius*kRadial.x;
   SphereVerts[i].y = kSliceCenter.y + fSliceRadius*kRadial.y;
   SphereVerts[i].z = kSliceCenter.z + fSliceRadius*kRadial.z;
  
   kNormal.x = SphereVerts[i].x;
   kNormal.y = SphereVerts[i].y;
   kNormal.z = SphereVerts[i].z;
   D3DXVec3Normalize(&kNormal,&kNormal);
   SphereVerts[i].nx = kNormal.x;
   SphereVerts[i].ny = kNormal.y;
   SphereVerts[i].nz = kNormal.z;
  
   SphereVerts[i].rgba = D3DXCOLOR(0.5,0.5,0.5,0.5);
   i++;
  }
  SphereVerts[i] = SphereVerts[iSave];
  i++;
}
// South pole
SphereVerts[i].x = 0;
SphereVerts[i].y = -fRadius;
SphereVerts[i].z = 0;
SphereVerts[i].nx = 0;
SphereVerts[i].ny = -1;
SphereVerts[i].nz = 0;
SphereVerts[i].rgba = D3DXCOLOR(0.5,0.5,0.5,0.5);
i++;
// North pole
SphereVerts[i].x = 0;
SphereVerts[i].y = fRadius;
SphereVerts[i].z = 0;
SphereVerts[i].nx = 0;
SphereVerts[i].ny = 1;
SphereVerts[i].nz = 0;
SphereVerts[i].rgba = D3DXCOLOR(0.5,0.5,0.5,0.5);
i++;
assert( i == iVQuantity );
int a = sizeof(DWORD);
BYTE* lpVertices;
m_pDevice->CreateVertexBuffer(iVQuantity * sizeof(MESHVERTEX), D3DUSAGE_WRITEONLY,D3DFVF_MESHVERTEX,D3DPOOL_MANAGED,&m_pVB,0);

m_pVB->Lock( 0, iVQuantity*sizeof(MESHVERTEX), (void**)&lpVertices, 0 );
memcpy( lpVertices, &SphereVerts[0], iVQuantity*sizeof(MESHVERTEX) );
m_pVB->Unlock();
// generate connectivity
int iIQuantity = 3*iTQuantity;
m_aiIndex = new int[iIQuantity];
int* aiLocalIndex = m_aiIndex;
for (iY = 0, iYStart = 0; iY < iYSm3; iY++)
{
  int i0 = iYStart;
  int i1 = i0 + 1;
  iYStart += iRSp1;
  int i2 = iYStart;
  int i3 = i2 + 1;
  for (i = 0; i < iRadialSamples; i++, aiLocalIndex += 6)
  {
   aiLocalIndex[0] = i0++;
   aiLocalIndex[1] = i1;
   aiLocalIndex[2] = i2;
   aiLocalIndex[3] = i1++;
   aiLocalIndex[4] = i3++;
   aiLocalIndex[5] = i2++;
  }
}
// south pole triangles
int iVQm2 = iVQuantity-2;
for (i = 0; i < iRadialSamples; i++, aiLocalIndex += 3)
{
  aiLocalIndex[0] = i;
  aiLocalIndex[1] = iVQm2;
  aiLocalIndex[2] = i+1;
}
// north pole triangles
int iVQm1 = iVQuantity-1, iOffset = iYSm3*iRSp1;
for (i = 0; i < iRadialSamples; i++, aiLocalIndex += 3)
{
  aiLocalIndex[0] = i+iOffset;
  aiLocalIndex[1] = i+1+iOffset;
  aiLocalIndex[2] = iVQm1;
}

unsigned int uiBufferLength = (unsigned int)(iIQuantity*sizeof(short));
m_pDevice->CreateIndexBuffer(uiBufferLength,
  D3DUSAGE_WRITEONLY,D3DFMT_INDEX16,D3DPOOL_MANAGED,&m_pIB,0);
void* pbIndices;
m_pIB->Lock(0,uiBufferLength,&pbIndices,0);
memcpy( pbIndices, m_aiIndex, iIQuantity*sizeof(short) );
m_pIB->Unlock();
delete[] afCos;
delete[] afSin;
delete[] SphereVerts;
delete[] m_aiIndex;

There are two places I suspect.
1. Do vertex buffer and index buffer properly copy the mesh data?
2. Unproper material setting or lose material

Additionally the sphere index are built up as counter clockwise while you are watching through the screen, which is why I use hr = pd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CW).

Sponsor:

#2 Ripiz   Members   -  Reputation: 529

Like
0Likes
Like

Posted 11 August 2012 - 04:40 PM

There's at least one issue (I didn't search anymore after finding it).

You create buffer as 16 bit indices:
m_pDevice->CreateIndexBuffer(uiBufferLength, D3DUSAGE_WRITEONLY,D3DFMT_INDEX16,D3DPOOL_MANAGED,&m_pIB,0);

But you have 32 bit indices:
m_aiIndex = new int[iIQuantity];

#3 monkeyboi   Members   -  Reputation: 188

Like
0Likes
Like

Posted 11 August 2012 - 04:53 PM

Thans Ripiz

After I change it to 32 it still can not get anything rendered

unsigned int uiBufferLength = (unsigned int)(iIQuantity*sizeof(int));
m_pDevice->CreateIndexBuffer(uiBufferLength,
  D3DUSAGE_WRITEONLY,D3DFMT_INDEX32,D3DPOOL_MANAGED,&m_pIB,0);
void* pbIndices;
m_pIB->Lock(0,uiBufferLength,&pbIndices,0);
memcpy( pbIndices, m_aiIndex, iIQuantity*sizeof(int) );
m_pIB->Unlock();


#4 RulerOfNothing   Members   -  Reputation: 1164

Like
0Likes
Like

Posted 11 August 2012 - 06:09 PM

After you call EndScene I believe you need to call the Present method like this:
pd3dDevice->Present(NULL,NULL,NULL,NULL);

#5 monkeyboi   Members   -  Reputation: 188

Like
0Likes
Like

Posted 11 August 2012 - 06:55 PM

I think you don't have to. Because in dxut Present() will be called after OnD3D9FrameRender

#6 Ripiz   Members   -  Reputation: 529

Like
1Likes
Like

Posted 12 August 2012 - 01:17 AM

Sphere's radius is 30, while camera is at ( -20, 10.0f, 0.0f ) (which is about 22 units length), you can't see sphere because your camera is inside.

#7 monkeyboi   Members   -  Reputation: 188

Like
0Likes
Like

Posted 12 August 2012 - 10:13 AM

Found where was wrong just post here to share this careless mistake:

m_pDevice->CreateIndexBuffer(uiBufferLength,
D3DUSAGE_WRITEONLY,D3DFMT_INDEX16,D3DPOOL_MANAGED,&m_pIB,0);//Here D3DUSAGE_WRITEONLY should be exchanged to 0

Got one wired bug now: Some times the program could compile and run, other times it will say "Miscrosoft Incremental Linker Has stopped working" and has link error as
LINK : fatal error LNK1000: Internal error during IncrBuildImage
1> Version 9.00.21022.08
1> ExceptionCode = C0000005
1> ExceptionFlags = 00000000
1> ExceptionAddress = 0129FCF7 (01220000) "j:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\link.exe"
1> NumberParameters = 00000002
1> ExceptionInformation[ 0] = 00000000
1> ExceptionInformation[ 1] = 011BD670
1>CONTEXT:
1> Eax = 401F3064 Esp = 0019EC64
1> Ebx = 4000815C Ebp = 0019EC8C
1> Ecx = 011BD670 Esi = 401F2EEC
1> Edx = 0019EC7C Edi = 0122D6C0
1> Eip = 0129FCF7 EFlags = 00010246
1> SegCs = 00000023 SegDs = 0000002B
1> SegSs = 0000002B SegEs = 0000002B
1> SegFs = 00000053 SegGs = 0000002B
1> Dr0 = 00000000 Dr3 = 00000000
1> Dr1 = 00000000 Dr6 = 00000000
1> Dr2 = 00000000 Dr7 = 00000000

Then build solution again, there will be a warning

1>Linking...
1>Embedding manifest...
1>.\DXUT\Core\dpiaware.manifest : manifest authoring warning 81010002: Unrecognized Element "application" in namespace "urn:schemas-microsoft-com:asm.v3".

and points to here
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>

What is this problem? and how could I solve it?

Thanks in advance.

Jerry

#8 dimitri.adamou   Members   -  Reputation: 329

Like
0Likes
Like

Posted 12 August 2012 - 03:07 PM

Either install http://www.microsoft...s.aspx?id=10986 or turn off Incremental Linking, this is a Compiler Issue. Well thats just assuming from your posted log, what version visual studio are you running?

Edited by dimitri.adamou, 12 August 2012 - 03:08 PM.


#9 monkeyboi   Members   -  Reputation: 188

Like
0Likes
Like

Posted 13 August 2012 - 05:27 AM

Ok Thanks Adamou

I have turn it off. Seems there is no problem now.

Jerry




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS