So I've looked through everything and with a tutorial for DirectX9 I'm doing, and I for the life of me cannot find out what's wrong with the code here:
Code:
/************************************/
/* CRYSTAL BOND */
/************* ***********/
/* DirectX game built by */
/** Glitch Softwares Studios **/
/************************************/
//Include important files
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include "functions.h"
//Include Direct3D Library
#pragma comment (lib, "d3d9.lib")
//Include files specifically for this game
#include "functions.h"
//Prototype of CALLBACK
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;
//Clear windows for use
ZeroMemory(&wc, sizeof(WNDCLASSEX));
//Build structure with information
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = L"WindowClass";
//Make the Windows Program
hWnd = CreateWindowEx(NULL,
L"WindowClass", //Class name
L"Crystal Bond", //Window Caption
WS_OVERLAPPEDWINDOW, //Style
5, //X Start
5, //Y Start
645, //Width
485, //Height
NULL, //Parent Window
NULL, //Menus
hInstance, //Application handle
NULL); //Use with multiple windows
//Make window visible
ShowWindow(hWnd, nCmdShow);
initD3D(hWnd);
MSG resp; //Create the structure to communicate the user input
while(GetMessage(&resp,NULL,0,0))
{
TranslateMessage(&resp); //Translate input to machine's language
DispatchMessage(&resp); //Send message to be processed.
}
return resp.wParam;
while(true)
{
// Check to see if any messages are waiting in the queue
while(PeekMessage(&resp, NULL, 0, 0, PM_REMOVE))
{
// Translate the message and dispatch it to WindowProc()
TranslateMessage(&resp);
DispatchMessage(&resp);
}
// If the message is WM_QUIT, exit the while loop
if(resp.message == WM_QUIT)
break;
renderFrame();
}
cleanD3D();
}
LRESULT CALLBACK WindowProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
//Look for what to do at message recieved
switch(message)
{
//Message says: Close the program and window
case WM_DESTROY:
{PostQuitMessage(0);return 0;break;}
}
//Else, and nothing was supported in SWITCH
return DefWindowProc(hWnd, message, wParam, lParam);
}
It's not the functions and the lack of certain pointers and things, as their defined in the other headers in "functions.h", I just KNOW it's in main.cpp here, it's GOTTA be.
So this code is compiled under Visual C++ 2008 Express Edition, and it compiles and works fine, but for some reason it doesn't show the window, but the program is running. However I've checked the line saying:
Code:
//Make window visible
ShowWindow(hWnd, nCmdShow);
And yet it still won't work, I'm pretty sure I did everything right, if anyone wants the other header files:
"functions.h"
Code:
#ifndef _FUNCTIONS_H_
#define _FUNCTIONS_H_
//Global declarations
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
#include "prototypes.h"
#include "dxfunctions.h"
#endif
"prototypes.h"
Code:
#ifndef _PROTOTYPES_H_
#define _PROTOTYPES_H_
void initD3D(HWND hWnd);
// initilize DirectX
void renderFrame(void);
// renders one (1) frame
void cleanD3D(void);
// when the game ends, this will be called to clear everything
#endif
"dxfunctions.h"
Code:
#ifndef _DXFUNCTIONS_H_
#define _DXFUNCTIONS_H_
// Initilize Direct3D
void initD3D(HWND hWnd)
{
d3d=Direct3DCreate9(D3D_SDK_VERSION); //Create the D3D interface
D3DPRESENT_PARAMETERS d3dpp; //Structure for holding device information
ZeroMemory(&d3dpp,sizeof(d3dpp)); //Erase STRUCT for usability
d3dpp.Windowed = true; // NOT Fullscreen
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; //Erase old frames
d3dpp.hDeviceWindow = hWnd; //Makes the window compatible with D3D
//Make the Direct3D class, using structure info above
d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);
}
// Make new frame
void renderFrame(void)
{
//Clear screen to color BLUE
d3ddev->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,40,100),1.0f,0);
d3ddev->BeginScene(); //Begin the 3D image render
//Render here
d3ddev->EndScene(); //End the 3D image render
//Display the rendered frame
d3ddev->Present(NULL,NULL,NULL,NULL);
}
// Clear the DirectX engine and COM
void cleanD3D(void)
{
d3ddev->Release();
d3d->Release();
}
#endif
Thanks for the help, I suspect this was to go in either Windows Programming or Game Programming in DirectX, but I wasn't sure, so move if appropriate.