• Advertisement
Sign in to follow this  

WitchavenDX is not Drawing TrisList

This topic is 4552 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

I'm new to DX and ran into a problem with drawing with trianglelist.
/*
 *		Direct3D Basecode Created By Ronny André Reierstad
 *		Window Code Originaly Created By Jeff Molofee 2000
 *		A HUGE Thanks To Fredric Echols For Cleaning Up
 *		And Optimizing This Code, Making It More Flexible!
 *		If You Want More DirectX 3D Source Code
 *		Visit Aron Tutorials http://www.morrowland.com/apron
 */

#include <windows.h>		// Header File For Windows
#include <d3dx9.h>		// Header File For DirectX 3D
#include <d3d9.h>		// Header File For DirectX 3D
#pragma comment(lib,"d3d9.lib")
typedef char Byte;
long cnt = 0;
	LPDIRECT3DVERTEXBUFFER9 m_pVB   = NULL      ; // Buffer to hold our vertices

#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)
//#define DEBUG_VS   // Uncomment this line to debug vertex shaders 
//#define DEBUG_PS   // Uncomment this line to debug pixel shaders 
#include <list>
#include <vector>
using namespace std;
#include <stdio.h>
#define PI 3.1415926538
#define M_PI 3.1415926538

float rot_y=0.0f;
struct vectors
{ 
	float x,y,z;
};
struct vertices
{
    float x, y, z, rhw;  // The transformed(screen space) position for the vertex.
    DWORD colour; 

};



const double DUKE3DCOORD_XSCALE = -1.0;
const double DUKE3DCOORD_YSCALE = 1.0;
const double DUKE3DCOORD_ZSCALE = -1.0 / 16;

// for non-face sprites
//
const double DUKE3DSPRITECOORD_XSCALE = 1.0 / 4;
const double DUKE3DSPRITECOORD_YSCALE = 1.0 / 4;

// for face sprites
//
const double DUKE3DFACESPRITECOORD_XSCALE = 1.0 / 5;
const double DUKE3DFACESPRITECOORD_YSCALE = 1.0 / 4;


class Art
{
public:
long artversion;
long numtiles;
long localtilestart;
long localtileend;
vector <short> tilesizx;
vector <short> tilesizy;
vector <long> picanm;
long palette[768];

void Read(char *filename);
void Convert();
void LoadPalette();

};

void Art::LoadPalette()
{
		long i;
		FILE *fil;

		fil = fopen("palette.dat","rb");
		fread(&palette[0],768,1,fil);
		fclose(fil);

}

void Art::Read(char *filename)
{
	FILE *fil;

	fil = fopen(filename,"rb");
	fread(&artversion,sizeof(long),1,fil);
    fread(&numtiles,sizeof(long),1,fil);
fread(&localtilestart,sizeof(long),1,fil);
fread(&localtileend,sizeof(long),1,fil);
for (int pb = 0; pb < localtileend-localtilestart+1; pb++)
{
tilesizx.push_back(0);
tilesizy.push_back(0);
picanm.push_back(0);
}
fread(&tilesizx[0],sizeof(short),localtileend-localtilestart+1,fil);
fread(&tilesizy[0],sizeof(short),localtileend-localtilestart+1,fil);
fread(&picanm[0],sizeof(long),localtileend-localtilestart+1,fil);

for (int tile=0; tile < localtileend-localtilestart+1; tile++)
for (int x = 0; x < tilesizx[tile]; x++)
for (int y = 0; y < tilesizy[tile]; y++)
{
	//fread (&dummy[,sizeof(long),1,
}
}
class Map 
{
public:
    // original engine's limits
    //
	long mapFormat,secCount,spriteCount,wallCount;
    enum
    {
        MAX_WALLS = 8192,
        MAX_SECTORS = 1024,
        MAX_SPRITES = 4096
    };
    
    // some bitmasks
    //
    enum
    {
        SECTORSTAT_PARALLAXING      = 0x0001,
        SECTORSTAT_SLOPED           = 0x0002,
        SECTORSTAT_SWAPXY           = 0x0004,
        SECTORSTAT_DOUBLESCALE      = 0x0008,
        SECTORSTAT_INVERTX          = 0x0010,
        SECTORSTAT_INVERTY          = 0x0020,
        SECTORSTAT_ALIGNTO1STWALL   = 0x0040,
        SECTORSTAT_VALIDMASK        = 0x007F,
        
        WALLSTAT_BLOCKINGWALL       = 0x0001,
        WALLSTAT_SWAPBOTTOMS        = 0x0002,
        WALLSTAT_ALIGNONBOTTOM      = 0x0004,
        WALLSTAT_INVERTX            = 0x0008,
        WALLSTAT_MASKINGWALL        = 0x0010,
        WALLSTAT_ONEWAYWALL         = 0x0020,
        WALLSTAT_BLOCKINGWALL2      = 0x0040,
        WALLSTAT_TRANSPARENT        = 0x0080,
        WALLSTAT_INVERTY            = 0x0100,
        WALLSTAT_INVERTALPHA        = 0x0200,
        WALLSTAT_VALIDMASK          = 0x03FF,
        
        SPRITESTAT_BLOCKINGSPRITE   = 0x0001,
        SPRITESTAT_TRANSPARENT      = 0x0002,
        SPRITESTAT_INVERTX          = 0x0004,
        SPRITESTAT_INVERTY          = 0x0008,
        SPRITESTAT_ONESIDED         = 0x0040,
        SPRITESTAT_REALCENTER       = 0x0080,
        SPRITESTAT_BLOCKINGSPRITE2  = 0x0100,
        SPRITESTAT_INVERTALPHA      = 0x0200,
        SPRITESTAT_INVISIBLE        = 0x8000,
        
        SPRITESTAT_TYPEMASK         = 0x0030,
        SPRITESTAT_FACESPRITE       = 0x0000,
        SPRITESTAT_WALLSPRITE       = 0x0010,
        SPRITESTAT_FLOORSPRITE      = 0x0020,
    };

	struct Sector
	{
		short		wallptr, wallnum;
		long		ceilingz, floorz;
		unsigned short		ceilingstat, floorstat;
		short		ceilingpicnum, ceilingheinum;
		signed char	ceilingshade;
		char        ceilingpal, ceilingxpanning, ceilingypanning;
		short		floorpicnum, floorheinum;
		signed char	floorshade;
		char        floorpal, floorxpanning, floorypanning;
		char		visibility;
		char        filler;
		short		lotag, hitag, extra;
	};

	struct Wall
	{
		long		x, y;
		short		point2, nextwall, nextsector;
		unsigned short       cstat;
		short		picnum, overpicnum;
		signed char	shade;
		char        pal, xrepeat, yrepeat, xpanning, ypanning;
		short		lotag, hitag, extra;
	};

    struct Sprite
    {
        long        x, y, z;
        unsigned short        cstat, picnum;
        signed char shade;
        char        pal, clipdist, filler;
        char        xrepeat, yrepeat;
        signed char xoffset, yoffset;
        short       sectnum, statnum;
        short       ang, owner, xvel, yvel, zvel;
        short       lotag, hitag, extra;
    };

    
public:

    
    void load(char *filename)
    {
        const int MAX_SECTORS = 1024;
        const int MAX_WALLS = 8192;
        const int MAX_SPRITES = 4096;
        
//        assert(sizeof(Sector) == 40);
//        assert(sizeof(Wall) == 32);
//        assert(sizeof(Sprite) == 44);
        

		FILE *f = fopen(filename,"rb");
        // load map format
        //
        fread(&mapFormat, 4,1,f);


            
        // load start position
        //
        fread(&m_startPos.x, 4,1,f);
        fread(&m_startPos.y, 4,1,f);
        fread(&m_startPos.z, 4,1,f);
		m_startPos.z /= 16;
        
         fread(&m_startAngle, 2,1,f);
        fread(& m_startSec , 2,1,f);
        
        // load sectors
        //
 
        fread(&secCount , 2,1,f);
        Sector sectors[MAX_SECTORS];
        fread(&sectors[0], sizeof(Sector), secCount,f);
        m_sectors.assign(sectors, sectors + secCount);
        
        // load walls
        //
        fread(&wallCount , 2,1,f);
        
        Wall walls[MAX_WALLS];
        fread(&walls[0], sizeof(Wall), wallCount,f);
        m_walls.assign(walls, walls + wallCount);
        
        // load sprites
        //
       fread(&spriteCount , 2,1,f);
        
        Sprite sprites[MAX_SPRITES];
        fread(sprites, sizeof(Sprite) , spriteCount,f);
        m_sprites.assign(sprites, sprites + spriteCount);
				fclose (f);
    }

    const vector<Sector> &sectors() const { return m_sectors; }
    const vector<Wall> &walls() const { return m_walls; }
    const vector<Sprite> &sprites() const { return m_sprites; }
    
    const vectors &startPos() const { return m_startPos; }
    const double startAngle() const { return m_startAngle / 2048.0; }
    int startSector() const { return m_startSec; }
    
public:
    vectors m_startPos;
    long m_startAngle;
    long m_startSec;
    
    vector<Sector> m_sectors;
    vector<Wall> m_walls;
    vector<Sprite> m_sprites;
};
Map playLevel;
vertices verts[playLevel.MAX_SECTORS*playLevel.MAX_WALLS];
Art tiles000;
Art tiles001;
Art tiles002;
Art tiles003;
Art tiles004;
Art tiles005;
Art tiles006;
Art tiles007;
Art tiles008;
Art tiles009;
Art tiles010;



HDC						hDC				= NULL;		// Private GDI Device Context
HWND					hWnd			= NULL;		// Holds Our Window Handle
HINSTANCE				hInstance;					// Holds The Instance Of The Application
LPDIRECT3D9				pD3D			= NULL;		// DirectX 3D Version 9
LPDIRECT3DDEVICE9		pD3DDevice		= NULL;		// DirectX 3D Rendering Device

bool	keys[256];			// Array Used For The Keyboard Routine
bool	active=TRUE;		// Window Active Flag Set To TRUE By Default
bool	fullscreen=TRUE;	// Fullscreen Flag Set To Fullscreen Mode By Default

LRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);	// Declaration For WndProc

void ReSizeD3DScene(int width, int height)				// Resize And Initialize The D3D Window
{
	if (height==0)										// Prevent A Divide By Zero By
	{
		height=1;										// Making Height Equal One
	}

	D3DXMATRIXA16 matProjection;						// Create A Projection Matrix

	// Calculate The Aspect Ratio Of The Window
	D3DXMatrixPerspectiveFovLH(&matProjection, 45.0f, (float)width/(float)height, 0.1f, 1000000.0f );

	pD3DDevice->SetTransform( D3DTS_PROJECTION, &matProjection );
	D3DXMatrixIdentity(&matProjection);					// Reset The Projection Matrix
}

int InitD3D()										   // All Setup For D3D Goes Here
{
	FILE *fil = fopen("whaven.dat","wb");

	pD3DDevice->SetRenderState(D3DRS_ZENABLE,  TRUE ); // Enable Z-Buffer (Depth Buffer)
    pD3DDevice->SetRenderState(D3DRS_CULLMODE, FALSE); // Disable Backface Culling
    pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE); // Disable Light

		playLevel.load("level1.map");
	tiles000.LoadPalette();
tiles000.Read("tiles000.art");
	tiles001.LoadPalette();
tiles001.Read("tiles001.art");
	tiles002.LoadPalette();
tiles002.Read("tiles002.art");
	tiles003.LoadPalette();
tiles003.Read("tiles003.art");
	tiles004.LoadPalette();
tiles004.Read("tiles004.art");
	tiles005.LoadPalette();
tiles005.Read("tiles005.art");
	tiles006.LoadPalette();
tiles006.Read("tiles006.art");
	tiles007.LoadPalette();
tiles007.Read("tiles007.art");
	tiles008.LoadPalette();
tiles008.Read("tiles008.art");
	tiles009.LoadPalette();
tiles009.Read("tiles009.art");
	tiles010.LoadPalette();
tiles010.Read("tiles010.art");
   	vertices dummy;
for(int i = 0; i < playLevel.secCount; i++)
	    {
	       int wallnum =  playLevel.m_sectors.wallnum;
	       
		   int CurWall = playLevel.m_sectors.wallptr;
	       for (int i2 = 0; i2 < wallnum; i2++)
		   {
			   
	
			   Map::Wall dukeWall = playLevel.m_walls[CurWall];
    
			   Map::Wall nextWall = playLevel.m_walls[playLevel.m_walls[CurWall].point2];
               CurWall = playLevel.m_walls[CurWall].nextwall;
    // readability
    //
 //   WallSegment& ceilingWS = pWall->ceilingSegment;
 //   WallSegment& floorWS = pWall->floorSegment;
  //  WallSegment& portalWS = pWall->portalSegment;

    const double ceilingZ = DUKE3DCOORD_ZSCALE * playLevel.m_sectors.ceilingz;
    const double floorZ   = DUKE3DCOORD_ZSCALE * playLevel.m_sectors.floorz;
    
    // begin/end vertices
    //
    vectors v1;
        v1.x = dukeWall.x * DUKE3DCOORD_XSCALE;
        v1.y = dukeWall.y * DUKE3DCOORD_YSCALE;
        v1.z = 0;
    vectors v2;
        v2.x = nextWall.x * DUKE3DCOORD_XSCALE;
        v2.y = nextWall.y * DUKE3DCOORD_YSCALE;
        v2.z = 0;
	   // vectors v1 = playLevel.mapPoint(wall.begin).floorVector();
	   // vectors v2 = map.mapPoint(wall.end).floorVector();
	    
        //glBegin(GL_LINES);
        	// wall
        	//
        	//if(!wall.isPortal())
        	//    glColor4d((i != 0 ? 1 : 0), 1, 1, 0.6);
        	//else
        	//    glColor4d(1, (i == 0 ? 1 : 0), 0, 0.6);
        	
        	//glVertex3d(v1.x, v1.y, v1.z);
        	//glVertex3d(v2.x, v2.y, v2.z);
 
		//verts.push_back(dummy);

		verts[cnt].x = v1.x;
		verts[cnt].z = v1.y;
		verts[cnt].y = ceilingZ;
		verts[cnt].rhw = 1.0f;
		verts[cnt].colour = D3DCOLOR_XRGB( 255, 255, 255);

		cnt++;
		//verts.push_back(dummy);
		verts[cnt].x = v1.x;
		verts[cnt].z = v1.y;
		verts[cnt].y = floorZ;
		verts[cnt].rhw = 1.0f;
		verts[cnt].colour = D3DCOLOR_XRGB( 255, 255, 255);

		cnt++;
		//		verts.push_back(dummy);
		verts[cnt].x = v2.x;
		verts[cnt].z = v2.y;
		verts[cnt].y = floorZ;
		verts[cnt].rhw = 1.0f;
		verts[cnt].colour = D3DCOLOR_XRGB( 255, 255, 255);

		cnt++;
        //	vectors wn = vectors(x, y, v1.z) + wall.ceilingSegment.normal * 100;
        	
        	//glColor4d(0, 1, 0, 0.6);
        	//glVertex3d(x, y, v1.z);
        	//glVertex3d(wn.x, wn.y, wn.z);
        	
        	// vertices normals
        	//
        //	vectors vn = v1 + map.mapPoint(wall.begin).normal * 100;
        	//glColor4d(0, 0, 1, 0.6);
        	//glVertex3d(v1.x, v1.y, v1.z);
        	//glVertex3d(vn.x, vn.y, vn.z);
       // glEnd();
		   }
	}
		fclose (fil);
					pD3DDevice->CreateVertexBuffer( 3*sizeof(verts),
                                                 0, D3DFVF_CUSTOMVERTEX,
                                                 D3DPOOL_DEFAULT, &m_pVB, NULL );
       VOID* pVertices;
    if( FAILED( m_pVB->Lock( 0, sizeof(verts), (void**)&pVertices, 0 ) ) )
        return E_FAIL;
    memcpy( pVertices, &verts[0], sizeof(verts) );
    m_pVB->Unlock(); 

	return TRUE;									   // Initialization Went OK
}

int DrawD3DScene()										// Here's Where We Do All The Drawing
{
    pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, // Clear Screen And Depth Buffer
								D3DCOLOR_COLORVALUE(0.7f,0.7f,1.0f,0.0f), 1.0f, 0 );
    D3DXMATRIX trans_matrix;
	D3DXMatrixTranslation(&trans_matrix,-playLevel.m_startPos.x,-playLevel.m_startPos.z,-playLevel.m_startPos.y);
	D3DXMATRIX rot_matrix;


	pD3DDevice->SetTransform(D3DTS_WORLD,&trans_matrix);
	//D3DXMatrixRotationY(&rot_matrix,rot_y);
	rot_y +=1.0f;

	pD3DDevice->BeginScene();
		
	// Nothing To draw!!!
		/* We are passing the vertices down a "stream" and specify the source as our vertex buffer */
	    pD3DDevice->SetStreamSource( 0, m_pVB, 0, sizeof(vertices) );
		/* Here we are telling D3D that we are using FVF as the Vertex Shader */
        pD3DDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
		/* DrawPrimitive() does the actual rendering of our geometry (here a single Triangle)*/
       pD3DDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 100 );
   //pD3DDevice->
	pD3DDevice->EndScene();
	
	pD3DDevice->Present( NULL, NULL, NULL, NULL );		// Display Result

	return TRUE;										// Keep Going
}

void KillD3DWindow()									// Properly Kill The Window
{
    if (pD3DDevice != NULL)	pD3DDevice->Release();		// Release D3D Device
	
	if (pD3D != NULL) pD3D->Release();					// Release D3D Interface

	if (fullscreen)										// Are We In Fullscreen Mode?
	{
		ChangeDisplaySettings(NULL,0);					// If So Switch Back To The Desktop
		ShowCursor(TRUE);								// Show Mouse Pointer
	}

	if (hDC && !ReleaseDC(hWnd,hDC))					// Are We Able To Release The DC
	{
		MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
		hDC=NULL;										// Set DC To NULL
	}

	if (hWnd && !DestroyWindow(hWnd))					// Are We Able To Destroy The Window?
	{
		MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
		hWnd=NULL;										// Set hWnd To NULL
	}

	if (!UnregisterClass("Direct3D",hInstance))			// Are We Able To Unregister Class
	{
		MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
		hInstance=NULL;									// Set hInstance To NULL
	}
}

/*	This Code Creates Our DirectX 3D Window.  Parameters Are:				*
 *	title			- Title To Appear At The Top Of The Window				*
 *	width			- Width Of The D3D Window Or Fullscreen Mode			*
 *	height			- Height Of The D3D Window Or Fullscreen Mode			*
 *	fullscreenflag	- Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE)	*/

BOOL CreateD3DWindow(char* title, int width, int height, bool fullscreenflag)
{
	WNDCLASS	wc;
	DWORD		dwExStyle;				// Window Extended Style
	DWORD		dwStyle;				// Window Style
	RECT		WindowRect;				// Grabs Rectangle Upper Left / Lower Right Values
	WindowRect.left=(long)0;			// Set Left Value To 0
	WindowRect.right=(long)width;		// Set Right Value To Requested Width
	WindowRect.top=(long)0;				// Set Top Value To 0
	WindowRect.bottom=(long)height;		// Set Bottom Value To Requested Height

	fullscreen=fullscreenflag;			// Set The Global Fullscreen Flag

	hInstance			= GetModuleHandle(NULL);				// Grab An Instance For Our Window
	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	// Redraw On Size, And Own DC For Window.
	wc.lpfnWndProc		= (WNDPROC) WndProc;					// WndProc Handles Messages
	wc.cbClsExtra		= 0;									// No Extra Window Data
	wc.cbWndExtra		= 0;									// No Extra Window Data
	wc.hInstance		= hInstance;							// Set The Instance
	wc.hIcon			= LoadIcon(NULL, IDI_WINLOGO);			// Load The Default Icon
	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);			// Load The Arrow Pointer
	wc.hbrBackground	= NULL;									// No Background Required For D3D
	wc.lpszMenuName		= NULL;									// We Don't Want A Menu
	wc.lpszClassName	= "Direct3D";							// Set The Class Name


	if (!RegisterClass(&wc))									// Attempt To Register The Window Class
	{
		MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;											// Return FALSE
	}

	if (fullscreen)												// Fullscreen Mode?
	{
		dwExStyle=WS_EX_APPWINDOW;								// Window Extended Style
		dwStyle=WS_POPUP;										// Windows Style
		ShowCursor(FALSE);										// Hide Mouse Pointer
	}
	else
	{
		dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended Style
		dwStyle=WS_OVERLAPPEDWINDOW;							// Windows Style
	}


	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);	// Adjust Window To True Requested Size


	// Create The Window
	if (!(hWnd=CreateWindowEx(	dwExStyle,							// Extended Style For The Window
								"Direct3D",							// Class Name
								title,								// Window Title
								dwStyle |							// Defined Window Style
								WS_CLIPSIBLINGS |					// Required Window Style
								WS_CLIPCHILDREN,					// Required Window Style
								0, 0,								// Window Position
								WindowRect.right-WindowRect.left,	// Calculate Window Width
								WindowRect.bottom-WindowRect.top,	// Calculate Window Height
								NULL,								// No Parent Window
								NULL,								// No Menu
								hInstance,							// Instance
								NULL)))								// Dont Pass Anything To WM_CREATE
	{
		KillD3DWindow();							// Reset The Display
		MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}


	if (!(hDC=GetDC(hWnd)))							// Did We Get A Device Context?
	{
		KillD3DWindow();								// Reset The Display
		MessageBox(NULL,"Can't Create A Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}


	pD3D = Direct3DCreate9( D3D_SDK_VERSION );		// Check For The Correct DirectX 3D version
	if ( pD3D == NULL )
	{
		KillD3DWindow();							// Reset The Display
		MessageBox(NULL,"Can't find D3D SDK Version 9.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}


	D3DPRESENT_PARAMETERS d3dpp=					// d3dpp Tells Windows How We Want Things To Be
	{
		width,										// Back Buffer Width
		height,										// Back Buffer Height
		D3DFMT_R5G6B5,								// Back Buffer Format (Color Depth)
		1,											// Back Buffer Count (Double Buffer)
		D3DMULTISAMPLE_NONE,						// No Multi Sample Type
		0,											// No Multi Sample Quality
		D3DSWAPEFFECT_DISCARD,						// Swap Effect (Fast)
		hWnd,										// The Window Handle
		!fullscreen,								// Windowed or Fullscreen
		TRUE,										// Enable Auto Depth Stencil  
		D3DFMT_D16,									// 16Bit Z-Buffer (Depth Buffer)
		0,											// No Flags
		D3DPRESENT_RATE_DEFAULT,					// Default Refresh Rate
		D3DPRESENT_INTERVAL_DEFAULT					// Default Presentation Interval (vertical sync)
	};


	// Check The Wanted Surface Format.
	if ( FAILED( pD3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
									      d3dpp.BackBufferFormat, D3DUSAGE_DEPTHSTENCIL,
									      D3DRTYPE_SURFACE, d3dpp.AutoDepthStencilFormat ) ) )
	{
		KillD3DWindow();							// Reset The Display
		MessageBox(NULL,"Can't Find Surface Format.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}


	// Create The DirectX 3D Device 
	if(FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
					 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pD3DDevice ) ) )
	{
		KillD3DWindow();							// Reset The Display
		MessageBox(NULL,"Can't Create DirectX 3D Device.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}


	ShowWindow(hWnd,SW_SHOW);						// Show The Window
	SetForegroundWindow(hWnd);						// Slightly Higher Priority
	SetFocus(hWnd);									// Sets Keyboard Focus To The Window
	ReSizeD3DScene(width, height);					// Set Up Our Perspective D3D Screen


	if (!InitD3D())									// Initialize Our Newly Created D3D Window
	{
		KillD3DWindow();							// Reset The Display
		MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return FALSE;								// Return FALSE
	}

	return TRUE;
}

LRESULT CALLBACK WndProc(	HWND	hWnd, 
							UINT	uMsg, 
							WPARAM	wParam, 
							LPARAM	lParam )
{
    switch( uMsg )
	{
		case WM_ACTIVATE:							// Watch For Window Activate Message
		{
			if (!HIWORD(wParam))					// Check Minimization State
			{
				active=TRUE;						// Program Is Active
			}
			else
			{
				active=FALSE;						// Program Is No Longer Active
			}

			return 0;								// Return To The Message Loop
		}

		case WM_SYSCOMMAND:							// Intercept System Commands
		{
			switch (wParam)							// Check System Calls
			{
				case SC_SCREENSAVE:					// Screensaver Trying To Start?
				case SC_MONITORPOWER:				// Monitor Trying To Enter Powersave?
				return 0;							// Prevent From Happening
			}
			break;									// Exit
		}

		case WM_CLOSE:								// Did We Receive A Close Message?
		{
			PostQuitMessage(0);						// Send A Quit Message
			return 0;								// Jump Back
		}

		case WM_KEYDOWN:							// Is A Key Being Held Down?
		{
			keys[wParam] = TRUE;					// If So, Mark It As TRUE
			return 0;								// Jump Back
		}

		case WM_KEYUP:								// Has A Key Been Released?
		{
			keys[wParam] = FALSE;					// If So, Mark It As FALSE
			return 0;								// Jump Back
		}

		case WM_SIZE:								// Resize The Direct3D Window
		{
			if(!fullscreen)
				ReSizeD3DScene(LOWORD(lParam), HIWORD(lParam));  // LoWord=Width, HiWord=Height
			return 0;								// Jump Back
		}
	}

	// Pass All Unhandled Messages To DefWindowProc
	return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

int WINAPI WinMain( HINSTANCE	hInstance,
                    HINSTANCE	hPrevInstance,
                    LPSTR		lpCmdLine,
                    int			nCmdShow )
{

	MSG     msg;
	BOOL	done=FALSE;								// Bool Variable To Exit Loop

	// Ask The User Which Screen Mode They Prefer
	if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
	{
		fullscreen=FALSE;							// Windowed Mode
	}

	// Create Our DirectX 3D Window
	if (!CreateD3DWindow("Apron Tutorials Direct3D Framework",800,600,fullscreen))
	{
		return 0;									// Quit If Window Was Not Created
	}

	while(!done)									// Loop That Runs While done=FALSE
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?
		{
			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?
			{
				done=TRUE;							// If So done=TRUE
			}
			else									// If Not, Deal With Window Messages
			{
				TranslateMessage(&msg);				// Translate The Message
				DispatchMessage(&msg);				// Dispatch The Message
			}
		}
		else										// If There Are No Messages
		{
			// Draw The Scene.  Watch For ESC Key And Quit Messages From DrawD3DScene()
			if ((active && !DrawD3DScene()) || keys[VK_ESCAPE])	// Active?  Was There A Quit Received?
			{
				done=TRUE;							// ESC or DrawD3DScene Signalled A Quit
			}

			if (keys[VK_F1])						// Is F1 Being Pressed?
			{
				keys[VK_F1]=FALSE;					// If So Make Key FALSE
				KillD3DWindow();					// Kill Our Current Window
				fullscreen=!fullscreen;				// Toggle Fullscreen / Windowed Mode
				// Recreate Our DirectX 3D Window
				if (!CreateD3DWindow("Apron Tutorials Direct3D Framework",800,600,fullscreen))
				{
					return 0;						// Quit If Window Was Not Created
				}
			}
		}
	}

	// Shutdown
	KillD3DWindow();
	return (msg.wParam);							// Exit The Program
}

Bobby

Share this post


Link to post
Share on other sites
Advertisement
it will not display as triangles.

i don't know if i missing something or the data is mishandled.

Bobby

Share this post


Link to post
Share on other sites
There is way too much code there for me to go through. You should start with the bare minimum code necessary to reproduce the problem and work from there. Are you able to create a simple application that displays a single triangle? Have you checked the winding order and/or Z-values and/or camera position? Have you tried outputing the loaded data to text files to see if it is being read in correctly?

Share this post


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

  • Advertisement