Page 1 of 1

How to draw 3d grid?

Posted: Fri Apr 15, 2005 12:05 am
by Guest
Hi, im a beginner to Irrlicht and C++. I started the splitscreen tutorial and edited it to have 3 wireframe and 1 textured camera, so what i want to have is a 3d grid like you see in all the 3d modelling programs, using Draw3dLine.
Anyone have an idea?

Posted: Fri Apr 15, 2005 12:56 am
by keless
sounds like you already have an idea. try it and if you have a specific problem come back and post it.

Well that didnt help much..

Posted: Fri Apr 15, 2005 4:44 am
by Aaron
Okay i got the lines to show up, but is there a better way than typing 25 Draw3dLine commands in a row for 25 lines?

Posted: Fri Apr 15, 2005 9:41 am
by Guest
Errr... for(line=0;line<25;line++) { etc. } ?

Posted: Fri Apr 15, 2005 11:24 am
by Vox
Yes, there is a better way. I have implemented drawIndexed3DLineList function for IVideoDriver.

Posted: Sat Apr 16, 2005 9:07 am
by markus
Hi Vox,
do you mind to share your code with us?

I've also written something that draws a 3D Grid.
But the Problem is, that it disappears from time to time when i move in the world. :?

Greetings
Markus

Posted: Sat Apr 16, 2005 5:29 pm
by SARIN
it might disapear depending on the render order. try setting it before the gui render and after the scene render

Posted: Sat Apr 16, 2005 6:28 pm
by Vox
markus wrote:Hi Vox,
do you mind to share your code with us?
Sure. You have to do rest by yourself. It is for NX++, but not implemented yet.

DIRECTX

Code: Select all

// draws an indexed 3D line list
void C_VIDEO_DIRECT_X::drawIndexed3DLineList(const S3DVertex* vertices, s32 vertexCount, const u16* indexList, s32 lineCount)
{
	if (!checkPrimitiveCount(vertexCount,lineCount))
		return;

	if(vertexCount > 0xFFFF)
	{
	  maxIndexWarning(16);
	}

	CVideoNull::drawIndexed3DLineList(vertices, vertexCount, indexList, lineCount);

	if (!vertexCount || !lineCount)
		return;

	setVertexShader(EVT_STANDARD);
	setRenderStates3DMode();

	DWORD state;
	  
	if(Material.Texture1)
	{
		pID3DDevice->GetTextureStageState(0, D3DTSS_COLOROP, &state);	
		pID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_DISABLE);	
	}

	if(Material.Lighting)
		pID3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
			
	pID3DDevice->DrawIndexedPrimitiveUP(	D3DPT_LINELIST, 0,
											vertexCount,
											lineCount,
											indexList,
											D3DFMT_INDEX16,
											vertices,
											sizeof(S3DVertex));
	if(Material.Lighting)
		pID3DDevice->SetRenderState(D3DRS_LIGHTING, TRUE);

	if(Material.Texture1)
		pID3DDevice->SetTextureStageState(0, D3DTSS_COLOROP, state);	
}
OPENGL

Code: Select all

//! draws an indexed line list
void CVideoOpenGLStub::drawIndexed3DLineList(const S3DVertex* vertices, s32 vertexCount, const u16* indexList, s32 lineCount)
{
	if(vertexCount > 0xFFFF)
	{
	  maxIndexWarning(16);
	}

	CVideoNull::drawIndexed3DLineList(vertices, vertexCount, indexList, lineCount);

	setRenderStates3DMode();

	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_VERTEX_ARRAY);

	// convert colors to gl color format.

	const S3DVertex* p = vertices;
	ColorBuffer.set_used(vertexCount);
	for (s32 i=0; i<vertexCount; ++i)
	{
		ColorBuffer[i] = p->Color.toOpenGLColor();
		++p;
	}

	// draw everything

	glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(video::SColor), &ColorBuffer[0]);
	glVertexPointer(3, GL_FLOAT, sizeof(S3DVertex),  &vertices[0].Pos);

	if(Material.Texture1)
	{
		extGlActiveTextureARB(GL_TEXTURE0_ARB);
		glDisable(GL_TEXTURE_2D);
	}

	if(Material.Lighting)
		glDisable(GL_LIGHTING);

	glDrawElements(GL_LINES, lineCount * 2, GL_UNSIGNED_SHORT, indexList);

	if(Material.Lighting)
		glEnable(GL_LIGHTING);

	if(Material.Texture1)
		glEnable(GL_TEXTURE_2D);
		
	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_VERTEX_ARRAY);
}