c++ - Cross compiling Direct3D on Linux with mingw -


how configure mingw32 cross-compile direct3d apps windows? there possibility? have succeeded compiling code tutorial: http://www.directxtutorial.com/tutorial9/b-direct3dbasics/dx9b4.aspx - using code::blocks on kubuntu i586-mingw32msvc-g++. needed add #define unicode , remove #pragma ... parts this, , used header files /usr/i586-mingw32msvc/include , libs mingw package.

however cannot compile code tutorial: http://www.directxtutorial.com/tutorial9/b-direct3dbasics/dx9b5.aspx

mingw doesn't have d3dx9.h file. i've installed wine1.2-dev package wine versions of windows-related header files, have errors:

with #define unicode:

-------------- build: debug in d3d ---------------  i586-mingw32msvc-g++ -wall  -g    -i/usr/include/wine/windows  -c /home/silmeth/programowanie/codeblocks/d3d/main.cpp -o obj/debug/main.o /home/silmeth/programowanie/codeblocks/d3d/main.cpp: in function ‘int winmain(hinstance__*, hinstance__*, char*, int)’: /home/silmeth/programowanie/codeblocks/d3d/main.cpp:50: error: invalid conversion ‘const wchar_t*’ ‘const wchar*’ /home/silmeth/programowanie/codeblocks/d3d/main.cpp:56: error: invalid conversion ‘const wchar_t*’ ‘const wchar*’ /home/silmeth/programowanie/codeblocks/d3d/main.cpp:56: error:   initializing argument 2 of ‘hwnd__* createwindowexw(dword, const wchar*, const wchar*, dword, int, int, int, int, hwnd__*, hmenu__*, hinstance__*, void*)’ /home/silmeth/programowanie/codeblocks/d3d/main.cpp:56: error: invalid conversion ‘const wchar_t*’ ‘const wchar*’ /home/silmeth/programowanie/codeblocks/d3d/main.cpp:56: error:   initializing argument 3 of ‘hwnd__* createwindowexw(dword, const wchar*, const wchar*, dword, int, int, int, int, hwnd__*, hmenu__*, hinstance__*, void*)’ /home/silmeth/programowanie/codeblocks/d3d/main.cpp: in function ‘void render_frame()’: /home/silmeth/programowanie/codeblocks/d3d/main.cpp:158: warning: taking address of temporary /home/silmeth/programowanie/codeblocks/d3d/main.cpp:159: warning: taking address of temporary /home/silmeth/programowanie/codeblocks/d3d/main.cpp:160: warning: taking address of temporary process terminated status 1 (0 minutes, 0 seconds) 5 errors, 3 warnings

and without #define:

 -------------- build: debug in d3d ---------------  i586-mingw32msvc-g++ -wall  -g    -i/usr/include/wine/windows  -c /home/silmeth/programowanie/codeblocks/d3d/main.cpp -o obj/debug/main.o /home/silmeth/programowanie/codeblocks/d3d/main.cpp: in function ‘int winmain(hinstance__*, hinstance__*, char*, int)’: /home/silmeth/programowanie/codeblocks/d3d/main.cpp:50: error: cannot convert ‘const wchar_t [12]’ ‘const char*’ in assignment /home/silmeth/programowanie/codeblocks/d3d/main.cpp:56: error: cannot convert ‘const wchar_t*’ ‘const char*’ argument ‘2’ ‘hwnd__* createwindowexa(dword, const char*, const char*, dword, int, int, int, int, hwnd__*, hmenu__*, hinstance__*, void*)’ /home/silmeth/programowanie/codeblocks/d3d/main.cpp: in function ‘void render_frame()’: /home/silmeth/programowanie/codeblocks/d3d/main.cpp:158: warning: taking address of temporary /home/silmeth/programowanie/codeblocks/d3d/main.cpp:159: warning: taking address of temporary /home/silmeth/programowanie/codeblocks/d3d/main.cpp:160: warning: taking address of temporary process terminated status 1 (0 minutes, 0 seconds) 2 errors, 3 warnings

here whole code i'm trying compile:

// include basic windows header files , direct3d header file #define unicode //tried comment , uncomment #include <windows.h> #include <windowsx.h> #include <d3d9.h> #include <d3dx9.h>  // define screen resolution #define screen_width 800 #define screen_height 600  // include direct3d library files //#pragma comment (lib, "d3d9.lib") //#pragma comment (lib, "d3dx9.lib")  // global declarations lpdirect3d9 d3d;    // pointer our direct3d interface lpdirect3ddevice9 d3ddev;    // pointer device class lpdirect3dvertexbuffer9 v_buffer = null;    // pointer vertex buffer  // function prototypes void initd3d(hwnd hwnd);    // sets , initializes direct3d void render_frame(void);    // renders single frame void cleand3d(void);    // closes direct3d , releases memory void init_graphics(void);    // 3d declarations  struct customvertex {float x, y, z; dword color;}; #define customfvf (d3dfvf_xyz | d3dfvf_diffuse)  // windowproc function prototype lresult callback windowproc(hwnd hwnd, uint message, wparam wparam, lparam lparam);   // entry point 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.lpszclassname = l"windowclass";      registerclassex(&wc);      hwnd = createwindowex(null, l"windowclass", l"our direct3d program",                           ws_overlappedwindow, 0, 0, screen_width, screen_height,                           null, null, hinstance, null);      showwindow(hwnd, ncmdshow);      // set , initialize direct3d     initd3d(hwnd);      // enter 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 directx , com     cleand3d();      return msg.wparam; }   // main message handler 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); }   // function initializes , prepares direct3d use void initd3d(hwnd hwnd) {     d3d = direct3dcreate9(d3d_sdk_version);      d3dpresent_parameters d3dpp;      zeromemory(&d3dpp, sizeof(d3dpp));     d3dpp.windowed = true;     d3dpp.swapeffect = d3dswapeffect_discard;     d3dpp.hdevicewindow = hwnd;     d3dpp.backbufferformat = d3dfmt_x8r8g8b8;     d3dpp.backbufferwidth = screen_width;     d3dpp.backbufferheight = screen_height;      // create device class using information , info d3dpp stuct     d3d->createdevice(d3dadapter_default,                       d3ddevtype_hal,                       hwnd,                       d3dcreate_software_vertexprocessing,                       &d3dpp,                       &d3ddev);      init_graphics();    // call function initialize triangle      d3ddev->setrenderstate(d3drs_lighting, false);    // turn off 3d lighting }   // function used render single frame void render_frame(void) {     d3ddev->clear(0, null, d3dclear_target, d3dcolor_xrgb(0, 0, 0), 1.0f, 0);      d3ddev->beginscene();      // select vertex format using     d3ddev->setfvf(customfvf);      // set pipeline      d3dxmatrix matrotatey;    // matrix store rotation information      static float index = 0.0f; index+=0.05f;    // ever-increasing float value      // build matrix rotate model based on increasing float value     d3dxmatrixrotationy(&matrotatey, index);      // tell direct3d our matrix     d3ddev->settransform(d3dts_world, &matrotatey);      d3dxmatrix matview;    // view transform matrix      d3dxmatrixlookatlh(&matview,                        &d3dxvector3 (0.0f, 0.0f, 10.0f),    // camera position                        &d3dxvector3 (0.0f, 0.0f, 0.0f),    // look-at position                        &d3dxvector3 (0.0f, 1.0f, 0.0f));    // direction      d3ddev->settransform(d3dts_view, &matview);    // set view transform matview      d3dxmatrix matprojection;     // projection transform matrix      d3dxmatrixperspectivefovlh(&matprojection,                                d3dxtoradian(45),    // horizontal field of view                                (float)screen_width / (float)screen_height, // aspect ratio                                1.0f,    // near view-plane                                100.0f);    // far view-plane      d3ddev->settransform(d3dts_projection, &matprojection);    // set projection      // select vertex buffer display     d3ddev->setstreamsource(0, v_buffer, 0, sizeof(customvertex));      // copy vertex buffer buffer     d3ddev->drawprimitive(d3dpt_trianglelist, 0, 1);      d3ddev->endscene();      d3ddev->present(null, null, null, null); }   // function cleans direct3d , com void cleand3d(void) {     v_buffer->release();    // close , release vertex buffer     d3ddev->release();    // close , release 3d device     d3d->release();    // close , release direct3d }   // function puts 3d models video ram void init_graphics(void) {     // create vertices using customvertex struct     customvertex vertices[] =     {         { 3.0f, -3.0f, 0.0f, d3dcolor_xrgb(0, 0, 255), },         { 0.0f, 3.0f, 0.0f, d3dcolor_xrgb(0, 255, 0), },         { -3.0f, -3.0f, 0.0f, d3dcolor_xrgb(255, 0, 0), },     };      // create vertex buffer interface called v_buffer     d3ddev->createvertexbuffer(3*sizeof(customvertex),                                0,                                customfvf,                                d3dpool_managed,                                &v_buffer,                                null);      void* pvoid;    // void pointer      // lock v_buffer , load vertices     v_buffer->lock(0, 0, (void**)&pvoid, 0);     memcpy(pvoid, vertices, sizeof(vertices));     v_buffer->unlock(); } 

do have install through wine ms directx sdk? change code? i'm directx- , windows-related things noob want cross-compile simple examples of d3d , check if works.

ok! i've succeeded!

unfortunately, needed download microsoft directx sdk (april 2007) (i couldn't install newer ones wine).

then had install mingw using wine , install mingw-utils 0.3 (i had obtain reimp.exe file).

then set path in wine's register c:\windows;c:\windows\system;c:\mingw\bin

then made wine reimp.exe "c:\program files\microsoft directx sdk (april 2007)/lib/x86/d3dx9.lib". command generated d3dx9_33.a file, i've changed d3dx9.a , put in /usr/i586-mingw32msvc/lib/.

i have copied lacking header files directx sdk /usr/i586-mingw32msvc/include.

and then... compiled program, linking libd3d9.a , libd3dx9.a, , compiled, linked, , works!

so news is: 1 can compile windows directx programs under linux using linux version of mingw.

the bad news: 1 need install few mingw utilities , whole ms dx sdk using wine.

edit

and 1 more thing: needed make wchar*-related castings manually - mingw shouts errors if isn't done. goz helpful here.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -