首页 > 其他分享 >VC6命令行编译DirectX9

VC6命令行编译DirectX9

时间:2022-11-01 18:56:06浏览次数:75  
标签:d3ddev d3dpp buffer hWnd void 编译 VC6 DirectX9 NULL

编程环境: VC6.0 绿色版

                  DirectX 9.0 SDK

1. 采用NMake方式编译DX9的代码, 不使用IDE。

界面采用Win32 API方式构建。

2. 准备源代码, 本例采用一个绘制三角形的代码文件(main.cpp)

// include the basic windows header files and the Direct3D header file
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>

// define the screen resolution
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600

// 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
LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;    // the pointer to the vertex buffer

// 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
void init_graphics(void);    // 3D declarations

struct CUSTOMVERTEX {FLOAT X, Y, Z, RHW; DWORD COLOR;};
#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

// 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.lpszClassName = "WindowClass";

    RegisterClassEx(&wc);

    hWnd = CreateWindowEx(NULL,
                          "WindowClass",
                          "Our Direct3D Program",
                          WS_OVERLAPPEDWINDOW,
                          0, 0,
                          SCREEN_WIDTH, SCREEN_HEIGHT,
                          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);

    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 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);

    init_graphics();    // call the function to initialize the triangle
}


// this is the function used to render a single frame
void render_frame(void)
{
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    d3ddev->BeginScene();

        // select which vertex format we are using
        d3ddev->SetFVF(CUSTOMFVF);

        // select the vertex buffer to display
        d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));

        // copy the vertex buffer to the back buffer
        d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

    d3ddev->EndScene();

    d3ddev->Present(NULL, NULL, NULL, NULL);
}


// this is the function that cleans up Direct3D and COM
void cleanD3D(void)
{
    v_buffer->Release();    // close and release the vertex buffer
    d3ddev->Release();    // close and release the 3D device
    d3d->Release();    // close and release Direct3D
}


// this is the function that puts the 3D models into video RAM
void init_graphics(void)
{
    // create the vertices using the CUSTOMVERTEX struct
    CUSTOMVERTEX vertices[] =
    {
        { 400.0f, 62.5f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
        { 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },
        { 150.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
    };

    // create a vertex buffer interface called v_buffer
    d3ddev->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),
                               0,
                               CUSTOMFVF,
                               D3DPOOL_MANAGED,
                               &v_buffer,
                               NULL);

    VOID* pVoid;    // a void pointer

    // lock v_buffer and load the vertices into it
    v_buffer->Lock(0, 0, (void**)&pVoid, 0);
    memcpy(pVoid, vertices, sizeof(vertices));
    v_buffer->Unlock();
}

3. 编写NMake的Makefile文件

main.exe:main.obj
	link /libpath:"D:/Dx9SDK/Lib/x86" d3d9.lib user32.lib main.obj

main.obj:main.cpp
	cl /I "D:/Dx9SDK/Include" /c main.cpp

这里D:/Dx9SDK为DirectX 9 SDK的安装目录.

 

 启动VC6.0 命令行窗口, 可以使用对【VC6安装目录】\VC98\Bin目录下的VCVARS32.BAT进行改造, 添加start cmd即可.

>> NMake

4. 运行生成的exe,得到运行结果。

 

                             ---------------- 勿在浮沙筑高台

 

标签:d3ddev,d3dpp,buffer,hWnd,void,编译,VC6,DirectX9,NULL
From: https://www.cnblogs.com/068XS228/p/16848786.html

相关文章

  • gcc编译步骤
    可以一步一步得到对应运行结果-o其实跟重命名差不多......
  • Jenkins Pipeline 流水线 - 拉代码(SVN) + Maven 编译打包
    JenkinsPipeline流水线步骤拉取SVN代码->Maven构建->Docker编译->发布至阿里云仓库->K8S更新Jenkins插件安装Localization:Chinese(Simplified)Subve......
  • 编译链接
    ..从这里抄的 https://blog.csdn.net/hxlawf/article/details/94623786,做做记录GCC编译选项CFLAGS参数选项     说明-c       用于把源码文......
  • 学习笔记-pyc反编译
    pyc反编译相关文章py可执行文件反编译教程--exe转换pyPython代码保护|pyc混淆从入门到工具实现相关工具python反编译rocky/python-uncompyle6#例如有一......
  • MDK (Arm Compiler 6)编译器V6版本
    使用过KeilMDK(ArmCompiler6)编译器V6版本的读者应该发现了一个问题,V6版本速度比V5版本编译速度快很多。(说明:是V6版本编译器,不是V6版本MDK)那你发现了ArmCompile......
  • 编译gRPC相关示例程序,undefined reference to `deflateInit2_'等相关错误解决
    编译gRPC相关示例程序时,出现如下链接错误:/home/suph/.local/lib/libgrpc.a(message_compress.cc.o):Infunction`zlib_compress(grpc_slice_buffer*,grpc_slice_buffer*......
  • [nrf51] boot DFU 编译lib文件
    ​​GCC下载​​下载gcc解压到任意目录然后修改SDK12.3.xx\nRF5_SDK_12.3.0_d7731ad\components\toolchain\gcc根据实际目录修改成如下内容:下载make​​make链接​​提取......
  • vs编译错误
     vs编译错误Vs报错 unexpectedcharacter 报错  原因: 一般是程序集引用导致问题。参考地址:https://stackoverflow.com/questions/31577120/why-do-i-get-a......
  • Numba编译器的介绍与应用
    1.介绍Numba是python的即时(Just-in-time)编译器,即当你调用python函数时,你的全部或部分代码就会被转换为“即时”执行的机器码,它将以你的本地机器码速度运行!它由Anacon......
  • C语言常见编译错误与执行错误
    hello:line1:syntaxerror:unexpectedword(expecting“)”)编写fasync_jni应用程序放在Tiny210开发板上跑会出现如下错误:然后编写一个最简单的helloworld程序放在T......