• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
monkeyboi

DXUT Can not get anything rendered

8 posts in this topic

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.

[CODE]
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;
}
}
[/CODE]

[CODE]
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);
[/CODE]

[CODE]
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);
}
[/CODE]

[CODE]
#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;
[/CODE]

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).
0

Share this post


Link to post
Share on other sites
There's at least one issue (I didn't search anymore after finding it).

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

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

Share this post


Link to post
Share on other sites
Thans Ripiz

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

[CODE]
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();
[/CODE]
0

Share this post


Link to post
Share on other sites
After you call EndScene I believe you need to call [url=http://msdn.microsoft.com/en-us/library/windows/desktop/bb174423%28v=vs.85%29.aspx]the Present method[/url] like this:
pd3dDevice->Present(NULL,NULL,NULL,NULL);
0

Share this post


Link to post
Share on other sites
Sphere's radius is 30, while camera is at [i]( -20, 10.0f, 0.0f )[/i] (which is about 22 units length), you can't see sphere because your camera is inside.
1

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites
Either install [url="http://www.microsoft.com/en-us/download/details.aspx?id=10986"]http://www.microsoft...s.aspx?id=10986[/url] 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
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0