Sign in to follow this  
Hauw

Just started 3D programming (C++)

Recommended Posts

Hello guys, I'm rather a new member of this forum. I've just had 2 years of experience in coding with C++ and I had experience with 2D games using SDL. However I'm stuck with 3D games, so I helped myself by google-ing several 3D tutorials. One of them is understandable to me, however, it won't compile. I've tried to download SDK, however with my lame 256kbps connection, downloading 556 MB file is rather impossible. Could someone fix it? Source : http://www.directxtutorial.com/tutorial9/b-direct3dbasics/dx9B1.aspx #include <windows.h> #include <windowsx.h> #include <d3d9.h> // include the Direct3D Library file #pragma comment (lib, "d3d9.lib") // global declarations LPDIRECT3D9 d3d; // the pointer to our Direct3D interface LPDIRECT3DDEVICE9 d3ddev; // the pointer to the device class // function prototypes void initD3D(HWND hWnd); // sets up and initializes Direct3D void render_frame(void); // renders a single frame void cleanD3D(void); // closes Direct3D and releases memory // the WindowProc function prototype LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); // the entry point for any Windows program int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hWnd; WNDCLASSEX wc; ZeroMemory(&wc, sizeof(WNDCLASSEX)); wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)COLOR_WINDOW; wc.lpszClassName = L"WindowClass"; RegisterClassEx(&wc); hWnd = CreateWindowEx(NULL, L"WindowClass", L"Our First Direct3D Program", WS_OVERLAPPEDWINDOW, 300, 300, 800, 600, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); // set up and initialize Direct3D initD3D(hWnd); // enter the main loop: MSG msg; while(TRUE) { while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } if(msg.message == WM_QUIT) break; render_frame(); } // clean up DirectX and COM cleanD3D(); return msg.wParam; } // this is the main message handler for the program LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_DESTROY: { PostQuitMessage(0); return 0; } break; } return DefWindowProc (hWnd, message, wParam, lParam); } // this function initializes and prepares Direct3D for use void initD3D(HWND hWnd) { d3d = Direct3DCreate9(D3D_SDK_VERSION); // create the Direct3D interface D3DPRESENT_PARAMETERS d3dpp; // create a struct to hold various device information ZeroMemory(&d3dpp, sizeof(d3dpp)); // clear out the struct for use d3dpp.Windowed = TRUE; // program windowed, not fullscreen d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames d3dpp.hDeviceWindow = hWnd; // set the window to be used by Direct3D // create a device class using this information and the info from the d3dpp stuct d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev); } // this is the function used to render a single frame void render_frame(void) { // clear the window to a deep blue d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0); d3ddev->BeginScene(); // begins the 3D scene // do 3D rendering on the back buffer here d3ddev->EndScene(); // ends the 3D scene d3ddev->Present(NULL, NULL, NULL, NULL); // displays the created frame on the screen } // this is the function that cleans up Direct3D and COM void cleanD3D(void) { d3ddev->Release(); // close and release the 3D device d3d->Release(); // close and release Direct3D } Errors : Line 38 cannot convert `const wchar_t[12]' to `const CHAR*' in assignment Line 51 [Warning] converting to non-pointer type `DWORD' from NULL Line 51 cannot convert `const wchar_t*' to `const CHAR*' for argument `2' to `HWND__* CreateWindowExA(DWORD, const CHAR*, const CHAR*, DWORD, int, int, int, int, HWND__*, HMENU__*, HINSTANCE__*, void*)' And also, I had several questions in my mind. Could someone answer them? 1. How do I load and display 3D models in C++? (the syntax) 2. Does I need external libraries such as SDL to load and display images? 3. With my 2D game, I've tried loading 500+ images worth of 7Mb in my compiler, and it takes at least 2 seconds to finish. 3D models looks like 2 minutes of loading (goodies O.o). Is it avoidable, and how? Better compiler, or 3D engines? 4. Figures of from question number 3, how does several large-sized games, load images, skins, musics, etc, just in seconds? Many thanks!! Your help is appreciated =D

Share this post


Link to post
Share on other sites
You will need files from the sdk to compile DirectX projects. So you better find a friend to download it for you and burn it on a DVD. The example projects in the SDK will also answer your questions.

3. The compiler does not load any images. It will only compile the code.

Share this post


Link to post
Share on other sites
Quote:
I'm using Dev-C++

You should really consider switching to a different compiler/IDE. Microsoft Visual C++ 2008 Express Edition is great and it's free. I know you have slow download speeds, but if you can find a friend (as mentioned above) to download the SDK for you, ask them to download this for you too.

Also, don't use that website. See here and here. Especially pay attention to Evil Steve's posts in the second one.

Share this post


Link to post
Share on other sites
I've once tried compiling DirectX applications with Code::Blocks and had nothing but problems- trying it with Dev-C++ must be a nightmare. I can't suggest anything other than Visual C++ for working with DirectX. I've used it for over a year and a half and haven't turned back.

Evil Steve's tutorials are a good way to start out learning DirectX. There's also the ones by Chad Vernon which are more concise, but still pretty good.

Share this post


Link to post
Share on other sites
I second (or third) the vote for getting a good IDE (Visual Studio 2008). You'll learn faster.

Also, if you're just getting into programming of the type you posted, change the programming style now! Every DirectX function gives some indication if it's successful or not. Even when you get it compiled (and you will), you will have errors during execution, even if it compiles.

The programming style you posted says: "I'm not going to check for any errors whatsoever. Hope it runs."

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this