2011年3月3日 星期四

工具BoneEdit

路人:這個工具是用BCB寫的吧,看附圖左上角的LOGO就知了.
c:是啊
路人:看起來沒什麼.
c:雖然這個BoneEdit只是個小軟體,但內容也不少,你看看用到的元件

路人:哇,那程式碼貼出來不就一狗票.
c:這樣好了,先別管元件,我主要介紹類別的功能,有需要的,我再說明裡面程式的寫法.

OpenGL的類別,主要是初始OpenGL
class CGL
{
public:
CGL();
virtual ~CGL();
void Resize(GLsizei width, GLsizei height, GLsizei depth);//視窗大小更動時呼叫
        bool Initial(HWND hWnd, unsigned int Width, unsigned int Height, int bits );//初始化
        void NowDC(void);//建立dc
        HDC m_hDC;
private:
int m_ScrWidth;//寬
int m_ScrHeight;//高
        int m_Depth;//深度
HGLRC m_hRC;//渲染環境
HWND m_hWnd;//渲染環境對應的視窗
};

其實看了上一篇的附圖,就可以知道,這個工具是BCB寫的.
在BCB內的用法為:
CGL *GL;  <--在Unit1.h內的TForm1宣告

Unit1.cpp
void __fastcall TForm1::FormCreate(TObject *Sender)//初始化
{
    GL = new CGL();
    if( GL->Initial( Panel1->Handle, Panel1->ClientWidth, Panel1->ClientHeight, 32 ) )
    {
Timer1->Enabled = true;
    }
}
//更新就如下使用(用到了Timer元件,至於Timer的Interval,就設為1)
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
    GL->NowDC();  //視窗移動時,會破壞畫面,用DC重建RC
    GL->Resize( Panel1->ClientWidth, Panel1->ClientHeight, 50000 );
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);
    glClearColor (0, 0, 0, 0.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    //*******************
    //這裡處理繪製
    //*******************

    SwapBuffers(GL->m_hDC);//繪製好的圖案顯示出來
}

路人:感覺不是很高明耶,而且效率應該很差吧...
c:真是不好意思,就寫寫程式...好玩嘛,
  順便補上使用的到.h

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <math.h>    
#include <iostream.h>
#include <commctrl.h>
#include <windowsx.h>
#include <mmsystem.h>

#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The GLaux Library

typedef struct
{
    float x,y,z;
} gVector;

typedef struct
{
    float u,v;
} gUV;

typedef struct
{
float m[16];
} gMatrix;

#define SafeDelete(pObject) if(pObject!=NULL) {delete pObject; pObject=NULL;}

沒有留言:

張貼留言