Skip to main content
gamedev.net
🔒 Locked

Bloodshed woes w/ DirectX

Started by ItsHercule 10 replies 3.8k views
Original Post
ItsHercule
ItsHercule
While I am waiting for my working Visual Studio to come in the mail, I am chugging along figuring this stuff out and I get to the beginnings of Direct3D with Blooshed's compiler. Try to compile the source code from the book (which states it is Dev-C++ compliant) and it chokes over and over. I have tried downloading devpaks, linking this, linking that, etc. Below is the code and its related parts that it chokes on:

#include <d3dx9.h>

LPDIRECT3D9 d3d = NULL;
LPDIRECT3DDEVICE9 d3ddev = NULL;

int Game_Init(HWND hwnd) {
    d3d = Direct3DCreate9(D3D_SDK_VERSION); // Problem Line?
    
    if (d3d == NULL) {
        MessageBox(hwnd, "Error Initializing Direct3D", "Critical Error!", MB_OK);
        return 0;
    }
    
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    
    d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
    if (d3ddev == NULL) {
        MessageBox(hwnd, "Error Creating Direct3D Device", "Critical Error!", MB_OK);
        return 0;
    }
    
    return 1;
}
The error: [Linker error] undefined reference to `Direct3DCreate9@4' Now I am ultimately confused on who or what I should be linking. On one hand I have the microsoft SDK files to link to and on the other I have the DevPak files that are already being linked now and may or may not be conflicting with the microsoft files that are supposedly being linked. Thanks for the help.
sakky
sakky
I Love newbies ;) ...

Hey dude you are NOT including the main Direct3D header AND you are probably now linking the main Direct3D library. He he, don't sweat it because I screw up like that a lot and forget them too.

So any ways, try adding #include and linking with D3D9.LIB. That will probably fix you problems. If it doesn't then post back and I'll try again.
Take back the internet with the most awsome browser around, FireFox
Raloth
Raloth
Quote:
Original post by sakky
I Love newbies ;) ...

Hey dude you are NOT including the main Direct3D header AND you are probably now linking the main Direct3D library. He he, don't sweat it because I screw up like that a lot and forget them too.

So any ways, try adding #include and linking with D3D9.LIB. That will probably fix you problems. If it doesn't then post back and I'll try again.

d3dx9.h includes d3d9.h. Though the linker error is because he hasn't linked the lib.
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
ItsHercule
ItsHercule
Well all those were already done in the first place.... unfortunately. To clarify here is the source of all 3 files involved in the project. (firstdirectx.cpp, game.h, game.cpp)

My linker also links the following:
../../../mssdk/Lib/d3d9.lib


game.h
#ifndef _GAME_H#define _GAME_H#define APPTITLE "Direct3D (Windowed)"#define FULLSCREEN 1#define SCREEN_WIDTH 1024#define SCREEN_HEIGHT 768int Game_Init(HWND);void Game_Run(HWND);void Game_End(HWND);#endif


game.cpp
#include <windows.h>#include <time.h>#include <stdio.h>#include <stdlib.h>#include <d3dx9.h>#include "game.h"// Global VariablesLPDIRECT3D9 d3d = NULL;LPDIRECT3DDEVICE9 d3ddev = NULL;int Game_Init(HWND hwnd) {    d3d = Direct3DCreate9(D3D_SDK_VERSION);        if (d3d == NULL) {        MessageBox(hwnd, "Error Initializing Direct3D", "Critical Error!", MB_OK);        return 0;    }        D3DPRESENT_PARAMETERS d3dpp;    ZeroMemory(&d3dpp, sizeof(d3dpp));    d3dpp.Windowed = TRUE;    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;        d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);    if (d3ddev == NULL) {        MessageBox(hwnd, "Error Creating Direct3D Device", "Critical Error!", MB_OK);        return 0;    }        return 1;}void Game_Run(HWND hwnd) {    if (d3ddev == NULL) {        return;    }        d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 255, 255), 1.0f, 0);        if (d3ddev->BeginScene()) {        d3ddev->EndScene();    }        d3ddev->Present(NULL, NULL, NULL, NULL);}void Game_End(HWND hwnd) {    if (d3ddev != NULL) {        d3ddev->Release();    }        if (d3d != NULL) {        d3d->Release();    }}


firstdirectx.cpp (should rename this to main.cpp!)
#include <windows.h>#include "game.h"// Function PrototypesLRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM);ATOM MyRegisterClass(HINSTANCE hInstance);BOOL InitInstance(HINSTANCE hInstance, int nCmdShow);ATOM MyRegisterClass(HINSTANCE hInstance) {    WNDCLASSEX wc;    wc.hInstance = hInstance;    wc.lpszClassName = APPTITLE;    wc.lpfnWndProc = (WNDPROC)WinProc;    wc.style = CS_DBLCLKS;    wc.cbSize = sizeof(WNDCLASSEX);    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);    wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);    wc.hCursor = LoadCursor(NULL, IDC_ARROW);    wc.lpszMenuName = NULL;    wc.cbClsExtra = 0;    wc.cbWndExtra = 0;    wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);        return RegisterClassEx(&wc);}BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) {    HWND hwnd;    DWORD style;        if (FULLSCREEN) {        style = WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP;    } else {        style = WS_OVERLAPPED;    }    hwnd = CreateWindowEx(0, APPTITLE, APPTITLE, style, CW_USEDEFAULT, CW_USEDEFAULT, SCREEN_WIDTH, SCREEN_HEIGHT, HWND_DESKTOP, NULL, hInstance, NULL);        if (!hwnd) {        return FALSE;    }    ShowWindow(hwnd, nCmdShow);    UpdateWindow(hwnd);    return TRUE;}int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) {    MSG msg;    HWND hwnd;    DWORD style;    int done = 0;        MyRegisterClass(hInstance);        // Removed for DirectX    // if (!InitInstance(hInstance, nCmdShow)) {    //     return FALSE;    // }    if (FULLSCREEN) {        style = WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP;    } else {        style = WS_OVERLAPPED;    }        hwnd = CreateWindowEx(0, APPTITLE, APPTITLE, style, CW_USEDEFAULT, CW_USEDEFAULT, SCREEN_WIDTH, SCREEN_HEIGHT, HWND_DESKTOP, NULL, hInstance, NULL);    if (!hwnd) {        return FALSE;    }    ShowWindow(hwnd, nCmdShow);    UpdateWindow(hwnd);    if (!Game_Init(hwnd)) {        return 0;    }    while (!done) {        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {            if (msg.message == WM_QUIT)                done = 1;                        TranslateMessage(&msg);            DispatchMessage(&msg);        } else {            Game_Run(hwnd);        }    }    return msg.wParam;}LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {    switch (message)    {        case WM_DESTROY:            Game_End(hwnd);            PostQuitMessage(0);            return 0;        default:            return DefWindowProc(hwnd, message, wParam, lParam);    }}


I think I am going on about 5-6 hours on searching google on such a noobish problem... I think my eyes are going to bleed.
ItsHercule
ItsHercule
As a side question.. should I not be using microsoft's dx9 sdk in favor of bloodshed's dx9 "devpack"?
Ainokea
Ainokea
Quote:
Original post by ItsHercule
As a side question.. should I not be using microsoft's dx9 sdk in favor of bloodshed's dx9 "devpack"?

Use the Dev-C++'s devpack because the library files for GCC (Dev-C++s compiler) are diffrent then the ones Micrsoft gives you in its SDK.

Please, correct me if I am wrong, though if I am wrong I do know that Dev-C++'s devpack works because I use it.
______________With the flesh of a cow.
ItsHercule
ItsHercule
Well that could be part of the problem. I was linking to c:/mssdk/Lib/d3d9.lib. I tried to switch it to Bloodshed's /lib/d3dx9.lib (since there is no d3d9.lib), but still same problem. Should I have a d3d9.lib somewhere?
Ainokea
Ainokea
You need to link to quite a few things, goto project options->Parameter->Linker, and then paste this inside:

-lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32

Note: You might not need all of those.
Note2: Place the necessary DirectX dll files inside your project directory.
Note3: This is probally a bad way to do it but thats how I do it and it works.
______________With the flesh of a cow.
christian h
christian h
Here's what I have in my 'Dev-Cpp/lib/':

libd3d9.a
libd3dim.a
libd3drm.a
libd3dx9d.a

So you should add '-ld3d9' to linker options in the project settings. There's no *.lib for Dev-Cpp, since the GCC uses *.a for static libraries. So if you do have *.lib files in your lib/ folder.. remove them!

ch.
ItsHercule
ItsHercule
Well I pasted that and still the same error

 C:\Dev-Cpp\Projects\FirstDirectX\game.o(.text+0x18) In function `Z9Game_InitP6HWND__':   [Linker error] undefined reference to `Direct3DCreate9@4'  C:\Dev-Cpp\Projects\FirstDirectX\game.o(.text+0x18) ld returned 1 exit status  C:\Dev-Cpp\Projects\FirstDirectX\Makefile.win [Build Error]  [firstdirectx.exe] Error 1 


What do you mean by Note2: Place the necessary DirectX dll files inside your project directory.?
ItsHercule
ItsHercule
Well la di da!

christian h's post did it!!

Looking over Ainokea's linker stuff, I see that they do not have -ld3d9 in their list? How do your DirectX files work then?

All in all, thank you everybody for your threads and finally getting this working! You were all a great help and have furthered my understanding about this stuff tenfold! Thank you!
sakky
sakky
So can I have my cookie now? LOL
Take back the internet with the most awsome browser around, FireFox

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.