Бывалый

Профиль
Группа: Участник
Сообщений: 213
Регистрация: 9.1.2008
Репутация: нет Всего: -1
|
Вот к примеру код: Код | //---------------------------------------------------------------------------
#include <vcl.h> #pragma hdrstop
#include <GL/gl.h> #include <GL/glu.h>
#include "Math.h" #include "Saver.h" #include "Panel.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "TeeDraw3D" #pragma link "TeeProcs" #pragma resource "*.dfm" extern TForm1 *Form1; TForm2 *Form2; //--------------------------------------------------------------------------- BOOL bSetupPixelFormat(HDC hdc) { PIXELFORMATDESCRIPTOR pfd, *ppfd; int pixelformat; ppfd = &pfd; ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR); ppfd->nVersion = 1; ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; ppfd->dwLayerMask = PFD_MAIN_PLANE; ppfd->iPixelType = PFD_TYPE_RGBA; ppfd->cColorBits = 16; ppfd->cDepthBits = 16; ppfd->cAccumBits = 0; ppfd->cStencilBits = 0; if ((pixelformat = ChoosePixelFormat(hdc, ppfd)) == 0) { MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK); return FALSE; } if (SetPixelFormat(hdc, pixelformat, ppfd) == FALSE) { MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK); return FALSE; } return TRUE; } //--------------------------------------------------------------------------- __fastcall TForm2::TForm2(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- HGLRC _wglCreateContext(HDC hdc); BOOL _wglMakeCurrent(HDC hdc, HGLRC hglrc); //--------------------------------------------------------------------------- void __fastcall TForm2::FormCreate(TObject *Sender) { ghDC = GetDC(Handle); if (!bSetupPixelFormat(ghDC)) Close(); ghRC = wglCreateContext(ghDC); wglMakeCurrent(ghDC, ghRC); glClearColor(0.0, 0.0, 0.0, 0.0); FormResize(Sender); glEnable(GL_COLOR_MATERIAL); glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); float p[4]={3,3,3,1}, d[3]={-1,-1,-3}; glLightfv(GL_LIGHT0,GL_POSITION,p); glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,d); } //--------------------------------------------------------------------------- void __fastcall TForm2::FormResize(TObject *Sender) { glViewport( 0, 0, Width, Height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho(-5,5, -5,5, 2,12); gluLookAt(0,0,5, 0,0,0, 0,1,0); glMatrixMode( GL_MODELVIEW ); } //--------------------------------------------------------------------------- void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action) { if(ghRC) { wglMakeCurrent(ghDC,0); wglDeleteContext(ghRC); } if(ghDC) ReleaseDC(Handle, ghDC); } //--------------------------------------------------------------------------- void TForm2::Draw() { glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
GLUquadricObj *quadObj; quadObj=gluNewQuadric();
gluQuadricDrawStyle(quadObj, GLU_FILL); glColor3f(1,0,0); gluSphere(quadObj, 2,10,10); glRotatef(3, 0,1,0); gluDeleteQuadric(quadObj);
SwapBuffers(ghDC); } //--------------------------------------------------------------------------- void __fastcall TForm2::Timer1Timer(TObject *Sender) { Draw(); } //---------------------------------------------------------------------------
|
Где в форме рисуется сфера. Вопрос - как мне всю графику вынести в отдельный элемент в билдере, скажем в Panel, а не в овсю форму. Подскажите пожалуйста...
|