• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

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

Phillip Schuster

D3DIM - DrawPrimitive - Nothing on screen

2 posts in this topic

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

0

Share this post


Link to post
Share on other sites
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[i].vertices[0]->ws_pos.GetD3DVector(),
pWorld->polys[i].normal.GetD3DVector(),0,0);
vertices[1] = D3DVERTEX(pWorld->polys[i].vertices[1]->ws_pos.GetD3DVector(),
pWorld->polys[i].normal.GetD3DVector(),0,0);
vertices[2] = D3DVERTEX(pWorld->polys[i].vertices[2]->ws_pos.GetD3DVector(),
pWorld->polys[i].normal.GetD3DVector(),0,0);

pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST,D3DFVF_VERTEX,vertices,3,NULL);
}*/

// Render a triangle
D3DTLVERTEX v[3];
v[0] = D3DTLVERTEX(D3DVECTOR(160, 50,0),1,D3DRGB(1,0,0),D3DRGB(0,0,0),0,0);
v[1] = D3DTLVERTEX(D3DVECTOR(240,200,0),1,D3DRGB(0,1,0),D3DRGB(0,0,0),0,0);
v[2] = D3DTLVERTEX(D3DVECTOR( 80,200,0),1,D3DRGB(0,0,1),D3DRGB(0,0,0),0,0);
pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST,D3DVT_TLVERTEX,(LPVOID)v,3,NULL);

pD3DDevice->EndScene();
}

void CRenderer::ClearViewport()
{
pDDViewport->Clear2( 1UL, (D3DRECT*)&rcViewport, D3DCLEAR_TARGET, 0x000000ff,
0L, 0L );
}

void CRenderer: isplayFrame()
{
// The g_pddsPrimary variable will be NULL when
// the application is in the middle of recreating
// DirectDraw objects.
if( NULL == pDDSPrimary )
return;

// We are in windowed mode, so perform a blit from the backbuffer to the
// correct position on the primary surface
pDDSPrimary->Blt( &rcScreen, pDDSBack, &rcViewport, DDBLT_WAIT, NULL );
}

void CRenderer::SetActiveCamera(CCamera *camera)
{
CurrentCamera = camera;
camera->bActive = TRUE;
}

Thanks very much.

Phillip

[This message has been edited by Phillip Schuster (edited October 04, 1999).]

[This message has been edited by Phillip Schuster (edited October 04, 1999).]

0

Share this post


Link to post
Share on other sites