Jump to content
  • Advertisement
Sign in to follow this  
ryt

I cant nothing on my screen

This topic is 3717 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Today I bilt this app in Direcx9 but I see nothing. I only try to draw simple triangle with 3 vertices. Everything compiles and should be ok but i dont see any vertices. I clear the buffer (render target) to a 0xff888888 and this is the only thing that is working. Here is the code:
#include <d3dx9.h>

IDirect3DDevice9 *pDevice = 0;
IDirect3DVertexBuffer9 *pBSplineVertexBuffer = 0;
const int width  = 640;
const int height = 480;
class vector3
{
public:
	vector3(float x, float y, float z, D3DXCOLOR color)
	{
		_x = x; _y = y; _z = z; _color = color;
	}
	float _x, _y, _z;
	D3DXCOLOR _color;
	static const DWORD FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
};

bool Setup()
{
	pDevice->CreateVertexBuffer(sizeof(vector3)*3,
		D3DUSAGE_WRITEONLY,
		vector3::FVF,
		D3DPOOL_MANAGED,
		&pBSplineVertexBuffer,
		0);

	vector3 *pVertices = 0;
	pBSplineVertexBuffer->Lock(0, 0, (void**)&pVertices, 0);
	pVertices[0] = vector3(-5.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255, 100, 255, 200));
	pVertices[1] = vector3(0.0f, 5.0f, 0.0f, D3DCOLOR_ARGB(255, 255, 100, 200));
	pVertices[2] = vector3(5.0f, 0.0f, 0.0f, D3DCOLOR_ARGB(255, 200, 100, 255));
	pBSplineVertexBuffer->Unlock();

	D3DXVECTOR3 vEye(0.0f, -10.0f, 0.0f);
	D3DXVECTOR3 vLookAt(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 vUp(0.0f, 1.0f, 0.0f);
	D3DXMATRIX mView;
	D3DXMatrixLookAtLH(&mView, &vEye, &vLookAt, &vUp);
	pDevice->SetTransform(D3DTS_VIEW, &mView);

	D3DXMATRIX mProj;
	D3DXMatrixPerspectiveFovLH(&mProj, D3DX_PI/4.0f, (float)width / (float)height,
		1.0f, 100.0f);
	pDevice->SetTransform(D3DTS_PROJECTION, &mProj);

	pDevice->SetRenderState(D3DRS_LIGHTING, false);
	pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

	return true;
};
bool Display(float timeDelta)
{
	pDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
		0xff888888, 1.0f, 0);

	D3DXMATRIX mCurve;
	D3DXMatrixIdentity(&mCurve);
	pDevice->SetTransform(D3DTS_WORLD, &mCurve);
	pDevice->BeginScene();
	pDevice->SetFVF(vector3::FVF);
	pDevice->SetStreamSource(0, pBSplineVertexBuffer, 0, sizeof(vector3));
	pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
	pDevice->EndScene();

	pDevice->Present(0, 0, 0, 0);

	return true;
};

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch( msg )
	{
	case WM_DESTROY:
		::PostQuitMessage(0);
		break;
		
	case WM_KEYDOWN:
		if( wParam == VK_ESCAPE )
			::DestroyWindow(hwnd);
		break;
	}
	return ::DefWindowProc(hwnd, msg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd)
{

	//initialize win and directx
	WNDCLASS wc;

	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = (WNDPROC)WndProc; 
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = hinstance;
	wc.hIcon         = LoadIcon(0, IDI_APPLICATION);
	wc.hCursor       = LoadCursor(0, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wc.lpszMenuName  = 0;
	wc.lpszClassName = "Direct3D9App";

	RegisterClass(&wc);

	HWND hwnd = 0;
	hwnd = ::CreateWindow("Direct3D9App", "Direct3D9App", 
		WS_EX_TOPMOST,
		0, 0, width, height,
		0 /*parent hwnd*/, 0 /* menu */, hinstance, 0 /*extra*/); 

	::ShowWindow(hwnd, SW_SHOW);
	::UpdateWindow(hwnd);



	HRESULT hr = 0;

	IDirect3D9* d3d9 = 0;
    d3d9 = Direct3DCreate9(D3D_SDK_VERSION);

	D3DCAPS9 caps;
	d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);

	int vp = 0;
	vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;

	D3DPRESENT_PARAMETERS d3dpp;
	d3dpp.BackBufferWidth            = width;
	d3dpp.BackBufferHeight           = height;
	d3dpp.BackBufferFormat           = D3DFMT_A8R8G8B8;
	d3dpp.BackBufferCount            = 1;
	d3dpp.MultiSampleType            = D3DMULTISAMPLE_NONE;
	d3dpp.MultiSampleQuality         = 0;
	d3dpp.SwapEffect                 = D3DSWAPEFFECT_DISCARD; 
	d3dpp.hDeviceWindow              = hwnd;
	d3dpp.Windowed                   = true;
	d3dpp.EnableAutoDepthStencil     = true; 
	d3dpp.AutoDepthStencilFormat     = D3DFMT_D24S8;
	d3dpp.Flags                      = 0;
	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
	d3dpp.PresentationInterval       = D3DPRESENT_INTERVAL_IMMEDIATE;

	hr = d3d9->CreateDevice(
		D3DADAPTER_DEFAULT, 
		D3DDEVTYPE_HAL,         
		hwnd,               
		vp,                 
	    &d3dpp,             
	    &pDevice);  

	d3d9->Release();

	Setup();
		
	//start display loop
	MSG msg;
	::ZeroMemory(&msg, sizeof(MSG));

	static float lastTime = (float)timeGetTime(); 

	while(msg.message != WM_QUIT)
	{
		if(::PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			::TranslateMessage(&msg);
			::DispatchMessage(&msg);
		}
		else
        {	
			float currTime  = (float)timeGetTime();
			float timeDelta = (currTime - lastTime)*0.001f;

			Display(timeDelta);

			lastTime = currTime;
        }
	}

	pBSplineVertexBuffer->Release();
	pDevice->Release();

	return 0;
}

Share this post


Link to post
Share on other sites
Advertisement
Didn't check all of your code but your eye point is incorrect to see the triangle.

Change you eyept to (0,0,-10).

Your triangle faces z = -1 but your eyepoint is below the triangle looking up.

Did you just make a typo in your eyepoint? [smile]

Share this post


Link to post
Share on other sites
yeah, thats it, thx wery much, all day i was spending time on this trying different things :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!