首頁 > 後端開發 > C++ > 主體

如何在 C Builder 窗體中渲染 OpenGL 影格?

Mary-Kate Olsen
發布: 2024-10-25 04:08:02
原創
579 人瀏覽過

How to Render an OpenGL Frame Within a C   Builder Form?

在 C Builder 中渲染 OpenGL 訊框

使用 OpenGL 自訂 C Builder 表單時,直接從線上資源複製 OpenGL 啟動程式碼時經常會遇到問題。對於使用C Builder 的用戶,這裡有一個在表單中渲染OpenGL 幀的詳細指南:

初始化

  1. 在表單類標頭中,定義user-定義成員如下:
<code class="cpp">int xs, ys;
HDC hdc;            // device context
HGLRC hrc;            // rendering context
int ogl_inicialized;
int ogl_init();
void ogl_exit();
void ogl_draw();
void ogl_resize();</code>
登入後複製
  1. 建立一個間隔為20-40 毫秒的計時器。
  2. 在表單的事件中(例如,調整大小、重繪、計時器) ),加入類似以下的程式碼:
<code class="cpp">void __fastcall TForm1::FormResize(TObject* Sender)
{
    ogl_resize();
}

void __fastcall TForm1::FormPaint(TObject* Sender)
{
    ogl_draw();
}

void __fastcall TForm1::Timer1Timer(TObject* Sender)
{
    ogl_draw();
}</code>
登入後複製

OpenGL 初始化

  1. 在ogl_init() 函數中,執行以下步驟:
<code class="cpp">hdc = GetDC(Form1->Handle);             // get device context

PIXELFORMATDESCRIPTOR pfd;
ZeroMemory(&pfd, sizeof(pfd));      // set the pixel format for the DC
...

if(wglMakeCurrent(hdc, hrc) == false)
{
    ShowMessage("Could not make current OpenGL Rendering context !!!");
    wglDeleteContext(hrc);          // destroy rendering context
    ogl_inicialized=0;
    return 0;
}
...</code>
登入後複製

OpenGL 渲染

  1. OpenGL 渲染
<code class="cpp">glBegin(GL_QUADS);
...
glEnd();</code>
登入後複製
在ogl_draw() 函數中,建立並繪製一個基本物件(例如,四邊形):

    附加說明
  • 附加說明
  • 附加說明
附加說明附加指示住包含頭檔。 初始化 OpenGL 時可以使用 TForm::Handle 作為視窗句柄。 此範例示範了窗體中心的一個簡單的綠色四邊形。 有關更進階的 OpenGL 功能(例如 GLSL、VAO/VBO),請參閱其他線上資源。

以上是如何在 C Builder 窗體中渲染 OpenGL 影格?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!