Jump to content
  • Advertisement

Archived

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

Quiggy

Crashes on DrawPrimitive?

This topic is 5738 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 currently reading through Jim Adams RPG/DirectX book and making decent progress. Or so I thought. I''m using his simple windows application framework and made sure that worked first. Then I implemented the DirectX stuff into it putting the code into their respective places within the code. It all works beautifully IF I comment out the DrawPrimitive command. Once I put that in, I get a nasty runtime error. "BounceTest.exe has encountered a problem and needs to close. We are sorry for the inconvenience." You know the one... I''ve gone through the code over and over again, but can not find any problems or typo''s. Does anybody have any ideas what can cause a DrawPrimitive to kill a program? I''m going to include some code here so if you feel inclined you can take a gander. The first is my DirectX init stuff. The second is the OnFrame DirectX stuff. BOOL DoInit() { BYTE *Ptr; D3DXMATRIX matProj, matView; sVertex Verts[4] = { { -100.0f, 100.0f, 0.0f, 0.0f, 0.0f }, { 100.0f, 100.0f, 0.0f, 1.0f, 0.0f }, { -100.0f, -100.0f, 0.0f, 0.0f, 1.0f }, { 100.0f, -100.0f, 0.0f, 1.0f, 1.0f } }; // This is where I set up the DirectX stuff. /* 1) Obtain an interface for Direct3D 2) Select a display Mode 3) Set the Presentation Method 4) Create the Device interface and initialize the display */ // ********* STEP 1 ************ if( (g_pD3D = Direct3DCreate8(D3D_SDK_VERSION)) == NULL) { WriteToLog("ERROR trying to Obtain Interface for Direct3D (Step #1)"); return FALSE; } // ************ STEP 2 ************** D3DDISPLAYMODE d3ddm; // D3DDisplayMode Structure if (FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm))) { WriteToLog("ERROR trying to select Display Mode (Step #2)"); return FALSE; } // ********** Step 3 ************** D3DPRESENT_PARAMETERS d3dpp; // D3DPresent_Parameters Structure // Clear out the present sturcture ZeroMemory(&d3dpp, sizeof(d3dpp) ); if (GRAPHICS_MODE == 1) // 1 = windows mode 2 = Full Screen Mode { d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; } else { d3dpp.Windowed = FALSE; d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP; d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_INTERVAL_DEFAULT; d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; } d3dpp.BackBufferFormat = d3ddm.Format; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; // ************ STEP 4 ************ if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice))) { WriteToLog("ERROR creating the Device (Step #4)"); return FALSE; } WriteToLog("DirectX Initialized Properly."); // ********** Create the Projection matrix ***************** g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE); g_pD3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE); D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 1.33333f, 1.0f, 1000.0f); g_pD3DDevice->SetTransform(D3DTS_PROJECTION, &matProj); // ***************** Create and set the view matrix ******************* D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3(0.0f, 0.0f, -500.0f), &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); g_pD3DDevice->SetTransform(D3DTS_VIEW, &matView); //********** Create Vertex Buffer and Set data *********** if(FAILED(g_pD3DDevice->CreateVertexBuffer(sizeof(sVertex) * 4, 0, VERTEXFVF, D3DPOOL_DEFAULT, &g_pD3DVB))) { WriteToLog("ERROR creating the Vertex Buffer"); return FALSE; } g_pD3DVB->Lock(0, 0, (BYTE**)&Ptr, 0); memcpy(Ptr, Verts, sizeof(Verts)); g_pD3DVB->Unlock(); D3DXCreateTextureFromFile(g_pD3DDevice, "4_Texture.bmp", &g_pTexture); return TRUE; } BOOL DoFrame() { D3DXMATRIX matWorld; // Clear device backbuffer g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_RGBA(0,64,128,255), 1.0f, 0); // Begin scene if(SUCCEEDED(g_pD3DDevice->BeginScene())) { // Create and set the world transformation matrix // Rotate object along Z-axis D3DXMatrixRotationZ(&matWorld, (float)timeGetTime() / 1000.0f); g_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld); // Set the vertex stream, shader, and texture g_pD3DDevice->SetStreamSource(0, g_pVB, sizeof(sVertex)); g_pD3DDevice->SetVertexShader(VERTEXFVF); g_pD3DDevice->SetTexture(0, g_pTexture); // Draw the vertex buffer if (FAILED(g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2))) { WriteToLog("DrawPrimitive Failed."); return FALSE; } // Release texture g_pD3DDevice->SetTexture(0, NULL); // End the scene g_pD3DDevice->EndScene(); } // Display the scene g_pD3DDevice->Present(NULL, NULL, NULL, NULL); return TRUE; } Thanks all! Quiggy.

Share this post


Link to post
Share on other sites
Advertisement
Yeah, checked and rechecked that. It appears to be correct. Here''s what I have set up in my header file. The FVF is at the very end.

Also can somebody tell me the flags for properly displaying code in those scroll boxes. I thought I knew it for my last message, but obviously it was wrong.


// Include Files

#include <windows.h>
#include <stdio.h>
#include <stdarg.h>

#include "d3d8.h"
#include "d3dx8.h"

// Main App Instances

HINSTANCE g_hInst; // Global Instance Handle
HWND g_hWnd; // Global Window Handle

// ****************************************************************
// Application window dimensions, type, class and window name
// ****************************************************************
const int WNDWIDTH = 640;
const int WNDHEIGHT = 480;
const int WNDTYPE = WS_OVERLAPPEDWINDOW;
const int GRAPHICS_MODE = 1; // 1 = Windowed and 2 = Full Screen

const char g_szClass[] = "FrameClass";
const char g_szCaption[] = "FrameCaption";

// DirectX variables.
IDirect3D8 *g_pD3D = NULL;
IDirect3DDevice8 *g_pD3DDevice = NULL;
IDirect3DVertexBuffer8 *g_pD3DVB = NULL;

// Vertex buffer
IDirect3DVertexBuffer8 *g_pVB = NULL;

// Texture
IDirect3DTexture8 *g_pTexture = NULL;

bool g_fEnableLogging;

// The 3-D vertex format and descriptor
typedef struct
{
FLOAT x, y, z;
FLOAT u, v;
} sVertex;

#define VERTEXFVF (D3DFVF_XYZ | D3DFVF_TEX1)





Share this post


Link to post
Share on other sites

  • 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!