全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:5481
推到 Plurk!
推到 Facebook!

想用OPENGL建構出球體但是沒圖案出現

缺席
5515531
一般會員


發表:19
回覆:44
積分:12
註冊:2008-04-16

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-09-01 08:45:37 IP:140.134.xxx.xxx 訂閱
我想嘗試著在BCB裡面用OPENGL程式畫出球體~但是沒有圖案出現
我有寫出一些大概不過就是沒有圖案跑出來
可以請各位專家幫我看一下哪邊有問題嗎??
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Application->OnIdle = IdleLoop;
size = 50.0f;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdleLoop(TObject*, bool& done)
{
done = false;
SwapBuffers(hdc);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::GLPanel1Setup(TObject *Sender)
{
//============================
hdc = GetDC(Handle);
SetPixelFormatDescriptor();
hrc = wglCreateContext(hdc);
glEnable(GL_CULL_FACE);
SetupLighting();
CreateInpriseCorporateLogo();
//============================
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetPixelFormatDescriptor()
{
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,
};
PixelFormat = ChoosePixelFormat(hdc, &pfd);
SetPixelFormat(hdc, PixelFormat, &pfd);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::GLPanel1Resize(TObject *Sender)
{
int height=GLPanel1->Height, width=GLPanel1->Width;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,500.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::GLPanel1Render(TObject *Sender)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, texture3);
glColor3f(0.0f, 0.0f, 1.0f);
glTranslatef(15.0, 5.0f, -7.5f);
glRotatef(90, 1.0, 0.0, 0.0);
glRotatef(90, 0.0, 0.0, 1.0);
glCallList(startoflist 5);
glPopMatrix();
glFlush();
GLPanel1->SwapBuffers();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CreateInpriseCorporateLogo()
{
startoflist = glGenLists(4);
DrawBlueSphere();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DrawBlueSphere()
{
BlueSphere = gluNewQuadric();
glBindTexture(GL_TEXTURE_2D, texture3);
gluQuadricTexture(BlueSphere, GL_TRUE);
gluQuadricDrawStyle(BlueSphere, GLU_FILL);
gluQuadricNormals(BlueSphere, GLU_SMOOTH);
glNewList(startoflist 5, GL_COMPILE);
gluSphere(BlueSphere, 30, 25, 25);
glEndList();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetupLighting()
{
GLfloat MaterialAmbient[] = {0.5, 0.5, 0.5, 1.0};
GLfloat MaterialDiffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat MaterialSpecular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat MaterialShininess[] = {50.0};
GLfloat AmbientLightPosition[] = {0.5, 1.0, 1.0, 0.0};
GLfloat LightAmbient[] = {0.5, 0.5, 0.5, 1.0};
glMaterialfv(GL_FRONT, GL_AMBIENT, MaterialAmbient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, MaterialDiffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, MaterialSpecular);
glMaterialfv(GL_FRONT, GL_SHININESS, MaterialShininess);
glLightfv(GL_LIGHT0, GL_POSITION, AmbientLightPosition);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, LightAmbient);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glShadeModel(GL_SMOOTH);
}
謝謝各位大大的指導!!
編輯記錄
5515531 重新編輯於 2008-09-01 14:36:47, 註解 無‧
系統時間:2024-11-21 16:48:55
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!