久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 C++ builder 中渲染 openGL 框架?

How to render an openGL frame in C++ builder?(如何在 C++ builder 中渲染 openGL 框架?)
本文介紹了如何在 C++ builder 中渲染 openGL 框架?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想在 C++ 構建器中的表單內初始化一個 openGL 框架.我嘗試復制此處提供的給定 openGL 啟動代碼的內容:http://edn.embarcadero.com/article/10528
我嘗試用 TFrame1 替換 TForm1,然后將其放入表單設計中,但沒有奏效.如何正確地做到這一點,有這方面的經驗嗎?

I want to initialize an openGL frame inside a form in C++ builder. I tried copying the contents of this given openGL startup code provided here: http://edn.embarcadero.com/article/10528
I tried replacing TForm1 with TFrame1 and then put it in the form design, but it didn't work. How to do this properly, any experience with this?

推薦答案

簡單,只需使用 TForm::Handle 作為窗口句柄...

easy, just use TForm::Handle as window handle ...

這是我在 BCB5 中移植到 BDS2006 中的一些古老示例:

Here some ancient example of mine in BCB5 ported to BDS2006:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include <gl/gl.h>
#include <gl/glu.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
int TForm1::ogl_init()
    {
    if (ogl_inicialized) return 1;
    hdc = GetDC(Form1->Handle);             // get device context
    PIXELFORMATDESCRIPTOR pfd;
    ZeroMemory( &pfd, sizeof( pfd ) );      // set the pixel format for the DC
    pfd.nSize = sizeof( pfd );
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 24;
    pfd.iLayerType = PFD_MAIN_PLANE;
    SetPixelFormat(hdc,ChoosePixelFormat(hdc, &pfd),&pfd);
    hrc = wglCreateContext(hdc);            // create current rendering context
    if(hrc == NULL)
            {
            ShowMessage("Could not initialize OpenGL Rendering context !!!");
            ogl_inicialized=0;
            return 0;
            }
    if(wglMakeCurrent(hdc, hrc) == false)
            {
            ShowMessage("Could not make current OpenGL Rendering context !!!");
            wglDeleteContext(hrc);          // destroy rendering context
            ogl_inicialized=0;
            return 0;
            }
    ogl_resize();
    glEnable(GL_DEPTH_TEST);                // Zbuf
    glDisable(GL_CULL_FACE);                // vynechavaj odvratene steny
    glDisable(GL_TEXTURE_2D);               // pouzivaj textury, farbu pouzivaj z textury
    glDisable(GL_BLEND);                    // priehladnost
    glShadeModel(GL_SMOOTH);                // gourard shading
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);   // background color
    ogl_inicialized=1;
    return 1;
    }
//---------------------------------------------------------------------------
void TForm1::ogl_exit()
    {
    if (!ogl_inicialized) return;
    wglMakeCurrent(NULL, NULL);     // release current rendering context
    wglDeleteContext(hrc);          // destroy rendering context
    ogl_inicialized=0;
    }
//---------------------------------------------------------------------------
void TForm1::ogl_draw()
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    float x=0.5,y=0.5,z=20.0;
    glBegin(GL_QUADS);

    glColor3f(0.0f, 1.0f, 0.0f);
    glVertex3f(-x,-y,-z);
    glVertex3f(-x,+y,-z);
    glVertex3f(+x,+y,-z);
    glVertex3f(+x,-y,-z);
    glColor3f(0.0f, 0.0f, 1.0f);
    glVertex3f(-x,-y,+z);
    glVertex3f(-x,+y,+z);
    glVertex3f(+x,+y,+z);
    glVertex3f(+x,-y,+z);

    glEnd();



    glFlush();
    SwapBuffers(hdc);
    }
//---------------------------------------------------------------------------
void TForm1::ogl_resize()
    {
    xs=ClientWidth;
    ys=ClientHeight;
    if (xs<=0) xs = 1;                  // Prevent a divide by zero
    if (ys<=0) ys = 1;
    if (!ogl_inicialized) return;
    glViewport(0,0,xs,ys);              // Set Viewport to window dimensions
    glMatrixMode(GL_PROJECTION);        // operacie s projekcnou maticou
    glLoadIdentity();                   // jednotkova matica projekcie
    gluPerspective(30,float(xs)/float(ys),0.1,100.0); // matica=perspektiva,120 stupnov premieta z viewsize do 0.1
    glMatrixMode(GL_TEXTURE);           // operacie s texturovou maticou
    glLoadIdentity();                   // jednotkova matica textury
    glMatrixMode(GL_MODELVIEW);         // operacie s modelovou maticou
    glLoadIdentity();                   // jednotkova matica modelu (objektu)
    ogl_draw();
    }
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
    {
    ogl_inicialized=0;
    hdc=NULL;
    hrc=NULL;
    ogl_init();
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
    {
    ogl_exit();
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::FormResize(TObject *Sender)
    {
    ogl_resize();
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
    {
    ogl_draw();
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
    {
    ogl_draw();
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseWheelDown(TObject *Sender, TShiftState Shift,
      TPoint &MousePos, bool &Handled)
    {
    glMatrixMode(GL_PROJECTION);
    glTranslatef(0,0,+2.0);
    ogl_draw();
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseWheelUp(TObject *Sender, TShiftState Shift,
      TPoint &MousePos, bool &Handled)
    {
    glMatrixMode(GL_PROJECTION);
    glTranslatef(0,0,-2.0);
    ogl_draw();
    }
//---------------------------------------------------------------------------

  1. 創建空的 1-Form 項目

  1. create empty 1-Form project

將此添加到表單類標題作為其用戶定義的成員

add this to form class header as its user defined members

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

  • 添加計時器 ~ 20-40 毫秒

  • add timer ~ 20-40 ms

    注意事項

    • 不需要所有 OpenGL 的東西都是表單類的成員
    • 定時器可以有任何間隔
    • OpenGL 也可以只是窗口的一部分,而不僅僅是整個事物
    • 可以與 VCL 組件結合使用(將面板用于按鈕等,并將 OpenGL 調整為外部區域)
    • 如果你不能讓它工作,請評論我,但我看不出有什么困難......
    • 不要忘記包含 gl.h !!!
    • 如果一切正常,您應該會在表單中心看到綠色四邊形
    • 鼠標滾輪向前/向后移動相機(縮放")
    • it is not required that all OpenGL stuff is member of form class
    • timer can have any interval
    • OpenGL can be also just a part of a window not only the whole thing
    • can combine with VCL components (use panels for buttons etc and resize OpenGL to area outside)
    • If you cannot get it to work comment me, but i do not see anything difficult to do ...
    • Do not forget to include gl.h !!!
    • if all work then you should see green quad in the center of form
    • mouse wheel moves camera forward/backward ('zoom')

    當您準備好使用 OpenGL 1.0 時,請查看:

    When you're ready to go beond OpenGL 1.0 take a look at:

    • 完整的 GL+GLSL+VAO/VBO C++ 示例

    玩得開心...

    這篇關于如何在 C++ builder 中渲染 openGL 框架?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

    【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!
  • 相關文檔推薦

    How do I set the icon for my application in visual studio 2008?(如何在 Visual Studio 2008 中為我的應用程序設置圖標?)
    Convert CString to const char*(將 CString 轉換為 const char*)
    Remove secure warnings (_CRT_SECURE_NO_WARNINGS) from projects by default in Visual Studio(默認情況下,在 Visual Studio 中從項目中刪除安全警告 (_CRT_SECURE_NO_WARNINGS))
    How do I start a new CUDA project in Visual Studio 2008?(如何在 Visual Studio 2008 中啟動新的 CUDA 項目?)
    Exporting classes containing `std::` objects (vector, map etc.) from a DLL(從 DLL 導出包含 `std::` 對象(向量、映射等)的類)
    What are some reasons a Release build would run differently than a Debug build(發布版本與調試版本的運行方式不同的一些原因是什么)
    主站蜘蛛池模板: 国产高清一区二区三区 | 国产精品毛片一区二区在线看 | 国产精品99久久久久久久久久久久 | 国产欧美一区二区三区在线看 | 国产精品欧美一区二区三区不卡 | 91玖玖| 在线观看涩涩视频 | 日韩欧美视频 | 成人在线视频观看 | 国产精品美女一区二区 | 精品久久久久久亚洲综合网站 | 欧美一级欧美一级在线播放 | 性一爱一乱一交一视频 | 欧美一级黄视频 | 国产成人精品久久二区二区91 | 久久久久久久一区 | 91视频精选 | 成人a视频| 91视频三区| 91精品国产91久久久久久最新 | .国产精品成人自产拍在线观看6 | 国产视频中文字幕 | av小说在线| 精品亚洲永久免费精品 | 美女久久视频 | 97视频在线观看免费 | 亚洲成人中文字幕 | 欧美激情欧美激情在线五月 | 91免费入口| 国产不卡视频 | 久99久视频 | 国产精品99999999| 久久成人一区二区三区 | 国产日韩欧美一区 | 久久av网| 久久久国产精品 | 精品国产乱码久久久久久图片 | 天天草天天干天天 | 国产一区二区激情视频 | 国产一区免费 | 黄网站免费观看 |