我根據網上的資料寫了如下代碼,但是沒有反應,左思右想二不得果,望指教!
//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#include <GL/glut.h>
#include <stdlib.h>
#pragma hdrstop
#include "Unit21.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "OpenGLSrc"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
//全域變數
#define MAX_CHAR 128
void selectFont(int size, int charset, const char* face)
{
HFONT hFont = CreateFontA(size, 0, 0, 0, FW_MEDIUM, 0, 0, 0,
charset, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, face);
HFONT hOldFont = (HFONT)SelectObject(wglGetCurrentDC(), hFont);
DeleteObject(hOldFont);
}
void Initialization()
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); //設定背景色為白色
}
//重繪回呼函式
void OnReshape()
{
glMatrixMode(GL_PROJECTION); //投影模式
glLoadIdentity(); //載入單位矩陣以初始化當前矩陣
//gluOrtho2D(0, w, 0, h); //將當前繪圖區域設定為二維正交投影
glMatrixMode(GL_MODELVIEW); //模型視圖模式
glLoadIdentity(); //初始化當前矩陣
}
void drawString(const char* str) //螢屏顯示字體
{
static int isFirstCall = 1;
static GLuint lists;
if (isFirstCall)
{
isFirstCall = 0;
// 申請MAX_CHAR個連續的顯示串列編號
lists = glGenLists(MAX_CHAR);
// 把每個字符的繪制命令都裝到對應的顯示串列中
wglUseFontBitmaps(wglGetCurrentDC(), 0, MAX_CHAR, lists);
}
// 呼叫每個字符對應的顯示串列,繪制每個字符
for (; *str != '\0'; ++str)
{
glCallList(lists + *str);
}
}
//顯示回呼函式
void OnDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
//Drawing();
selectFont(48, ANSI_CHARSET, "Comic Sans MS"); //字體可以在系統檔案里尋找
glColor3f(1.0f, 0.0f, 0.0f); //設定字體顏色
glRasterPos2i(0.0f,0.0f); //起始位置
drawString("Hello,OpenGL."); //輸出的字串
glutSwapBuffers(); //交換前后快取區
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OpenGL1Click(TObject *Sender)
{
Initialization();
OnDisplay();
//OnReshape();
}
//---------------------------------------------------------------------------
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/120962.html
標籤:VCL組件使用和開發
