link102

Members
  • Content count

    19
  • Joined

  • Last visited

Community Reputation

252 Neutral

About link102

  • Rank
    Member
  1. It's working now. I used the method (poorly) described here and it magically worked: http://bassser.tumblr.com/post/11626074256/reconstructing-position-from-depth-buffer I'm still struggling a bit with the names of all the coordinate spaces, but I do know that I wasn't passing the correct coordinate space to the inverse projection matrix. I believe it wants NDC space coordinates and I was passing it screen space so I had to divide by w first or something like that, I'm stil looking into it.
  2. For the past 3 days I've been trying to get ssao working without much result. I've narrowed the problem down to the way I'm converting screen coordinates to view coordinates and back again. Below is the code I use to test the conversion.   Attached are the results of the shader and the depth buffer. [removed for now, please check back later]   Anyone able to point out what's going wrong here? Are the screenToViewSpace & viewToScreenSpace functions correct? #version 420 in vec2 vTexCoord; in vec3 vNormal; layout(binding = 0) uniform sampler2D uTexDiffuse; layout(binding = 2) uniform sampler2D uTexDepth; uniform mat4 projectionMatrix; uniform mat4 invProjectionMatrix; out vec4 out_fragColor; vec3 screenToViewSpace(in vec2 texCoord, in float depth) { vec4 position = vec4(texCoord, depth, 1.0); // unpack position.xyz = position.xyz * 2.0 - 1.0; // unproject position = invProjectionMatrix * position; position /= position.w; return position.xyz; } vec2 viewToScreenSpace(in vec3 unprojectedPosition) { vec4 position = vec4(unprojectedPosition, 0.0); // project position = projectionMatrix * position; position /= position.w; // pack position = position * 0.5 + 0.5; return position.xy; } void main() { float depth = texture(uTexDepth, vTexCoord).r; if(vTexCoord.x < 0.5) { // convert to view space, then back to screen space out_fragColor.xy = viewToScreenSpace(screenToViewSpace(vTexCoord, depth)); } else { out_fragColor.xy = vTexCoord; } }
  3. Hi GameDev,   I'm currently working on a game in OpenGL ES 2.0 (Android) and I've ran into a bit of an issue:   I have 2 meshes, both have their own shader object (code below). During initialization I upload the vertexdata (setPositionAttribute & setTextureAttribute). When it's time to draw though, I can only see the 2nd object. So I'm assuming the vertexdata from the 2nd object has replaced the vertexdata from the 1st.   Is this assumption (vertexdata is being shared by all program objects) correct? Is there a way to separate the vertexdata or do I have to upload it each frame?   Edit: problem solved. I forgot to use VBOs. More info here
  4. Is there any way of adding data into the vertice container as if it's an array? [code]struct CUSTOMVERTEX { FLOAT x, y, z; }; CUSTOMVERTEX Vertices[] = { { 0.0f, 0.0f, 0.0f}, { 1.0f, 0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f}, { 1.0f, 0.0f, 1.0f}, }; d3ddev->CreateVertexBuffer(sizeof(Vertices) * sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL); VOID* pVoid; v_buffer->Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, Vertices, sizeof(Vertices)); v_buffer->Unlock();[/code] from that into something like this: [code]// NOTE: speudo code CUSTOMVERTEX Vertices[]; Vertices.add(0.0f, 0.0f, 0.0f); Vertices.add(1.0f, 0.0f, 0.0f); Vertices.add(0.0f, 0.0f, 1.0f); Vertices.add(1.0f, 0.0f, 1.0f); d3ddev->CreateVertexBuffer(sizeof(Vertices) * sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL); VOID* pVoid; v_buffer->Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, Vertices, sizeof(Vertices)); v_buffer->Unlock();[/code] If you're wondering, I'm planning on stuffing this into a for loop.
  5. vertex array

    Alternate tutorial for index buffers: http://www.directxtutorial.com/Tutorial9/B-Direct3DBasics/dx9B7.aspx
  6. Question about cpp classes and objects

    Something screwed up and removed my reply to your last [i]I think your WNDCLASSEX strucure should be zero initialised for safety.[/i] Like this right? WNDCLASSEX wcex = {0}; Why should I zero initialise it? the variable is local (right?), it gets destroyed after the class [s]initiator[/s] constructor ends. [quote]In dynamic languages it makes more sense because there is no static type checker, nor one definitive place you can go to find the type of a variable. Its a minor stylistic issue, don't sweat it if you prefer it. You might find [url="http://www.joelonsoftware.com/articles/Wrong.html"]this[/url] an interesting read though.[/quote] Makes sence, since the compiler will tell me if I have a type mismatch. It's better to note which kind of variable it is instead of which type. One thing though. What do you think of this line? _hInstance = hInstance; (line 12 of windows.h)
  7. Question about cpp classes and objects

    Thank you [i]- Consider using typedef rather than #define for BUTTON though.[/i] Sorted [i]- Type names are generally written in CamelCase. ALL_CAPS is mostly reserved for constants and preprocessor defines such as include guards.[/i] Sorted, but why are all the win32 types in upper case? [i]- Many people consider hungarian notation to be pointless and verbose, but that is just a stylistic issue.[/i] It worked fine on all my php projects. I like the hungarian notation because I distinguish variables from definitions better. (visual studio doesn't highlight them) [i]- You have little or no error checking. Consider exceptions for errors during object construction.[/i] Yea, I am going to do that after I finish this class. I'm planning on making a custom window template for it, since I don't like the standard MessageBox() function.
  8. Need advices to get started

    You didn't break any rules, FAQ = Frequently Asked Questions... and you just happen to ask one. You can find a link to the FAQ above the first post in a topic or by clicking [url="http://www.gamedev.net/index.php?app=forums&module=forums&section=rules&f=31"]here[/url] /helped
  9. Question about cpp classes and objects

    [quote]I'm not really sure what you are asking. The code you've posted isn't C++. Are you posting psuedo code? Are they supposed to be declarations or definitions?[/quote] 1 It's pseudo code because I wasn't sure how to write it in cpp. I'm used to php's method of defining a class (though I haven't tried anything like this in php either). 2 they're declarations. Thank you for your responce, I'll try it right away. Edit: ok, so how am I doing? (in otherwords, do you see anything that should have been coded in another way or might cause problems later on? [b]main.cpp[/b] [source lang="cpp"]#include <windows.h> #include <tchar.h> //build this into an error class later void error(LPCWSTR text){ //MessageBox(NULL, text, "Error", MB_OK | MB_ICONWARNING); } #include "window.h" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { window window("title", hInstance); Button button = window.createButton("Submit", 10, 10, 100, 20); //next: add event listener to the button. //The message loop MSG msg = {0}; while(msg.message != WM_QUIT){ if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); } } return (int)msg.wParam; }[/source] [b]window.h[/b] [source lang="cpp"]typedef HWND Button; class window { public: int _iWidth, _iHeight; HWND _hWnd; HINSTANCE _hInstance; window(LPCTSTR sName, HINSTANCE hInstance) { _iWidth = 800; _iHeight = 600; _hInstance = hInstance; //Fill in the Window class and register it WNDCLASSEX wcex = {0}; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = _hInstance; wcex.hIcon = NULL; wcex.hIconSm = NULL; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = sName; RegisterClassEx(&wcex); //Create the window _hWnd = CreateWindow(sName, sName, WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, _iWidth, _iHeight, NULL, NULL, _hInstance, NULL); if(!_hWnd){ return; } } ////////////////////////////////////////////////////////// // Create Button // Button createButton(LPCTSTR text, int iX, int iY, int iWidth, int iHeight) { return CreateWindow("BUTTON", text, BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, iX, iY, iWidth, iHeight, _hWnd, NULL, _hInstance, NULL); } ////////////////////////////////////////////////////////// // Window Procedure // private: static LRESULT CALLBACK WndProc(HWND _hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ switch(uMsg){ case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(_hWnd, uMsg, wParam, lParam); } };[/source]
  10. 2 Quick questions; Is it possible for a cpp class to stack like so? [code]WINDOW Window("title"); CHILDWINDOW Window.Child("child title"); BUTTON Window.child.Button("Submit", 10, 10, 100, 20);[/code] And is it possible for an object to access a variable from it's parent? (the child window needs to access hInstance and hWnd from the main window) Thank you.
  11. Need a bit of help finding a bug

    Quote:Original post by yewbie IDirect3DSurface9 *surface; IDirect3DSurface9* surface; They function the same.but what does the asteric do? (I know, noob question right >_>) @noidwright Although a bit puzzling for a noob like me, thank you for your feedback. Here's what I changed the notify function to: bool V_RETURN(HRESULT hResult){ if(FAILED(hResult)){ MessageBox(hWnd,DXGetErrorDescription(hResult), DXGetErrorString(hResult), MB_OK | MB_ICONWARNING); return false; } } I'll see if I can implement the safe release later.
  12. Need a bit of help finding a bug

    Quote:Original post by Fl4sh *** Source Snippet Removed *** The hell is this? L"test.bmp" = _T("test.bmp") the line hResult = D3DXLoadSurfaceFromFile(surface, NULL, NULL, L"test.bmp", NULL, D3DX_DEFAULT, 0, NULL); expects a unicode string Quote:Original post by FableFox Ha.. ha.. ha.. Almost all beginners will experience the '==' and '=' thing. Wish I got this tip sooner :-) But since I will do scripting here and there, I'm sure it will be usefull. I've been there, from my experience with php. btw: I've tested to see if it could find the bmp file. It gave me a D3DERR_INVALIDDATA after I renamed it. Meaning the problem does not lie within the name or location of the bmp. I've stil got the D3DERR_INVALIDCALL, just with I knew which parameter is wrong. edit: SOLVED! Thank you very much for you help guys :D, here's the fix: I was trying to see if the test.bmp file had the right format (D3DFMT_X8R8G8B8) turns out it's to big for the surface I was trying to load it on. Final code: (d3d9.lib d3dx9d.lib dxerr.lib included in the editor) #include <windows.h> #include <tchar.h> #include <d3d9.h> #include <d3dx9.h> #include <dxerr.h> HINSTANCE hInst; HWND hWnd; LPDIRECT3D9 pD3D; //the Direct3d object LPDIRECT3DDEVICE9 pd3dDevice; //the Direct3D device IDirect3DSurface9 *surface; int iWidth = 1280; int iHeight = 960; bool InitWindow(HINSTANCE hInstance, int iWidth, int iHeight); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); void notify(HRESULT hResult){ MessageBox(hWnd,DXGetErrorDescription(hResult),DXGetErrorString(hResult),MB_OK | MB_ICONWARNING); } ////////////////// //INITDIRECT3D // bool initDirect3D(HWND hWnd, int iWidth, int iHeight){ pD3D = NULL; pd3dDevice = NULL; HRESULT hResult; if(NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION))){ return false; } D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = FALSE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.BackBufferWidth = iWidth; d3dpp.BackBufferHeight = iHeight; d3dpp.hDeviceWindow = hWnd; hResult = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice); if(FAILED(hResult)){ notify(hResult); return false; } hResult = pd3dDevice->CreateOffscreenPlainSurface(iWidth, iHeight, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL); if(FAILED(hResult)){ notify(hResult); return false; } hResult = D3DXLoadSurfaceFromFile(surface, NULL, NULL, L"test.bmp", NULL, D3DX_DEFAULT, 0, NULL); if(FAILED(hResult)){ notify(hResult); return false; } return true; } //////////// //RENDER // void render(void){ IDirect3DSurface9* backbuffer = NULL; if(pd3dDevice == NULL){ return; } pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(62, 62, 68), 1.0f, 0); pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); pd3dDevice->StretchRect(surface, NULL, backbuffer, NULL, D3DTEXF_NONE); pd3dDevice->Present(NULL, NULL, NULL, NULL); } void cleanUp(void){ if(pd3dDevice != NULL){ pd3dDevice->Release(); } if(pD3D != NULL){ pD3D->Release(); } } int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){ if(!InitWindow(hInstance, iWidth, iHeight)){ return false; } if(!initDirect3D(hWnd, iWidth, iHeight)){ return false; } MSG msg = {0}; while(msg.message != WM_QUIT){ if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); } else { render(); } } cleanUp(); return (int) msg.wParam; } bool InitWindow(HINSTANCE hInstance, int iWidth, int iHeight){ WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = 0; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = TEXT("DirectX 1"); wcex.hIconSm = 0; RegisterClassEx(&wcex); RECT rect = {0, 0, iWidth, iHeight}; AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); hWnd = CreateWindow(TEXT("DirectX 1"), //class name TEXT("DirectX 1"), //window title WS_EX_TOPMOST | WS_POPUP | WS_VISIBLE, CW_USEDEFAULT, //initial x position CW_USEDEFAULT, //initial y postion iWidth, //width iHeight, //height NULL, //parent handle NULL, //menu handle hInstance, //instance handle NULL); if(!hWnd){ return false; } ShowWindow(hWnd, SW_SHOW); UpdateWindow(hWnd); return true; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ switch(message){ case WM_KEYDOWN: switch(wParam){ case VK_ESCAPE: PostQuitMessage(0); break; } break; case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hWnd, message, wParam, lParam); } I stil have a couple of questions? - What's the difference between IDirect3DSurface9 *surface; and IDirect3DSurface9* surface;? - Is the cleanUp() in the correct location (at the end of WinMain) and is it complete enough? - Are there any things you would change about this code that would make it run better or easier to read? Like putting some functions in a separate file or changing some of the code to a object oriented style. - Are there any ways of improving the error reporting? (the notify(); function) [Edited by - link102 on December 10, 2010 6:01:28 AM]
  13. Need a bit of help finding a bug

    first of all thank you for your replies :D I've merged the codes back into 1 file again. Not quite sure yet what the differences between implementation code and function declaration are. Does this backward comparison thing work with other data types? Here's the code so far. It compiles, but has a D3DERR_INVALIDCALL > one of D3DXLoadSurfaceFromFile's parameters is not valid? What does that mean? #include <windows.h> #include <tchar.h> #include <d3d9.h> #include <d3dx9.h> #include <dxerr.h> HINSTANCE hInst; HWND hWnd; LPDIRECT3D9 pD3D; //the Direct3d object LPDIRECT3DDEVICE9 pd3dDevice; //the Direct3D device IDirect3DSurface9* surface; int iWidth = 1280; int iHeight = 960; bool InitWindow(HINSTANCE hInstance, int iWidth, int iHeight); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); void notify(HRESULT hResult){ MessageBox(hWnd,DXGetErrorDescription(hResult),DXGetErrorString(hResult),MB_OK | MB_ICONWARNING); } bool initDirect3D(HWND hWnd, int iWidth, int iHeight){ pD3D = NULL; pd3dDevice = NULL; HRESULT hResult; if(NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION))){ return false; } D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = FALSE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.BackBufferWidth = iWidth; d3dpp.BackBufferHeight = iHeight; d3dpp.hDeviceWindow = hWnd; if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice))){ notify(hResult); return false; } hResult = pd3dDevice->CreateOffscreenPlainSurface(iWidth, iHeight, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL); if(FAILED(hResult)){ notify(hResult); return false; } hResult = D3DXLoadSurfaceFromFile(surface, NULL, NULL, L"test.bmp", NULL, D3DX_DEFAULT, 0, NULL); if(FAILED(hResult)){ notify(hResult); return false; } return true; } void render(void){ IDirect3DSurface9* backbuffer = NULL; if(pd3dDevice == NULL){ return; } pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(62, 62, 68), 1.0f, 0); pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); pd3dDevice->StretchRect(surface, NULL, backbuffer, NULL, D3DTEXF_NONE); pd3dDevice->Present(NULL, NULL, NULL, NULL); } void cleanUp(void){ if(pd3dDevice != NULL){ pd3dDevice->Release(); } if(pD3D != NULL){ pD3D->Release(); } } int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){ if(!InitWindow(hInstance, iWidth, iHeight)){ return false; } if(!initDirect3D(hWnd, iWidth, iHeight)){ return false; } MSG msg = {0}; while(msg.message != WM_QUIT){ if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); } else { render(); } } cleanUp(); return (int) msg.wParam; } bool InitWindow(HINSTANCE hInstance, int iWidth, int iHeight){ WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = 0; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = TEXT("DirectX 1"); wcex.hIconSm = 0; RegisterClassEx(&wcex); RECT rect = {0, 0, iWidth, iHeight}; AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); hWnd = CreateWindow(TEXT("DirectX 1"), //class name TEXT("DirectX 1"), //window title WS_EX_TOPMOST | WS_POPUP | WS_VISIBLE, CW_USEDEFAULT, //initial x position CW_USEDEFAULT, //initial y postion iWidth, //width iHeight, //height NULL, //parent handle NULL, //menu handle hInstance, //instance handle NULL); if(!hWnd){ return false; } ShowWindow(hWnd, SW_SHOW); UpdateWindow(hWnd); return true; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ switch(message){ case WM_KEYDOWN: switch(wParam){ case VK_ESCAPE: PostQuitMessage(0); break; } break; case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hWnd, message, wParam, lParam); } If it's any help here's the debug log: (note I've edited it, watch the "{}") 'Directx 1.exe': Loaded '{my visual studio filepath}\Projects\Directx 1\Debug\Directx 1.exe', Symbols loaded. 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\ntdll.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\kernel32.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\d3d9.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\d3d8thk.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\gdi32.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\user32.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\msvcrt.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\advapi32.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\rpcrt4.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\secur32.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\version.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\winmm.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\D3dx9d_42.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456\msvcr90d.dll', Symbols loaded. 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\imm32.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\lpk.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\usp10.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\uxtheme.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\MSCTF.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\MSCTFIME.IME' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\ole32.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\d3d9d.dll' 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\d3dx9d_33.dll' D3D9 Helper: Enhanced D3DDebugging disabled; Application was not compiled with D3D_DEBUG_INFO 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\d3dref9.dll' Direct3D9: (INFO) :======================= Reference SWVP device selected Direct3D9: (INFO) :Using P4 PSGP D3DX: Source surface data (pvSrcData or cbSrcData) is invalid 'Directx 1.exe': Loaded 'D:\WINDOWS\system32\oleaut32.dll' The thread 'Win32 Thread' (0x108) has exited with code 0 (0x0). repeat this about 200 times { Direct3D9: (ERROR) : [0] : Address 00BEE4CB Direct3D9: (ERROR) : [1] : Address 00BEE59B Direct3D9: (ERROR) : [2] : Address 00BEE440 Direct3D9: (ERROR) : [3] : Address 00BE2DB4 Direct3D9: (ERROR) : [4] : Address 4FD3AF2E Direct3D9: (ERROR) : [5] : Address 004240B0 Direct3D9: (ERROR) : [6] : Address 00411D0E Direct3D9: (ERROR) : [7] : Address 0042BE9B Direct3D9: (ERROR) : [8] : Address 0042BBFF Direct3D9: (ERROR) : [9] : Address 7C7E7077 Direct3D9: (ERROR) : [10] : Address 00000000 Direct3D9: (ERROR) : [11] : Address 00000000 Direct3D9: (ERROR) : [12] : Address 00000000 Direct3D9: (ERROR) : [13] : Address 00000000 Direct3D9: (ERROR) : [14] : Address 00000000 Direct3D9: (ERROR) : [15] : Address 00000000 } The program '[2476] Directx 1.exe: Native' has exited with code 0 (0x0).
  14. Sorry about the bad title, it's not very descriptive. This program is supposed to load a bitmap and output it on the screen. However, the program compiles fine, but when it runs, it just shows a black screen, then exits with no errors. I've traced the bug to "initDirect3D(hWnd, iWith, iHeight)" (in main.cpp). That's where the program ends. What I'd like you to help me with is; A: What did I do wrong? Why isn't this working. B: Is there anything else I should change? Do you notice any pitfalls I might have stepped in or do you see any programming conventions that don't make sense? If you need to know more about this project's setup just ask and I'll post some more details a.s.a.p main.cpp #include <windows.h> #include <tchar.h> #include <d3d9.h> #include <d3dx9.h> #include "direct3D.h" HINSTANCE hInst; HWND hWnd; int iWidth = 1280; int iHeight = 960; bool InitWindow(HINSTANCE hInstance, int iWidth, int iHeight); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){ if(!InitWindow(hInstance, iWidth, iHeight)){ return false; } if(!initDirect3D(hWnd, iWidth, iHeight)){ return false; } MSG msg = {0}; while(msg.message != WM_QUIT){ if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){ TranslateMessage(&msg); DispatchMessage(&msg); } else { render(); } } cleanUp(); return (int) msg.wParam; } bool InitWindow(HINSTANCE hInstance, int iWidth, int iHeight){ WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = 0; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = TEXT("DirectX 1"); wcex.hIconSm = 0; RegisterClassEx(&wcex); RECT rect = {0, 0, iWidth, iHeight}; AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); hWnd = CreateWindow(TEXT("DirectX 1"), //class name TEXT("DirectX 1"), //window title WS_EX_TOPMOST | WS_POPUP | WS_VISIBLE, CW_USEDEFAULT, //initial x position CW_USEDEFAULT, //initial y postion iWidth, //width iHeight, //height NULL, //parent handle NULL, //menu handle hInstance, //instance handle NULL); if(!hWnd){ return false; } ShowWindow(hWnd, SW_SHOW); UpdateWindow(hWnd); return true; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ switch(message){ case WM_KEYDOWN: switch(wParam){ case VK_ESCAPE: PostQuitMessage(0); break; } break; case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hWnd, message, wParam, lParam); } direct3D.h LPDIRECT3D9 pD3D; //the Direct3d object LPDIRECT3DDEVICE9 pd3dDevice; //the Direct3D device IDirect3DSurface9* surface; bool initDirect3D(HWND hWnd, int iWidth, int iHeight){ pD3D = NULL; pd3dDevice = NULL; HRESULT hResult; if(NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION))){ return false; } D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = FALSE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.BackBufferWidth = iWidth; d3dpp.BackBufferHeight = iHeight; d3dpp.hDeviceWindow = hWnd; if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice))){ return false; } hResult = pd3dDevice->CreateOffscreenPlainSurface(iWidth, iHeight, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL); if(FAILED(hResult)){ return NULL; } hResult = D3DXLoadSurfaceFromFile(surface, NULL, NULL, L"test.bmp", NULL, D3DX_DEFAULT, 0, NULL); if(FAILED(hResult)){ return NULL; } return true; } void render(void){ IDirect3DSurface9* backbuffer = NULL; if(pd3dDevice == NULL){ return; } pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(62, 62, 68), 1.0f, 0); pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); pd3dDevice->StretchRect(surface, NULL, backbuffer, NULL, D3DTEXF_NONE); pd3dDevice->Present(NULL, NULL, NULL, NULL); } void cleanUp(void){ if(pd3dDevice != NULL){ pd3dDevice->Release(); } if(pD3D != NULL){ pD3D->Release(); } } thank you. [Edited by - link102 on December 9, 2010 4:12:13 PM]