D3DIM - DrawPrimitive - Nothing on screen

Started by
1 comment, last by Phillip Schuster 24 years, 6 months ago
Hi,

It could be something with the vertex format.
Try replacing the line:
pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST,D3DVT_TLVERTEX,(LPVOID)v,3,NULL);
With:
pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST,D3DFVF_TLVERTEX,(LPVOID)v,3,NULL);

Greetings Tobias

Advertisement
Hi all !!

I have a big problem. After playing around with a lot of 3D Engines, I want to write my own (just for learning purposes). I want it to do in D3D Immediate Mode. I am using DirectX 6 and MSVC 6 !!
Ok, I went through a lot of tutorials and read a lot about DrawPrimitive and DirectX. Initializing is fine (I think so, I don't get errors). I simply give DrawPrimitive a simple triangle with screen coordinates, but it does not display anything. I tried to use 3D Triangles, nothing. The backbuffer is flipped, because my window gets blue (I clear the backbuffer with a blue, the window background is black).

I post my complete render and init-code, perhaps someone finds the error:

// Renderer.cpp: Implementierung der Klasse CRenderer.////////////////////////////////////////////////////////////////////////#include "stdafx.h"#include "Renderer.h"//////////////////////////////////////////////////////////////////////// Konstruktion/Destruktion//////////////////////////////////////////////////////////////////////CRenderer::CRenderer(){	pDD				= NULL;	pDD4			= NULL;	pDDSPrimary		= NULL;	pDDSBack		= NULL;	pDDClipper		= NULL;	pD3D			= NULL;	pD3DDevice		= NULL;	pDDViewport		= NULL;}CRenderer::~CRenderer(){}BOOL CRenderer::Init(HINSTANCE hInstance, HWND hWnd){    HRESULT hr; 	hTargetWnd = hWnd;    // Create a DirectDraw object.    hr = DirectDrawCreate(NULL, &pDD, NULL);    if(FAILED(hr)) {		MessageBox(hWnd,"DirectDrawCreate failed","3D Engine",MB_OK);        return false;	}	     // Get a ptr to an IDirectDraw4 interface. This interface to DirectDraw    // represents the DX6 version of the API.    hr = pDD->QueryInterface(IID_IDirectDraw4, (VOID**)&pDD4);    if(FAILED(hr)) {		MessageBox(hWnd,"QueryInterface failed","3D Engine",MB_OK);        return false;	}	hr = pDD4->SetCooperativeLevel(hWnd, DDSCL_NORMAL);    if(FAILED(hr)) {		MessageBox(hWnd,"SetCooperativeLevel failed","3D Engine",MB_OK);        return false;	}    // Prepare a surface description for the primary surface.    DDSURFACEDESC2 ddsd;    ZeroMemory( &ddsd, sizeof(DDSURFACEDESC2) );    ddsd.dwSize         = sizeof(DDSURFACEDESC2);    ddsd.dwFlags        = DDSD_CAPS;    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;     // Create the primary surface.    hr = pDD4->CreateSurface( &ddsd, &pDDSPrimary, NULL );    if(FAILED(hr)) {		MessageBox(hWnd,"CreateSurface (Primary) failed","3D Engine",MB_OK);        return false;	}	    ddsd.dwFlags        = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;     // Set the dimensions of the back buffer. Note that if our window changes    // size, we need to destroy this surface and create a new one.    GetClientRect( hWnd, &rcScreen );    GetClientRect( hWnd, &rcViewport );    ClientToScreen( hWnd, (POINT*)&rcScreen.left );    ClientToScreen( hWnd, (POINT*)&rcScreen.right );    ddsd.dwWidth  = rcScreen.right - rcScreen.left;    ddsd.dwHeight = rcScreen.bottom - rcScreen.top;     // Create the back buffer. The most likely reason for failure is running    // out of video memory. (A more sophisticated app should handle this.)    hr = pDD4->CreateSurface( &ddsd, &pDDSBack, NULL );    if(FAILED(hr)) {		MessageBox(hWnd,"CreateSurface (BackBuffer) failed","3D Engine",MB_OK);        return false;	}  	//Here a Z-Buffer should be initialized    // Create the clipper.    hr = pDD4->CreateClipper( 0, &pDDClipper, NULL );    if(FAILED(hr)) {		MessageBox(hWnd,"CreateClipper failed","3D Engine",MB_OK);        return false;	}     // Assign it to the window handle, then set    // the clipper to the desired surface.    pDDClipper->SetHWnd( 0, hWnd );    pDDSPrimary->SetClipper( pDDClipper );    pDDClipper->Release();     // Query DirectDraw for access to Direct3D    pDD4->QueryInterface( IID_IDirect3D3, (VOID**)&pD3D );    if(FAILED(hr)) {		MessageBox(hWnd,"QueryInterface failed","3D Engine",MB_OK);        return false;	}	// Check the display mode, and     ddsd.dwSize = sizeof(DDSURFACEDESC2);    pDD4->GetDisplayMode( &ddsd );    if( ddsd.ddpfPixelFormat.dwRGBBitCount <= 8 ) {		MessageBox(hWnd,"Kann mit 256 Farben nicht gestartet werden","3d Engine",0);        return false;	} 	// Find a device we can use	D3DFINDDEVICESEARCH search;	D3DFINDDEVICERESULT result;	ZeroMemory(&search, sizeof(search));	search.dwSize = sizeof(search);	search.dwFlags = D3DFDS_HARDWARE;	search.bHardware = TRUE;	ZeroMemory(&result, sizeof(result));	result.dwSize = sizeof(result);	if (pD3D->FindDevice(&search, &result) != D3D_OK) {		MessageBox(hWnd,"Kein Device gefunden","3D Engine",MB_OK);		return false;	}	// Create the D3D device	if (pD3D->CreateDevice(result.guid, pDDSBack, &pD3DDevice, NULL) != D3D_OK) {		return FALSE;	}    // Set up the viewport data parameters    D3DVIEWPORT2 vdData;    ZeroMemory( &vdData, sizeof(D3DVIEWPORT2) );     // Always set the structure size!    vdData.dwSize       = sizeof(D3DVIEWPORT2); 	vdData.dwX = 0;	vdData.dwY = 0;    vdData.dwWidth      = rcScreen.right - rcScreen.left;    vdData.dwHeight     = rcScreen.bottom - rcScreen.top;	vdData.dvClipX      = 0.0f;     vdData.dvClipWidth  = (float)vdData.dwWidth;     vdData.dvClipY      = 0.0f;     vdData.dvClipHeight = (float)vdData.dwHeight;;     vdData.dvMaxZ       = 100.0f;  // Create the viewport.    hr = pD3D->CreateViewport( &pDDViewport, NULL );    if(FAILED(hr)) {		MessageBox(hWnd,"CreateViewport failed","3D Engine",MB_OK);        return false;	}     // Associate the viewport with the device.    pD3DDevice->AddViewport( pDDViewport );     // Set the parameters for the new viewport.    pDDViewport->SetViewport2( &vdData ); 	// Set the current viewport for the device    pD3DDevice->SetCurrentViewport( pDDViewport ); 	return true;}void CRenderer::ShutDown(){	// Release the DDraw and D3D objects used by the app    if( pDDViewport )      pDDViewport->Release();	if( pD3D )             pD3D->Release();	if( pDDSBack )		   pDDSBack->Release();	if( pDDSPrimary )      pDDSPrimary->Release();	if( pDD4 )             pDD4->Release();    // Do a safe check for releasing the D3DDEVICE. RefCount should be zero.    if( pD3DDevice )        if( 0 < pD3DDevice->Release() )			return;	// Do a safe check for releasing DDRAW. RefCount should be zero.    if( pDD )        if( 0 < pDD->Release() )			return;	pDD				= NULL;	pDD4			= NULL;	pDDSPrimary		= NULL;	pDDSBack		= NULL;	pDDClipper		= NULL;	pD3D			= NULL;	pD3DDevice		= NULL;	pDDViewport		= NULL;}void CRenderer::RenderWorld(CWorld *pWorld){    D3DMATRIX mat;    mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;    mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;    mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;    mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;    	pD3DDevice->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);    D3DMATRIX matView;	matView = CurrentCamera->ViewMatrix.GetD3DMatrix();    pD3DDevice->SetTransform( D3DTRANSFORMSTATE_VIEW, &matView );     // The projection matrix defines how the 3-D scene is "projected"     // onto the 2-D render target surface. For more information,    // see "What Is the Projection Transformation?"     // Set up a very simple projection that scales x and y     // by 2, and translates z by -1.0.    D3DMATRIX matProj;	matProj = CurrentCamera->ProjectionMatrix.GetD3DMatrix();    pD3DDevice->SetTransform( D3DTRANSFORMSTATE_PROJECTION, &matProj );/*	pD3DDevice->BeginScene();	long i;	for (i=0;inum_Polys;i++) {		D3DVERTEX vertices[3];		vertices[0] = D3DVERTEX(pWorld->polys.vertices[0]->ws_pos.GetD3DVector(),<BR>								pWorld->polys.normal.GetD3DVector(),0,0);<BR>		vertices[1] = D3DVERTEX(pWorld->polys.vertices[1]->ws_pos.GetD3DVector(),<BR>								pWorld->polys.normal.GetD3DVector(),0,0);<BR>		vertices[2] = D3DVERTEX(pWorld->polys.vertices[2]->ws_pos.GetD3DVector(),<BR>								pWorld->polys.normal.GetD3DVector(),0,0);<P>		pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST,D3DFVF_VERTEX,vertices,3,NULL);<BR>	}*/<P>// Render a triangle<BR>	D3DTLVERTEX v[3];<BR>	v[0] = D3DTLVERTEX(D3DVECTOR(160, 50,0),1,D3DRGB(1,0,0),D3DRGB(0,0,0),0,0);<BR>	v[1] = D3DTLVERTEX(D3DVECTOR(240,200,0),1,D3DRGB(0,1,0),D3DRGB(0,0,0),0,0);<BR>	v[2] = D3DTLVERTEX(D3DVECTOR( 80,200,0),1,D3DRGB(0,0,1),D3DRGB(0,0,0),0,0);<BR>	pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST,D3DVT_TLVERTEX,(LPVOID)v,3,NULL);<P>	pD3DDevice->EndScene();<BR>}<P>void CRenderer::ClearViewport()<BR>{<BR>    pDDViewport->Clear2( 1UL, (D3DRECT*)&rcViewport, D3DCLEAR_TARGET, 0x000000ff,<BR>                        0L, 0L );<BR>}<P>void CRenderer:   <IMG SRC="http://www.gamedev.net/community/forums/ubb/biggrin.gif">isplayFrame()<BR>{<BR>    // The g_pddsPrimary variable will be NULL when <BR>    // the application is in the middle of recreating<BR>    // DirectDraw objects.<BR>    if( NULL == pDDSPrimary )<BR>        return;<BR> <BR>    // We are in windowed mode, so perform a blit from the backbuffer to the<BR>    // correct position on the primary surface<BR>    pDDSPrimary->Blt( &rcScreen, pDDSBack, &rcViewport, DDBLT_WAIT, NULL );<BR>}<P>void CRenderer::SetActiveCamera(CCamera *camera)<BR>{<BR>	CurrentCamera = camera;<BR>	camera->bActive = TRUE;<BR>}<BR></B></pre></font><P>Thanks very much.<P>Phillip<P>[This message has been edited by Phillip Schuster (edited October 04, 1999).]<p>[This message has been edited by Phillip Schuster (edited October 04, 1999).]

Phillip Schuster
Hi !!

THANKS ALOT !!! It works now. My god, such a damn bad fault. Ok, I have learned something )

Thanks again.


Phillip

Phillip Schuster

This topic is closed to new replies.

Advertisement