• 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
Hawkblood

Problem with DrawIndexedPrimitive

2 posts in this topic

I have two different scenes that are put together at the end. The first scene is the interior of my ship and the second is some terrain. The ship is a mesh rendered with Evolved's Normal mapping with multiple lights. The terrain is a triangle list rendered with DrawIndexedPrimitive. The problem is that the ship's interior doesn't render correctly. It only works correctly if I don't render the terrain (at all). Even when I had a condition to stop rendering the terrain, the ship's interior still had the same issue. Here is an image and the relevant code:

The terrain code:

void TERRAINSTRUCT::Show(GAMEENGINE *GE){
	D3DXMATRIX pm;
	D3DXMatrixPerspectiveFovLH(&pm, 
					D3DX_PI/4.0f,    // the horizontal field of view 
					SCREEN_WIDTH / SCREEN_HEIGHT, // aspect ratio 
					0.5f,    // the near view-plane 
					20000);    // the far view-plane 
	GE->d3ddev->SetTransform(D3DTS_PROJECTION, &pm);

	GE->d3ddev->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_RGBA (105,105,105,105) );
	GE->d3ddev->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_CURRENT );        
	GE->d3ddev->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_TEXTURE );        
	GE->d3ddev->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE2X );
	//do range0
	GE->d3ddev->SetMaterial(&DefaultMatl);
	GE->d3ddev->SetFVF(T_D3DFVF_CUSTOMVERTEX);
	for (int z=0;z<25;z++){
		for (int x=0;x<25;x++){

			if (Range0_1Index[x][z].type==0){//range0
				int i=Range0_1Index[x][z].index;
				D3DXMATRIX wm;
				D3DXMatrixIdentity(&wm);
				wm(3,0)=(float(x)-12.5f)*10.0f;
				wm(3,1)=-1.83f;
				wm(3,2)=(float(z)-12.5f)*10.0f;
				GE->d3ddev->SetTransform(D3DTS_WORLD,&wm);
				GE->d3ddev->SetTexture(0,TextureList[5].Texture);
				GE->d3ddev->SetTexture(1,TextureList[DetailImage].Texture);


				GE->d3ddev->SetStreamSource(0, Range0[i].pVertexObject, 0, sizeof(T_D3DVERTEX));
				GE->d3ddev->SetIndices(Range0[i].i_buffer);
				GE->d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 121, 0, 100*2);
			}

			if (Range0_1Index[x][z].type==1){//range1
				int i=Range0_1Index[x][z].index;
				D3DXMATRIX wm;
				D3DXMatrixIdentity(&wm);
				wm(3,0)=(float(x)-12.5f)*10.0f;
				wm(3,1)=-1.83f;
				wm(3,2)=(float(z)-12.5f)*10.0f;
				GE->d3ddev->SetTransform(D3DTS_WORLD,&wm);
				GE->d3ddev->SetTexture(0,TextureList[5].Texture);
				GE->d3ddev->SetTexture(1,TextureList[DetailImage].Texture);


				GE->d3ddev->SetStreamSource(0, Range1[i].pVertexObject, 0, sizeof(T_D3DVERTEX));
				GE->d3ddev->SetIndices(Range1[i].i_buffer);
				GE->d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 25, 0, 16*2);
			}

		}
	}

	GE->d3ddev->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
	GE->d3ddev->SetTexture(1,NULL);
	GE->d3ddev->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_RGBA (15,15,15,15) );
}

And here is the ship interior code:

void GAMEENGINE::RenderShipInt(){
	d3ddev->SetRenderTarget(0,fpRenderSurf);
	D3DXMatrixPerspectiveFovLH(&MyCamera.m_projMatrix, 
						   D3DX_PI/4.0f,    // the horizontal field of view 
						   SCREEN_WIDTH / SCREEN_HEIGHT, // aspect ratio 
						   0.5f,    // the near view-plane 
						   20000);    // the far view-plane 

	d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE,false);
	d3ddev->SetRenderState(D3DRS_ZWRITEENABLE, true);
	d3ddev->Clear(0,
                           NULL,
                           D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
                           D3DCOLOR_ARGB(0,0,255,0),
                           1.0f,
                           0);
	d3ddev->BeginScene();
	d3ddev->SetTransform(D3DTS_PROJECTION, &MyCamera.m_projMatrix);



	D3DXMATRIX tmp;
	D3DXMatrixIdentity(&tmp);
//	tmp=MyCamera.RotationMatrix;
	tmp(3,0)-=MyCamera.fpPosition.x;
	tmp(3,1)-=23;//MyCamera.fpPosition.y; 23
	tmp(3,2)-=MyCamera.fpPosition.z;

	FXManager.Effect[NormalMappingFX].FX->BeginParameterBlock();
	D3DXVECTOR4 v4( 0.1f, 0.1f, 0.1f, 0 );
	FXManager.Effect[NormalMappingFX].FX->SetVector("Ambient",&v4);

	v4=D3DXVECTOR4(-MyCamera.fpPosition.x,0,-MyCamera.fpPosition.z,0);

	FXManager.Effect[NormalMappingFX].FX->SetVector("LightPosition_1",&v4);
	v4=D3DXVECTOR4(0.35f,0.3f,0.25f,0);
	FXManager.Effect[NormalMappingFX].FX->SetVector("LightColor_1",&v4);
	FXManager.Effect[NormalMappingFX].FX->SetFloat("LightRange_1",10);
	FXManager.Effect[NormalMappingFX].FX->SetTechnique("Light1");
	FXManager.Effect[NormalMappingFX].FX->SetTexture("BaseTX",TextureList[ShipTexture[1].C].Texture);
//	FXManager.Effect[NormalMappingFX].FX->SetTexture("NormalTX",TextureList[ShipTexture[1].N].Texture);
	FXManager.Effect[NormalMappingFX].FX->SetTexture("NormalTX",TextureList[6].Texture);
	D3DXMATRIX wvp=tmp*MyCamera.m_fpViewMat*MyCamera.m_projMatrix;
	FXManager.Effect[NormalMappingFX].FX->SetMatrix("WorldVP",&wvp);
	FXManager.Effect[NormalMappingFX].FX->SetMatrix("World",&tmp);
	FXManager.Effect[NormalMappingFX].FX->SetMatrix("ViewInv",&(MyCamera.fpRotationMatrix*MyCamera.RotationMatrix));
	D3DXHANDLE H=FXManager.Effect[NormalMappingFX].FX->EndParameterBlock();
	FXManager.Effect[NormalMappingFX].FX->ApplyParameterBlock(H);
	UINT cPasses;
	FXManager.Effect[NormalMappingFX].FX->Begin(&cPasses,0);
//	d3ddev->SetTransform(D3DTS_WORLD,&tmp); don't need this
	for (UINT iPass = 0; iPass < cPasses; iPass++)
	{
		FXManager.Effect[NormalMappingFX].FX->BeginPass(iPass);

		MeshObject[ShipInt].ppMesh->DrawSubset(0);

		FXManager.Effect[NormalMappingFX].FX->EndPass();
	}
	FXManager.Effect[NormalMappingFX].FX->End();


	d3ddev->EndScene();
}

They both work just fine except that the ship's interior doesn't show the lighting properly.

 

By the way, when I take out the "DrawIndexedPrimitive" lines, the ship's interior renders fine......

Edited by Hawkblood
0

Share this post


Link to post
Share on other sites

Ok. I figured out what is causing it. Well, I think I did..... My terrain has 2 tex coordinate sets (tu,tv). One for the base texture and the other for the detail. When I set the "detail" tu,tv pair to 0,0 the ship interior renders correctly, but the terrain of course doesn't..... I wish someone would help me.sad.png

 

Here is my FVF info:

 

struct T_D3DVERTEX {float x, y, z; float nx,ny,nz; float tu1,tv1; float tu2,tv2;};
 

#define T_D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX2)


 

Edited by Hawkblood
0

Share this post


Link to post
Share on other sites

I really need help solving this......

 

I found an effect that will allow me to do detail, but using it kills the lighting for the terrain. If I knew how to write it I would add lighting to the effect..... Sadly I don't know enough to do this.sad.png

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