aardio通過(guò)ocx調(diào)用opengl功能

ocx: vb6.0編寫(xiě)ActiveX控件,工程,引用 vbogl.tlb

代碼:


Public Function EnableOpenGL(ghDC As Long) As Long

Dim hrc? ? As Long '

On Error GoTo Err


? ? Dim pfd As PIXELFORMATDESCRIPTOR? ? ? ? ? ? ? ? 'pfd像素格式設(shè)置.

? ? ZeroMemory pfd, Len(pfd)

? ? pfd.nSize = Len(pfd)? ? ? ? ? ? ? ? ? ? ? ? '大小

? ? pfd.nVersion = 1? ? ? ? ? ? ? ? ? ? ? ? ? ? '版本

? ? pfd.dwFlags = PFD_DRAW_TO_WINDOW Or PFD_SUPPORT_OPENGL Or PFD_DOUBLEBUFFER '標(biāo)志

? ? pfd.iPixelType = PFD_TYPE_RGBA? ? ? ? ? ? ? '像素類型

? ? pfd.cColorBits = 24? ? ? ? ? ? ? ? ? ? ? ? '顏色位數(shù)

? ? pfd.cDepthBits = 32? ? ? ? ? ? ? ? ? ? ? ? '位寬

? ? pfd.iLayerType = PFD_MAIN_PLANE? ? ? ? ? ? '圖層類型


? ? Dim PixFormat As Long

? ? PixFormat = ChoosePixelFormat(ghDC, pfd)? ? '選擇設(shè)備中最匹配我們所設(shè)置的像素

? ? SetPixelFormat ghDC, PixFormat, pfd? ? ? ? '設(shè)置成當(dāng)前的像素

? ? hrc = wglCreateContext(ghDC)? ? ? ? ? ? ? ? '建立翻譯描述表

? ? wglMakeCurrent ghDC, hrc

? ? '將建立的翻譯描述表設(shè)置為當(dāng)前

? ? EnableOpenGL = hrc

? ? Exit Function

Err:

MsgBox "Can't? create? OpenGL? context!", vbCritical, "Error"

? ? ? EnableOpenGL = 0

End Function

Public Sub DisableOpenGL(ghRC As Long)

? ? ? ? ? wglMakeCurrent 0, 0

? ? ? ? ? wglDeleteContext ghRC

End Sub


Public Sub Display(hdc As Long)

? ? ? ? ? glClearColor 0#, 0#, 1#, 0#? '清空顏色緩存的RGBA顏色值

? ? ? ? ? glClear clrColorBufferBit? ? '為繪下幀曲面清除緩沖區(qū)

? ? ? ? ? glColor3f 0.8, 0.3, 0.5? ? ? '設(shè)置顯示的字體顏色


? ? ? ? ? glPushMatrix? ? ? ? ? ? ? ? ? '依據(jù)當(dāng)前模式(模式-視圖矩陣)使矩陣入棧


? ? ? ? glBegin glBeginModeConstants.bmPolygon '開(kāi)始繪圖,繪制一個(gè)三角形

? ? ? ? ? ? ? ? ? ? ? glVertex2f -0.5, -0.5? ? '三角形的3個(gè)頂點(diǎn)

? ? ? ? ? ? ? ? ? ? ? glVertex2f -0.5, 0.5

? ? ? ? ? ? ? ? ? ? ? glVertex2f 0.5, -0.5

? ? ? ? ? glEnd

? ? ? ? ? glPopMatrix? ? ? ? ? ? ? ? ? ? ? ? ? '依據(jù)當(dāng)前模式(模式-視圖矩陣)使矩陣出棧

? ? ? ? ? SwapBuffers hdc? ? ? ? ? ? '切換緩存

End Sub

保存編譯成 ocx文件,我取的名字是 gl3d.ocx。

然后點(diǎn)運(yùn)行,查看看源碼 可以得到 clsid。

打開(kāi)aardio 新建工程

添加一個(gè) picturebox

添加代碼

import com.lite;

var hrc;

var glocx=com.lite("\res\gl3d.ocx")

var gl3d=glocx.createEmbed(mainForm.picturebox,"{10692B74-4939-44FB-82B6-27ED3A889414}");

var globj=gl3d._object;

segl=function(hdc){//返回 hRC

return(globj.EnableOpenGL(hdc));

}

display=function(hdc){

globj.Display(hdc);

}

disgl=function(hrc){

globj.DisableOpenGL(hrc);

}

hddc=::User32.GetDC(mainForm.picturebox.hwnd);

hrc=segl(hddc);

mainForm.show();

display(hddc);//目前先放這里吧省事

return win.loopMessage();

運(yùn)行看看效果吧。。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容