
Originally Posted by
Hell_Demon
post full code? :3
main.cpp
Code:
#include "main.h"
//main file
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WNDCLASSEX wnd;
wnd.cbSize = sizeof(WNDCLASSEX);
wnd.style= CS_HREDRAW | CS_VREDRAW;
wnd.lpfnWndProc= (WNDPROC)WndProc;
wnd.cbClsExtra= 0;
wnd.cbWndExtra= 0;
wnd.hInstance= hInstance;
wnd.hIcon= 0;
wnd.hCursor= LoadCursor(NULL, IDC_ARROW);
wnd.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);
wnd.lpszMenuName= 0;
wnd.lpszClassName= "wndClass";
wnd.hIconSm = 0;
RegisterClassEx(&wnd);
if (!LoadOptions()) {
messge = "Failed to load options please reinstall.";
MessageBox(NULL, messge, "Lost, Scared and Confused Error", MB_ICONINFORMATION|MB_SETFOREGROUND);
return 0;
}
hWnd = CreateWindow("wndClass", "Lost, Scared and Confused", WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT, fW, fH,
NULL, NULL, hInstance, NULL);
if (!StartDirect3D(hWnd)) {
messge = "Failed to start DirectX9, this may be caused by DirectX Runtime not being installed.";
MessageBox(NULL, messge, "Lost, Scared and Confused Error", MB_ICONINFORMATION|MB_SETFOREGROUND);
return 0;
}
if (!LoadData) {
messge = "Failed to load models and textures.";
MessageBox(NULL, messge, "Lost, Scared and Confused Error", MB_ICONINFORMATION|MB_SETFOREGROUND);
return 0;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
MSG msg;
ZeroMemory(&msg, sizeof(msg));
while (msg.message != WM_QUIT) {
if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
RenderDirectX();
Update();
}
ReleaseD3D();
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_DESTROY: {
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
main.h
Code:
#include "DataHandler.h"
#include <stdio.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
HWND hWnd;
char *messge;
void Update() {
}
class SpriteHandler {
public:
void DrawGUI() {
if (status == 0) {
mainSprite->SetTransform(&createMatrix(0.0f, 0.0f, fW, fH, 1.0f, 0.8f));
mainSprite->Draw(main[0], NULL, NULL, NULL, 0xFFFFFFFF);
}
}
private:
};
SpriteHandler sh;
void RenderDirectX() {
d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);
d3dDevice->BeginScene();
mainSprite->Begin(D3DXSPRITE_ALPHABLEND);
sh.DrawGUI();
mainSprite->End();
d3dDevice->EndScene();
d3dDevice->Present(NULL, NULL, NULL, NULL);
}
void ReleaseD3D() {
d3d->Release();
d3dDevice->Release();
mainSprite->Release();
for (int i = 0; i < 3; i++) {
main[i]->Release();
}
}
DataHandler.h
Code:
#include "D3DX.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int status = 0;
LPDIRECT3DTEXTURE9 main[3];
LPD3DXSPRITE mainSprite;
bool LoadTextures() {
main[0] = NULL;
main[1] = NULL;
main[2] = NULL;
if (FAILED(D3DXCreateTextureFromFile(d3dDevice, "bin/mainer/main800.png", &main[0])))
return false;
if (FAILED(D3DXCreateTextureFromFile(d3dDevice, "bin/mainer/main1024.png", &main[1])))
return false;
if (FAILED(D3DXCreateTextureFromFile(d3dDevice, "bin/mainer/main1280.png", &main[2])))
return false;
return true;
}
bool LoadData() {
if (FAILED(D3DXCreateSprite(d3dDevice, &mainSprite))) {
return false;
}
if (!LoadTextures()) {
return false;
}
return true;
}
bool LoadOptions() {
ifstream options ("data/options.txt");
string bWH;
if (options.is_open()) {
getline (options,bWH);
options.close();
} else {
return false;
}
baseWH = atoi(bWH.c_str());
if (baseWH == 0) {
fW = 800;
fH = 600;
} else {
if (baseWH == 1) {
fW = 1024;
fH = 768;
} else {
if (baseWH == 2) {
fW = 1280;
fH = 1024;
}
}
}
return true;
}
D3DX.h
Code:
#include <windows.h>
#include <mmsystem.h>
#include <XAnimator_lib.h>
//basics
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3dDevice;
int fW, fH, baseWH;
bool StartDirect3D(HWND hWnd) {
d3d = Direct3DCreate9(D3D_SDK_VERSION);
if (!d3d)
return false;
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
HRESULT hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &d3dDevice);
if (FAILED(hr)) {
HRESULT hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3dDevice);
if (FAILED(hr)) {
return false;
}
}
d3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
d3dDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(0, 0, 0));
d3dDevice->LightEnable(0, TRUE);
d3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
D3DXMATRIX matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 800.0f/600.0f, 1.0f, 200.0f );
d3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);
D3DXMATRIX matView, rotY;
D3DXMatrixIdentity(&matView);
D3DXMatrixRotationY(&rotY, 1.0);
matView = rotY;
d3dDevice->SetTransform(D3DTS_VIEW, &matView);
return true;
}
D3DXMATRIX createMatrix(float x, float y, float w, float h, float sA, float sB) {
D3DXVECTOR2 centre = D3DXVECTOR2(w/2, h/2);
D3DXVECTOR2 trans = D3DXVECTOR2(x, y);
float rotation = 0.0f;
D3DXVECTOR2 scaling(sA, sB);
D3DXMATRIX matrixR;
D3DXMatrixTransformation2D(&matrixR, NULL, 0.0, &scaling, ¢re, rotation, &trans);
return matrixR;
}
ps im using C++ visual studio 10