#include "global.h"
#include <atlbase.h>
LPDIRECT3D9 d3d = 0;
LPDIRECT3DDEVICE9 d3ddev = 0;
D3DPRESENT_PARAMETERS d3dpp;
LPD3DXSPRITE d3dSprite;
LPD3DXFONT font;
void InitD3D(GAMEWINDOW* gw)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = gw->Windowed;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.hDeviceWindow = gw->hWnd;
d3dpp.BackBufferWidth = gw->width;
d3dpp.BackBufferHeight = gw->height;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, gw->hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
d3ddev->SetRenderState(D3DRS_ZENABLE, true);
d3ddev->SetRenderState(D3DRS_LIGHTING, true);
d3ddev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50));
d3ddev->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
d3ddev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR);
d3ddev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
D3DXCreateSprite(d3ddev, &d3dSprite);
return;
}
void StartRender()
{
d3ddev->Clear(0, 0, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1, 0);
d3ddev->Clear(0, 0, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1, 0);
d3ddev->BeginScene();
d3dSprite->Begin(D3DXSPRITE_ALPHABLEND);
return;
}
void EndRender()
{
d3dSprite->End();
d3ddev->EndScene();
d3ddev->Present(0, 0, 0, 0);
return;
}
void LoadModel(MODEL* Model, LPCTSTR File)
{
LPD3DXBUFFER d3dBuffer;
D3DXLoadMeshFromX(File, D3DXMESH_SYSTEMMEM, d3ddev, 0, &d3dBuffer,
0, &Model->NumMaterials, &Model->Mesh);
D3DXMATERIAL* tempMaterial = (D3DXMATERIAL*)d3dBuffer->GetBufferPointer();
Model->Material = new D3DMATERIAL9[Model->NumMaterials];
Model->Texture = new LPDIRECT3DTEXTURE9[Model->NumMaterials];
for(DWORD i = 0; i < Model->NumMaterials; i++)
{
Model->Material = tempMaterial.MatD3D;
Model->Material.Ambient = Model->Material.Diffuse;
USES_CONVERSION;
if(FAILED(D3DXCreateTextureFromFileEx(d3ddev, CA2W(tempMaterial.pTextureFilename),
D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,
D3DX_DEFAULT, D3DX_DEFAULT, D3DCOLOR_XRGB(255, 0, 255), 0, 0, &Model->Texture)))
Model->Texture = NULL;
}
return;
}
void DrawModel(MODEL* Model, float x, float y, float z, float rotx, float roty, float rotz)
{
D3DXMATRIX matTranslate;
D3DXMatrixTranslation(&matTranslate, x, y, z);
D3DXMATRIX matRotX;
D3DXMATRIX matRotY;
D3DXMATRIX matRotZ;
D3DXMatrixRotationX(&matRotX, rotx);
D3DXMatrixRotationY(&matRotY, roty);
D3DXMatrixRotationZ(&matRotZ, rotz);
d3ddev->SetTransform(D3DTS_WORLD, &(matRotX * matRotY * matRotZ * matTranslate));
for(DWORD i = 0; i < Model->NumMaterials; i++)
{
d3ddev->SetMaterial(&Model->Material);
if(Model->Texture != NULL)
d3ddev->SetTexture(0, Model->Texture);
Model->Mesh->DrawSubset(i);
}
return;
}
void CreateLight(D3DLIGHT9* light, float brightness, float x, float y, float z, float index)
{
light->Type = D3DLIGHT_POINT;
light->Diffuse.r = light->Ambient.r = brightness;
light->Diffuse.g = light->Ambient.g = brightness;
light->Diffuse.b = light->Ambient.b = brightness;
light->Diffuse.a = light->Ambient.a = 1.0;
D3DVECTOR Pos = {x, y, z};
light->Position = Pos;
light->Attenuation0 = 0;
light->Attenuation1 = 0.125;
light->Attenuation2 = 0;
d3ddev->SetLight(index, light);
d3ddev->LightEnable(index, true);
}
Problem with meshes
Hello. This is my first post on GameDev.net, so sorry if I forget to mention any details about my program.
I have a problem with my meshes. I have created a program using DirectX and C++ to display meshes. However, when I run the program, the mesh material, as well as the texture, are not properly set.
Here's a picture of an x-file in the program:
------------------------------------------------
------------------------------------------------
Here is my desired result, I ran this with a different program:
------------------------------------------------
------------------------------------------------
When I compile the x-file of a tiger from the DirectX 9 sample x-files, I get this result:
------------------------------------------------
------------------------------------------------
I have been trying to fix this problem for a few days. Please reply if you know the problem. Thanks.
Here's my Direct3D code. It probably contains the problem:
-----------------------------------------------------------------------------------
---------------------------------------------------------------------------------
[Edited by - Mr Krackers on March 5, 2008 10:14:03 PM]
Does your gun model have texture co-ordinates? The tiger model's texture coordinates look wrong that is why the stripes don't look correct.
Hello mmakrzem. Thanks for the reply[attention]
I don't think the gun's has texture coordinates. I'm not exactly how to put texture coordinates on an x-file (I am not very advanced in programming yet).
However, I don't think its the x-file that's causing the problem. I used a sample program from DirectXTutorial.com, and when I ran it with the same x-file, the gun looks fine, as you can see from the second picture.
[Edited by - Mr Krackers on March 4, 2008 4:30:11 PM]
I don't think the gun's has texture coordinates. I'm not exactly how to put texture coordinates on an x-file (I am not very advanced in programming yet).
However, I don't think its the x-file that's causing the problem. I used a sample program from DirectXTutorial.com, and when I ran it with the same x-file, the gun looks fine, as you can see from the second picture.
[Edited by - Mr Krackers on March 4, 2008 4:30:11 PM]
I also have another problem (sorry). I have only one header file in my program, and it includes all the default DirectX include files needed for my program. However, when I try to include <atlbase.h>, the program has the following errors:
You can ignore this question if you like. It isn't of that much importance (unless it has something to do with my first problem) because I can just include it in one of my ".cpp" files and it works fine.
Thanks in advance[attention]
[Edited by - Mr Krackers on March 6, 2008 12:08:39 PM]
DirectInput.obj : error LNK2005: "char * __cdecl CA2W(char *)" (?CA2W@@YAPADPAD@Z) already defined in Direct3D.objInput.obj : error LNK2005: "char * __cdecl CA2W(char *)" (?CA2W@@YAPADPAD@Z) already defined in Direct3D.objLogic.obj : error LNK2005: "char * __cdecl CA2W(char *)" (?CA2W@@YAPADPAD@Z) already defined in Direct3D.objLoop.obj : error LNK2005: "char * __cdecl CA2W(char *)" (?CA2W@@YAPADPAD@Z) already defined in Direct3D.objRender.obj : error LNK2005: "char * __cdecl CA2W(char *)" (?CA2W@@YAPADPAD@Z) already defined in Direct3D.objWinMain.obj : error LNK2005: "char * __cdecl CA2W(char *)" (?CA2W@@YAPADPAD@Z) already defined in Direct3D.obj
You can ignore this question if you like. It isn't of that much importance (unless it has something to do with my first problem) because I can just include it in one of my ".cpp" files and it works fine.
Thanks in advance[attention]
[Edited by - Mr Krackers on March 6, 2008 12:08:39 PM]
put the textures i nthe same folder as the .exe, and while you're at it, put them in the same folder as the project file.
because you're loading the filepath directly from the .x file, and its probobly just relative to either the .exe/project folder (depending on where you're running the program from) , or relative to the .x file, if you open up the .x file you could tinker the with filepaths, or just test my theory by putting copies of those files in the 3 places i mentioned
because you're loading the filepath directly from the .x file, and its probobly just relative to either the .exe/project folder (depending on where you're running the program from) , or relative to the .x file, if you open up the .x file you could tinker the with filepaths, or just test my theory by putting copies of those files in the 3 places i mentioned
Quote:Original post by Mr Krackers
I also have another problem (sorry). I have only one header file in my program, and it includes all the default DirectX include files needed for my program. However, when I try to include <atlbase.h>, the program has the following errors:
*** Source Snippet Removed ***
You can ignore this question if you like. It isn't of that much importance (unless it has something to do with my first problem) because I can just include it in one of my ".cpp" files and it works fine.
Thanks in advance[attention]
also (by the way sorry for not putting all this in the same post, i get ideas in shifts :) )
put this as the first line of your header file
//---------
#ifndef HEADER_H
#define HEADER_H
//------------
and this part, as the last line of the header file
#endif
that will probobly get rid of the redefintion problems
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement