Hi Shaki,
Well I am not new to programming, but new to directx. Even though I followed Chillis tutorials in the past, it didn't mean I understood the engine that well. So I have been trying to start from scratch, and I wanted to use directx sprites instead of the putpixel.
I can understand why some of the code looks like frankinstein code, and that is because I didn't understand everything I was doing, and picked up bits and pieces from different sources. I would like to improve it later, when I know what I am doing.
Right I assumed bool Hangbot::Init() was only being run once and hence put my initialisation code in there heh heh. It seems it was running over and over and reloading my graphics and fonts like you said.
With the sprites and fonts, I realised that D3DXCreateTextureFromFileEx and D3DXCreateFont should only have been run once, but everytime I tried to move them into a different member function the program crashed heh heh.
The directx tutorial I followed originally had the game code in the same file as winmain. I separated this to try to simplify it, as I don't want to be messing with winmain when I am doing the game.
I don't know why the original tutorial I followed separated game.cpp and winmain.cpp, but I thought it was like chilli separating the direct3d stuff and winmain. I would change this later, but I get easily lost.
Before I downloaded your changes, I had this code I was testing
Code: Select all
#include "Sprite.h"
Sprite::Sprite()
{
}
Sprite::~Sprite()
{
sprite->Release();
}
void Sprite::Init(IDirect3DDevice9* m_pd3dDevice)
{
D3DXCreateTextureFromFileEx(m_pd3dDevice, L"data/rustydrone2.jpg", D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2,
D3DX_DEFAULT, 0, D3DFMT_R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &m_texture);
D3DXCreateSprite(m_pd3dDevice, &sprite);
}
void Sprite::Render(IDirect3DDevice9* m_pd3dDevice)
{
Pos.x = 0.0f;
Pos.y = 0.0f;
Pos.z = 0.0f;
// Draw The Sprite
//sprite->Begin(D3DXSPRITE_ALPHABLEND);
sprite->Begin(NULL);
sprite->Draw(m_texture, NULL, NULL, &Pos, 0xFFFFFFFF);
sprite->End();
};
To me it looked fine, but every time I run it, it crashed.
When I look at what you added to the sprite routine. I can see the asserts, but I can't see much difference, except that yours works, and mine doesn't LOL,
Code: Select all
void Sprite::LoadTexture(IDirect3DDevice9* m_pd3dDevice){
HRESULT result;
result = D3DXCreateTextureFromFileEx(m_pd3dDevice,L"rustydrone2.jpg", D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2,
D3DX_DEFAULT, 0, D3DFMT_R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &m_texture);
assert(!FAILED(result));
result = D3DXCreateSprite(m_pd3dDevice, &sprite);
assert(!FAILED(result));
}
Thankyou for all the help. I haven't had time to dig through the code properly yet. I am sure there are bits you have added I haven't totally worked out yet.
I can see what you added is quite logical though, and it is what I wanted to do, but I am a little out of my depth.
I have lots of directx books, but I find them very difficult to learn from, and so I ploughed straight in.
BTW I have added a lot more to the code since my last post, but it is simple to implement it, now you have sorted out my problems.
Thanks a lot.
PS. You said that the code was jumping about all over the place, I think that is what you said. Do you mean the directx and winmain stuff, and what are your suggestions for improving it?
I try to keep things modular, but now I am thinking maybe keyboardinput, and letterDraw may have been ok in the same class, because they share similar functions.
PPS. I can understand why you moved
Code: Select all
void Letterdraw::LoadFont(IDirect3DDevice9* m_pd3dDevice){
letterFont.setFont(80,m_pd3dDevice);
}
To a different function so it only runs once, but I originally put it in the constructor, because I am sure a constructor is only run once, when the class is first initialised. Am I wrong?