Archived

This topic is now archived and is closed to further replies.

evergrowgames

Just starting, and having a problem with rending a triangle(DX 8.1)

Recommended Posts

evergrowgames    122
EDIT: Thanks for the tag help. The problem could be anywhere, so I added all of the code. It isn't commented very well, or very well structured, as I tend to do that after I hit a landmark(the first being actual rendering). Basically, I just get a huge red screen, and that's it. The debugger sys that nothing is wrong, so I think that it may just be a logic error of mine. The code should render a triangle, with a material added to it, but it just stays invisible. If anyone decides to help, I will be eternally grateful.
#define _WIN32_WINNT 0x0500

#include <objbase.h>
#include <windows.h>
#include <stdio.h>
#include <d3d8.h>
#include <d3dx8.h>


LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);



	//VertexStructure

	typedef struct {
	  FLOAT x, y, z;     
	  DWORD color;        
	} sVertex;
	#define VERTEXFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE)

	IDirect3D8 *g_D3D;
	D3DDISPLAYMODE d3ddm;
	D3DPRESENT_PARAMETERS d3dpp;
	IDirect3DDevice8 *g_D3DDevice;
	IDirect3DVertexBuffer8 *D3DVB;
	D3DXMATRIX matProj, matView, matWorld;

	D3DXVECTOR3 vecVP, vecTP, vecUP(0.0f, 1.0f, 0.0f);
		


	sVertex Verts[3] = {
		{   0.0f,  0.0f, 0.0f, 0xffff0000 },
		{  10.0f,  0.0f, 0.0f, 0xff0000ff },
		{  10.0f, 10.0f, 0.0f, 0xffffffff },
    };



int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{

	CoInitializeEx(NULL, COINIT_MULTITHREADED);


	
	WNDCLASSEX wcex = {sizeof(WNDCLASSEX), CS_CLASSDC, WindowProc, 0L, 0L, hInstance, NULL, NULL, NULL, NULL, "RPGUCLASS", NULL};

	RegisterClassEx(&wcex);

	
	HWND hWnd;

	hWnd = CreateWindow("RPGUCLASS", "RPGUNLIMITED v. 0.01 GOOD", WS_OVERLAPPEDWINDOW, 200, 200, 500, 400, NULL, NULL, hInstance,
		NULL);

	

	ShowWindow(hWnd, SW_SHOWNORMAL);
	UpdateWindow(hWnd);


	
	g_D3D = Direct3DCreate8(D3D_SDK_VERSION);

	d3ddm.Width = 1280;
	d3ddm.Height = 1024;
	d3ddm.RefreshRate = 0;
	d3ddm.Format = D3DFMT_A8R8G8B8;


	ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));

	d3dpp.Windowed = FALSE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP;
	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
	d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
	d3dpp.BackBufferFormat = d3ddm.Format;
	d3dpp.BackBufferHeight = 1024;
	d3dpp.BackBufferWidth = 1280;
	
	
	g_D3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_D3DDevice);


	vecVP.x = 0.0;
	vecVP.y = 0.0;
	vecVP.z = -100.0;
	vecTP.x = vecTP.y = vecTP.z = 0.0f;
		
	
	

	

	
	
	
	
	g_D3DDevice->CreateVertexBuffer(sizeof(sVertex) * 3, D3DUSAGE_WRITEONLY, VERTEXFVF, D3DPOOL_MANAGED, &D3DVB);

	
	
	BYTE *Ptr;

	D3DVB->Lock(0, 0, (BYTE**)&Ptr, 0);

	
	
	memcpy(Ptr, Verts, sizeof(Verts));

	D3DVB->Unlock();


	

	D3DMATERIAL8 d3dm;

	ZeroMemory(&d3dm, sizeof(D3DMATERIAL8));

	d3dm.Diffuse.r = d3dm.Ambient.r = 1.0f;
	d3dm.Diffuse.g = d3dm.Ambient.g = 1.0f;
	d3dm.Diffuse.b = d3dm.Ambient.b = 0.0f;
	d3dm.Diffuse.a = d3dm.Ambient.a = 1.0f;



	

	
	
	MSG Msg;

	ZeroMemory(&Msg, sizeof(MSG));

	while(Msg.message != WM_QUIT) {

		if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {

			TranslateMessage(&Msg);
			DispatchMessage(&Msg);
		} else {
  


			g_D3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 0, 0), 1.0f, 0 );


			g_D3DDevice->BeginScene();

			
			
			
			D3DXMatrixRotationZ(&matWorld, 1);
			g_D3DDevice->SetTransform(D3DTS_WORLD,&matWorld);

			D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 1.25, 1.0f, 1000.0f);
			g_D3DDevice->SetTransform(D3DTS_PROJECTION, &matProj);

			D3DXMatrixLookAtLH(&matView, &vecVP, &vecTP, &vecUP);
			g_D3DDevice->SetTransform(D3DTS_VIEW, &matView);
			
			
			
			

			g_D3DDevice->SetStreamSource(0, D3DVB, sizeof(sVertex));
			g_D3DDevice->SetVertexShader(VERTEXFVF);



			g_D3DDevice->SetMaterial(&d3dm);

			//loop


			g_D3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0 , 1);



			g_D3DDevice->EndScene();

			g_D3DDevice->Present(NULL, NULL, NULL, NULL);

		}
	}
	
	

	D3DVB->Release();
    g_D3DDevice->Release();

	g_D3D->Release();	


	UnregisterClass("RPGUCLASS", hInstance);


	CoUninitialize();



	return 0;
}




LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{

	switch(uMsg) {
	case WM_DESTROY:
		PostQuitMessage(0);
		break;

	default: return DefWindowProc(hWnd, uMsg, wParam, lParam);
	}

	return 0;
}




  
[edited by - evergrowgames on August 5, 2003 2:14:43 PM] [edited by - evergrowgames on August 5, 2003 2:55:55 PM] [edited by - evergrowgames on August 5, 2003 3:04:34 PM]

Share this post


Link to post
Share on other sites
RuntimeFailure    122
I dont know if this is linked to your problem but, you set your back buffer to a much higher size than your window size.

This could be causing your problem but, if not it still is draining memory that could be used elsewhere.


[edited by - RuntimeFailure on August 5, 2003 8:59:24 PM]

Share this post


Link to post
Share on other sites