Skip to main content
gamedev.net
🔒 Locked

Why doesn't it render

Started by bcome Nov 20, 2003 at 3:56 PM 6 replies 500+ views
Original Post
bcome
bcome
I''ve been looking at my code for hours. And I cant figure out why it isn''t rendering. I turn on ambient lighting, enable the z-buffer, turn off culling. but it still wont render. I begin the scene (it works), i set the shader, set the stream source, then I draw the primitive, then I end the scene, switch to the backbuffer. But it still doesn''t work.
D3DXMATRIX proj;
//Set up projection matrix

D3DXMatrixPerspectiveFovLH(
		D3DXMatrixIdentity(&proj), //matrix

		D3DX_PI/4, //fovy

		float(this->m_Width) / float(this->m_Height), //aspect

		0.1f, //nearZ

		1000.0f); //farZ

Direct3DDevice8->SetTransform(D3DTS_PROJECTION, &proj);
//Set up view matrix

D3DXVECTOR3 eye(0.0f, 0.0f, -5.0f), where(0.0f, 0.0f, 0.0f), up(0.0f, 1.0f, 0.0f);
D3DXMatrixLookAtLH(
		D3DXMatrixIdentity(&proj), //matrix

		&eye, //eye

		&where, //where

		&up); //up

Direct3DDevice8->SetTransform(D3DTS_VIEW, &proj);

Direct3DDevice8->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 1.0f, 0);

if (SUCCEEDED(Direct3DDevice8->BeginScene()))
{
	Vertex *verts = 0;

	//generate new points


	if (SUCCEEDED(Point->Lock(0, sizeof(Vertex) * 3, (BYTE**) &verts, 0)))
	{
		for (int x = 0; x < 3; x++)
		{
			verts[x].x = float(rand()) * OneOverRAND_MAX;
			verts[x].y = float(rand()) * OneOverRAND_MAX;
			verts[x].z = float(rand()) * OneOverRAND_MAX;
			verts[x].diffuse = D3DCOLOR_XRGB(rand() & 255, rand() & 255, rand() & 255);
		}
		Point->Unlock();
	} else {
		OutputDebugString("Frame(): Locking of buffer failed.\n");
	}

	Direct3DDevice8->SetVertexShader(VertexFVF);
	Direct3DDevice8->SetStreamSource(0, Point, sizeof(Vertex));
	Direct3DDevice8->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 1);
	Direct3DDevice8->EndScene();
	Direct3DDevice8->Present(NULL, NULL, NULL, NULL);
} else {
		OutputDebugString("Frame(): Begin scene failed.\n");
}

return TRUE;
oh, i forgot to mention, I set the view & projection matrixes.
IDirect3DVertexBuffer *Point 

u r what u bcome
<!-- ................................ -->u r what u bcomeMy (XHTML
Sean Doherty
Sean Doherty
Where is your world matrix transformation?

_______________________________________
Understanding is a three edged sword...
_______________________________________Understanding is a three edged sword...Freelance Games - Home of XBLIG Starchonwww.FreelanceGames.com
Namethatnobodyelsetook
Namethatnobodyelsetook
The identity calls are not needed, but aren''t a problem. They return the matrix you passed in, and they are run first, so ignore the previous post.

You don''t need to call identity before calling the other functions, they write new values to matrices, not modify existing ones.

If you''re using DX9, change from SetVertexShader to SetFVF... that''s about all I can think of right now.
bcome
bcome
quote:
Original post by Namethatnobodyelsetook
...
If you're using DX9, change from SetVertexShader to SetFVF... that's about all I can think of right now.



I thought I made the variables clear enough, I am using DX8

quote:
Original post by Sean Doherty
Where is your world matrix transformation?



I need a world matrix, I thought by default it was well 0 (no rotations, position <0,0,0>), I'll check that.

EDIT: Nope I added a world transformation and it still isn't showing.

//...

D3DXMatrixTranslation(D3DXMatrixIdentity(&proj), 0.0f, 0.0f, 0.0f);
Direct3DDevice8->SetTransform(D3DTS_WORLD, &proj);




u r what u bcome


[edited by - bcome on November 20, 2003 7:20:02 PM]
<!-- ................................ -->u r what u bcomeMy (XHTML
Sean Doherty
Sean Doherty
quote:

I turn on ambient lighting



Since you don''t have your vertices don’t have normals; don''t you want the light source turned off? How is “OneOverRAND_MAX” defined; are you sure that the triangle is visible? Can you post your vertex format? Did you try clearing the screen with another color?


_______________________________________
Understanding is a three edged sword...
_______________________________________Understanding is a three edged sword...Freelance Games - Home of XBLIG Starchonwww.FreelanceGames.com
bcome
bcome
quote:
Original post by Sean Doherty
Since you don't have your vertices don’t have normals; don't you want the light source turned off? How is “OneOverRAND_MAX” defined; are you sure that the triangle is visible? Can you post your vertex format?




struct Vertex {
FLOAT x, y, z;
D3DCOLOR diffuse;
};
#define VertexFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE)
const float OneOverRAND_MAX = 1.0f / float(RAND_MAX);


quote:
Original post by Sean Doherty
Did you try clearing the screen with another color?



hmmm... didn't try that, but the color should show wouldn't it? I initially was tring to just render 3 points, and that didn't work either.

well, I gotta go for awhile... be back in a couple of hours and try again.



u r what u bcome


[edited by - bcome on November 20, 2003 8:14:03 PM]
<!-- ................................ -->u r what u bcomeMy (XHTML
Sean Doherty
Sean Doherty
I can't say for sure what was wrong with your code; I am guessing a combination of culling, lighting should be off, and the world transformation matrix. You should also be careful about using data structure names that could be reserved (ie. Point, vertex). The following is the modified code; it works on my machine.

Edit: The problem was the lighting; when you render the object without the lighting enabled, it renders as black; remember lighting has no effect on objects without normals.



#define VertexFVF44 (D3DFVF_XYZ | D3DFVF_DIFFUSE)

const unsigned int c_uiNumberOfVertices = 4;


LPDIRECT3DVERTEXBUFFER8 PointVB;
struct Vertex44
{
float x, y, z;
D3DCOLOR diffuse;
};

const float OneOverRAND_MAX = 1.0f / float(RAND_MAX);


m_pD3DDevice->CreateVertexBuffer(3 * sizeof(Vertex44), // VEXTEX_XYZ_DIFFUSE_NORMAL

D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC | D3DUSAGE_POINTS,
VertexFVF44,
D3DPOOL_DEFAULT,
&PointVB);



D3DXMATRIX proj;
//Set up projection matrix

D3DXMatrixPerspectiveFovLH( D3DXMatrixIdentity(&proj),
D3DX_PI/4, float(1024) / float(768),
0.1f, 1000.0f);
m_pD3DDevice->SetTransform(D3DTS_PROJECTION, &proj);
D3DXVECTOR3 eye(0.0f, 0.0f, -5.0f),
where(0.0f, 0.0f, 0.0f),
up(0.0f, 1.0f, 0.0f);
D3DXMatrixLookAtLH(D3DXMatrixIdentity(&proj),
&eye, &where, &up);
m_pD3DDevice->SetTransform(D3DTS_VIEW, &proj);

m_pD3DDevice->SetTexture(0,NULL);

m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 255, 1.0f, 0);

m_pD3DDevice->BeginScene();
Vertex44 *verts;
PointVB->Lock(0, 3* sizeof(Vertex44), (BYTE**) &verts, 0);

ZeroMemory(verts, sizeof(PointVB));


for (int x = 0; x < 3; x++)
{
verts[x].x = float(rand()) * OneOverRAND_MAX;
verts[x].y = float(rand()) * OneOverRAND_MAX;
verts[x].z = float(rand()) * OneOverRAND_MAX;
verts[x].diffuse = D3DCOLOR_XRGB(rand() & 255, rand() & 255, rand() & 255);
}

/*
verts[0].x = -10.0f;
verts[0].y = -10.0f;
verts[0].z = 10.0f;
verts[0].diffuse = D3DCOLOR_XRGB(255, 0, 0);

verts[1].x = -10.0f;
verts[1].y = 10.0f;
verts[1].z = 10.0f;
verts[1].diffuse = D3DCOLOR_XRGB(0, 255, 0);

verts[2].x = 50.0f;
verts[2].y = 50.0f;
verts[2].z = 10.0f;
verts[2].diffuse = D3DCOLOR_XRGB(0, 0, 255);
*/

PointVB->Unlock();

m_pD3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
m_pD3DDevice->SetRenderState( D3DRS_LIGHTING, TRUE);

D3DXMatrixIdentity(&matWorld);
m_pD3DDevice->SetTransform( D3DTS_WORLD, &matWorld );


m_pD3DDevice->SetVertexShader(VertexFVF44);
m_pD3DDevice->SetStreamSource(0, PointVB, sizeof(Vertex44));

m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 1);
m_pD3DDevice->EndScene();
m_pD3DDevice->Present(NULL, NULL, NULL, NULL);


_______________________________________
Understanding is a three edged sword...




[edited by - Sean Doherty on November 20, 2003 10:42:48 PM]
_______________________________________Understanding is a three edged sword...Freelance Games - Home of XBLIG Starchonwww.FreelanceGames.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.