|
Thanks for the reply.
But I tried to change the time threshold. (I changed the threshold from 2 to 60)
The result is the same. Timeout still be happened.
So I think that the main problem is not about timing.
According to the experiment, it looks like there is another problem...
|
|
|
|
|
That is not what i meant...but if you are on to something then forget it
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
Get a stopwatch and time how long it takes for APIFuncA() to run. From your symptoms it looks like the thread's exiting before APIFuncA() has run to completion.
I'd try simplifying your code - all that mucking about with Windows messages and threads is enough to give anyone a headache. How do you know that APIFuncA() has completed? There must be some indication somewhere.
Cheers,
Ash
modified on Wednesday, June 23, 2010 2:06 PM
|
|
|
|
|
Thanks for the reply.
The problem which I occurred is about APIFuncB(), not APIFuncA()
Accroding to the document, APIFuncA() returns an int value.
And does't need any waiting mechanism on APIFuncA().
But about APIFuncB(), the document only mentioned two points.
1 : APIFuncB() is asynchronous. When I call APIFuncB(), I must wait for PostThreadMessage of API.
And the message which API sent is SUCCESS_MSG and ERROR_MSG .
When I received the SUCCESS_MSG, I can call the subsequent API functions to do next steps.
2 : The timeout value of APIFuncB() is 1 second, so it suggest the timeout value in my program is 2 seconds.
And the document doesn't describe how to implement the waiting mechanism. I must implement by myself.
That's why I use SetTimer()、WaitPostThreadMessage()、TimerFunc() to implement the waiting mechanism.
Based on my code which posted in this article thread, I think that when I call APIFuncB(),
the created thread is still running, not ended.
Is my thought wrong ?
|
|
|
|
|
Hi
I'm creating a 3D app which the main purpose for it is to be a game engine renderer. The file format that I will use for geometry is the RAW Triangle, since it is very simple to understand. I've created a function able to read the entire 3d file and parse it to a IDirect3DVertexBuffer9. Things are going fine here, but the problem is when it becomes rendered. I'm not getting the full object rendered, it seems that file is corrupted.
|
|
|
|
|
ant-damage wrote: Things are going fine here, but the problem is when it becomes rendered. I'm not getting the full object rendered, it seems that file is corrupted.
Without seeing the code it is hard to know, but when you issue the call from your VertexBuffer are you setting the size and stride values correctly?
Tutorial on IDirect3DVertexBuffer9()[^]
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
Yes. I used that tutorial from "drunkenhyena.com" to understand more about the direct 3d
The code I'm working is huge.
Here is the whole code.
main.cpp
#include "common.h"
#pragma comment(lib, "d3d9")
#pragma comment(lib, "user32")
#pragma comment(lib, "gdi32")
extern IDirect3D9 *g_d3d9;
extern IDirect3DDevice9 *g_device;
extern D3DPRESENT_PARAMETERS g_pparams;
extern const unsigned Width;
extern const unsigned Height;
extern HRESULT Init_d3d9(IDirect3D9 **d3d9);
extern void Init_pparams(HWND hwnd, D3DFORMAT format, D3DFORMAT depth, D3DPRESENT_PARAMETERS *pparams);
extern HRESULT Init_device(IDirect3D9 *d3d9, HWND hwnd, D3DPRESENT_PARAMETERS *pparams, IDirect3DDevice9 **device);
extern void Kill_d3d9(IDirect3D9 **d3d9, IDirect3DDevice9 **device);
HRESULT load_RAW(const char *fname, IDirect3DVertexBuffer9 **buffer, int *count)
{
HRESULT hr = E_FAIL;
FILE *f = fopen(fname, "r");
if(f)
{
(*count) = 0;
float tmp[3] = {0};
while(fscanf(f, "%g %g %g", &tmp[0], &tmp[1], &tmp[2]) == 3)(*count)++;
rewind(f);
HUD_VERTEX vert[(*count)];
memset(vert, 0, sizeof(vert));
for(int i = 0; i < (*count); i++)
{
fscanf(f, "%g %g %g", &(vert[i].x), &(vert[i].y), &(vert[i].z));
if(ferror(f))
{
fclose(f);
return hr;
}
}
fclose(f);
int byteLen = sizeof(vert);
hr = g_device->CreateVertexBuffer(byteLen, D3DUSAGE_WRITEONLY, HUD_VERTEX_fvf, D3DPOOL_MANAGED, buffer, NULL);
if(FAILED(hr))return hr;
void *ptr = NULL;
hr = (*buffer)->Lock(0, 0, &ptr, 0);
if(FAILED(hr))return hr;
memcpy(ptr, vert, byteLen);
hr = (*buffer)->Unlock();
if(FAILED(hr))return hr;
}
fclose(f);
return hr;
}
void Resources_Init()
{
}
void Resources_Free()
{
}
HRESULT Device_Render(IDirect3DVertexBuffer9 *buffer, int count)
{
HRESULT hr = D3D_OK;
hr = g_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_COLORVALUE(1.0, 1.0, 1.0, 1.0), 0.0, 0);
if(FAILED(hr))return hr;
hr = g_device->BeginScene();
if(FAILED(hr))return hr;
g_device->SetFVF(HUD_VERTEX_fvf);
g_device->SetStreamSource(0, buffer, 0, sizeof(HUD_VERTEX));
g_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, count);
g_device->EndScene();
g_device->Present(NULL, NULL, NULL, NULL);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_KEYDOWN:
case WM_CLOSE:
case WM_LBUTTONDOWN:
PostQuitMessage(0);
return 0;
default: return DefWindowProc(hwnd, message, wParam, lParam);
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
WNDCLASS wc;
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "Render";
RegisterClass(&wc);
HWND hwnd = CreateWindow("Render", "Test window", WS_POPUP | WS_VISIBLE, 0, 0, Width, Height, NULL, NULL, hInstance, NULL);
HRESULT hr = D3D_OK;
hr = Init_d3d9(&g_d3d9);
if(FAILED(hr))
{
LOG("Init_d3d9() failed!", hr);
DestroyWindow(hwnd);
return 0;
}
Init_pparams(hwnd, D3DFMT_A8R8G8B8, D3DFMT_D24S8, &g_pparams);
hr = Init_device(g_d3d9, hwnd, &g_pparams, &g_device);
if(FAILED(hr))
{
LOG("Init_device() failed!", hr);
Kill_d3d9(&g_d3d9, &g_device);
DestroyWindow(hwnd);
return 0;
}
int circleTriangles = 0;
IDirect3DVertexBuffer9 *circle = NULL;
hr = load_RAW("circle.raw", &circle, &circleTriangles);
if(FAILED(hr))
{
LOG("load_RAW() failed!", hr);
Kill_d3d9(&g_d3d9, &g_device);
DestroyWindow(hwnd);
return 0;
}
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
hr = Device_Render(circle, circleTriangles + 1);
if(FAILED(hr))
{
LOG("Device_Render() failed!", hr);
Kill_d3d9(&g_d3d9, &g_device);
DestroyWindow(hwnd);
return 0;
}
hr = g_device->TestCooperativeLevel();
if(FAILED(hr))
{
LOG("TestCooperativeLevel() failed!", hr);
Kill_d3d9(&g_d3d9, &g_device);
DestroyWindow(hwnd);
return 0;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Kill_d3d9(&g_d3d9, &g_device);
DestroyWindow(hwnd);
return msg.wParam;
}
d3d9_api.cpp
#include "common.h"
IDirect3D9 *g_d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
IDirect3DDevice9 *g_device = NULL;
D3DPRESENT_PARAMETERS g_pparams = {0};
extern const unsigned Width = GetSystemMetrics(SM_CXSCREEN);
extern const unsigned Height = GetSystemMetrics(SM_CYSCREEN);
HRESULT Init_d3d9(IDirect3D9 **d3d9)
{
LOG(__FUNCTION__);
(*d3d9) = Direct3DCreate9(D3D_SDK_VERSION);
if(!(*d3d9))return E_FAIL;
else return D3D_OK;
}
void Init_pparams(HWND hwnd, D3DFORMAT format, D3DFORMAT depth, D3DPRESENT_PARAMETERS *pparams)
{
LOG(__FUNCTION__);
memset(pparams, 0, sizeof(D3DPRESENT_PARAMETERS));
pparams->BackBufferCount = 1;
pparams->MultiSampleType = D3DMULTISAMPLE_NONE;
pparams->MultiSampleQuality = 0;
pparams->SwapEffect = D3DSWAPEFFECT_DISCARD;
pparams->hDeviceWindow = hwnd;
pparams->Flags = 0;
pparams->FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
pparams->PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
pparams->BackBufferFormat = format;
if(depth == D3DFMT_UNKNOWN)pparams->EnableAutoDepthStencil = false;
else pparams->EnableAutoDepthStencil = true;
pparams->AutoDepthStencilFormat = depth;
pparams->Windowed = false;
pparams->BackBufferWidth = Width;
pparams->BackBufferHeight = Height;
}
HRESULT Init_device(IDirect3D9 *d3d9, HWND hwnd, D3DPRESENT_PARAMETERS *pparams, IDirect3DDevice9 **device)
{
LOG(__FUNCTION__);
HRESULT hr = d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, pparams, device);
return hr;
}
void Kill_d3d9(IDirect3D9 **d3d9, IDirect3DDevice9 **device)
{
LOG(__FUNCTION__);
if((*device))
{
(*device)->Release();
(*device) = NULL;
}
if((*d3d9))
{
(*d3d9)->Release();
(*d3d9) = NULL;
}
}
extern void Resources_Init();
extern void Resources_Free();
HRESULT Reset_device(IDirect3DDevice9 *device, D3DPRESENT_PARAMETERS *pparams, HRESULT hr)
{
if(hr == D3DERR_DEVICELOST)
{
Resources_Free();
Sleep(500);
}
else if(hr == D3DERR_DEVICENOTRESET)
{
hr = device->Reset(pparams);
if(SUCCEEDED(hr))Resources_Init();
}
return hr;
}
common.h
#include <d3d9.h>
#include <stdio.h>
class gameLog
{
public:
gameLog(const char *file = "log.log")
{
FILE *f = fopen(file, "w");
fclose(f);
}
void operator()(const char *str, HRESULT hr = D3D_OK, const char *file = "log.log")
{
FILE *f = fopen(file, "a");
if(hr != D3D_OK) fprintf(f, "%s\tHRESULT: %#x\n", str, hr);
else fprintf(f, "%s\n", str);
fclose(f);
}
};
static gameLog LOG;
struct HUD_VERTEX
{
float x, y, z, rhw;
unsigned color;
};
const unsigned HUD_VERTEX_fvf = D3DFVF_XYZRHW | D3DFVF_DIFFUSE;
typedef HRESULT (WINAPI *D3DXCreateTextureFromFile_ENTRY)(IDirect3DDevice9 *pDevice, LPCTSTR pSrcFile, IDirect3DTexture9 **ppTexture);
inline HRESULT WINAPI D3DXCreateTextureFromFile(IDirect3DDevice9 *pDevice, LPCTSTR pSrcFile, IDirect3DTexture9 **ppTexture)
{
HINSTANCE hlib = LoadLibrary("d3dx9.dll");
if(hlib)
{
#ifdef UNICODE
D3DXCreateTextureFromFile_ENTRY func = (D3DXCreateTextureFromFile_ENTRY)GetProcAddress(hlib, "D3DXCreateTextureFromFileW");
#else
D3DXCreateTextureFromFile_ENTRY func = (D3DXCreateTextureFromFile_ENTRY)GetProcAddress(hlib, "D3DXCreateTextureFromFileA");
#endif
if(func)return func(pDevice, pSrcFile, ppTexture);
else return E_FAIL;
}
else return E_FAIL;
}
|
|
|
|
|
I did kind-of ask for that didn't I?? Okay... That's gonna take me a bit to look through....
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
By the way I'm using Blender 2.49a for exporting the geometry files
Here
HRESULT load_RAW(const char *fname, IDirect3DVertexBuffer9 **buffer, int *count)
{
HRESULT hr = E_FAIL;
FILE *f = fopen(fname, "r");
if(f)
{
(*count) = 0;
float tmp[3] = {0};
while(fscanf(f, "%g %g %g", &tmp[0], &tmp[1], &tmp[2]) == 3)(*count)++;
rewind(f);
HUD_VERTEX vert[(*count)];
memset(vert, 0, sizeof(vert));
for(int i = 0; i < (*count); i++)
{
fscanf(f, "%g %g %g", &(vert[i].x), &(vert[i].y), &(vert[i].z));
if(ferror(f))
{
fclose(f);
return hr;
}
}
fclose(f);
int byteLen = sizeof(vert);
hr = g_device->CreateVertexBuffer(byteLen, D3DUSAGE_WRITEONLY, HUD_VERTEX_fvf, D3DPOOL_MANAGED, buffer, NULL);
if(FAILED(hr))return hr;
void *ptr = NULL;
hr = (*buffer)->Lock(0, 0, &ptr, 0);
if(FAILED(hr))return hr;
memcpy(ptr, vert, byteLen);
hr = (*buffer)->Unlock();
if(FAILED(hr))return hr;
}
fclose(f);
return hr;
}
And here
HRESULT Device_Render(IDirect3DVertexBuffer9 *buffer, int count)
{
HRESULT hr = D3D_OK;
hr = g_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_COLORVALUE(1.0, 1.0, 1.0, 1.0), 0.0, 0);
if(FAILED(hr))return hr;
hr = g_device->BeginScene();
if(FAILED(hr))return hr;
g_device->SetFVF(HUD_VERTEX_fvf);
g_device->SetStreamSource(0, buffer, 0, sizeof(HUD_VERTEX));
g_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, count);
g_device->EndScene();
g_device->Present(NULL, NULL, NULL, NULL);
}
|
|
|
|
|
I have never looked at the RAW output from Blender, and without compiling this only one thing "jumps" out at me....
g_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, count);
Are you sure that Blender is outputting a Triangle Strip or a list of triangles?
http://en.wikipedia.org/wiki/File:Triangle_Strip_Small.png[^]
In this example a Triangle strip would be vertexes A, B, C, D, E, F.
But a list of triangles would be:
A,B,C, C,B,D, E,C,D, F,E,D
You can see how incorrectly sending the right destination from one to the other could render with bizarre results....
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
Blender is outputting a strange kind of list of triangles. For instance, a circle, it seems that Blender is outputting a triangle fan.
|
|
|
|
|
ant-damage wrote: it seems that Blender is outputting a triangle fan.
Then you will need to define this as a triangle fan for display....
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
I think that I've found the solution for my problem here.
|
|
|
|
|
The RAW Triangle Format is parsed by reading lines, not individual values. That was what I didn't know.
|
|
|
|
|
congrats on finding it! I never worked with raw, we use other model formats.
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
By the way, which formats do you use?
|
|
|
|
|
3dStudio, OpenFlight... Mostly
basically everything supported by open scene graph.
I haven't written my own loader for years.
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
Hey, i just wanted to ask if theres a way i can read the data of a file so i can paste it to another file?
Like i read the data of cmd.exe and paste it to whatever.exe?
|
|
|
|
|
Please be clear what you are asking.
ALLERSLIT wrote: i can read the data of a file so i can paste it to another file?
cmd.exe is not a file to be read from, it's an executable.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Executables are files though
|
|
|
|
|
and an ice cube is water. What's your point?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
That it's fine to read from cmd.exe, it's just unusual
|
|
|
|
|
I believe we are going to need more details about what you want to do...till now it sounds like you either want to read file data to the clipboard to paste it somewhere OR you need a filecopy method (like copy in a dos prompt).
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
I want to create a program out of a program.
We all have a cmd.exe in our windows folder, how would i be able to create the cmd.exe out of my own program?
|
|
|
|
|
What would your program do?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|