zoukankan      html  css  js  c++  java
  • Direct3D 9学习笔记(9)文本绘制

    一.使用ID3DXFont接口

    image

    创建一个ID3DXFont对象

    D3DXFONT_DESC df;
    ZeroMemory(&df, sizeof(D3DXFONT_DESC));
    
    df.Height         = 25;    // in logical units
    df.Width          = 12;    // in logical units   
    df.Weight         = 500;   // boldness, range 0(light) - 1000(bold)
    df.Italic         = false;     
    df.CharSet        = DEFAULT_CHARSET;
    df.OutputPrecision   = 0;                     
    df.Quality        = 0;           
    df.PitchAndFamily = 0;           
    strcpy(df.FaceName, "Times New Roman"); // font style
    
    //
    // Create an ID3DXFont based on 'lf'.
    //
    
    if(FAILED(D3DXCreateFontIndirect(Device, &df, &Font)))
    {
    }
    

    二.使用ID3DXFont绘制文本

    image

            RECT rect = {0, 0, Width, Height};
            Font->DrawText(NULL,
                FPSString, 
                -1, // size of string or -1 indicates null terminating string
                &rect,            // rectangle text is to be formatted to in windows coords
                DT_TOP | DT_LEFT, // draw in the top left corner of the viewport
                0xffff0000);      // black text
    

    三.D3DXCreateText

    Creates a mesh containing the specified text, using the font associated with the device context.

    //
    // Describe the font we want.
    //
    
    LOGFONT lf;
    ZeroMemory(&lf, sizeof(LOGFONT));
    
    lf.lfHeight         = 25;    // in logical units
    lf.lfWidth          = 12;    // in logical units
    lf.lfEscapement     = 0;        
    lf.lfOrientation    = 0;     
    lf.lfWeight         = 500;   // boldness, range 0(light) - 1000(bold)
    lf.lfItalic         = false;   
    lf.lfUnderline      = false;    
    lf.lfStrikeOut      = false;    
    lf.lfCharSet        = DEFAULT_CHARSET;
    lf.lfOutPrecision   = 0;              
    lf.lfClipPrecision  = 0;          
    lf.lfQuality        = 0;           
    lf.lfPitchAndFamily = 0;    
    strcpy(lf.lfFaceName, "Times New Roman"); // font style
    
    //
    // Create the font and select it with the device context.
    //
    hFont = CreateFontIndirect(&lf);
    hFontOld = (HFONT)SelectObject(hdc, hFont); 
    
    //
    // Create the text mesh based on the selected font in the HDC.
    //
    D3DXCreateText(Device, hdc, "Direct3D", 
        0.001f, 0.4f, &Text, 0, 0);
    

    其会返回一个ID3DXMesh,然后调用DrawSubset方法

    Device->SetMaterial(&d3d::BLUE_MTRL);
    Text->DrawSubset(0);
    

    image

  • 相关阅读:
    Java内部类详解
    Mac连接linux服务器
    mac 添加环境变量(jmeter添加至环境变量中)
    Charles使用断点修改返回或请求参数
    解决git clone速度慢的问题
    group by分组后获得每组中时间最大的那条记录
    使用Charles进行弱网测试
    http常见的状态码
    Mac使用Charles抓取ios手机APP中的https请求
    airtest使用poco方法的断言知识
  • 原文地址:https://www.cnblogs.com/Clingingboy/p/2631708.html
Copyright © 2011-2022 走看看