|
누군가 님이 쓰신 글 :
: 가만보니 뭐가 빠졌군요
: Panel1->WindowProc = Panel1_NewProc;
:
: void __fastcall TFmDraw3D::Panel1_NewProc(Messages::TMessage &Message)
: {
: //여기서 WM_PAINT할때 DrawScene을 호출함.
: }
: 이런 형식으로 해야합니다.
감사합니다...
하지만 링크 에러가 나네요
void __fastcall TFmDraw3D::DrawScene(void)부분에서
auxSolidSphere(100.0f);에서 링크에러가 납니다..
주석 처리하고 돌리면 돌아는 가는데 ... 여전히 패널에 반응은 없습니다.
ㅡㅜ
//---------------------------------------------------------------------------
#include <vcl.h>
#include <vcl/vcl.h>
#pragma hdrstop
#include "Draw3DForm.h"
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
#include <float.h>
#include <math.h>
#define GL_PI 3.1415f
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFmDraw3D *FmDraw3D;
__fastcall TFmDraw3D::TFmDraw3D(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TFmDraw3D::FormCreate(TObject *Sender)
{
GLInit();
}
//---------------------------------------------------------------------------
void __fastcall TFmDraw3D::GLInit(void)
{
int pf;
hDC = GetDC(Panel1->Handle);
memset(&pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cDepthBits = 16;
pfd.cColorBits = 32; //true color
pf = ChoosePixelFormat(hDC, &pfd);
if (pf == 0) { MessageBox(NULL, "ChoosePixelFormat() failed: Cannot find a suitable pixel format.", "Error", MB_OK); return; }
if (SetPixelFormat(hDC, pf, &pfd) == FALSE) { MessageBox(NULL, "SetPixelFormat() failed: Cannot set format specified.", "Error", MB_OK); return; }
DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
ReleaseDC(Handle, hDC);
Panel1->WindowProc = Panel1_NewProc;
}
//---------------------------------------------------------------------------
void __fastcall TFmDraw3D::FormResize(TObject *Sender)
{
static int nWidth, nHeight;
static int nAspect;
nWidth = Panel1->Width;
nHeight = Panel1->Height;
glViewport(0.0, 0.0, nWidth, nHeight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(nHeight == 0) nHeight = 1;
nAspect = nWidth / nHeight;
gluPerspective(45.0f, nAspect, 1.0f, 200.0f);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
//---------------------------------------------------------------------------
void __fastcall TFmDraw3D::PaintBox1Paint(TObject *Sender)
{
DrawScene();
}
//---------------------------------------------------------------------------
void __fastcall TFmDraw3D::FormDestroy(TObject *Sender)
{
wglMakeCurrent(hDC, NULL);
wglDeleteContext(hRC);
}
//---------------------------------------------------------------------------
void __fastcall TFmDraw3D::DrawScene(void)
{
//우선 지우고
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
//그림을 그린다.
glColor3f(1.0f,0.0f,0.0f);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -100.0f);
auxSolidSphere(100.0f);
glBegin(GL_TRIANGLES);
glColor3ub(255,0,0);
glVertex3f( 0.0f, 1.0f, -10.0f);
glColor3ub(0,255,0);
glVertex3f(-1.0f,-1.0f, -10.0f);
glColor3ub(0,0,255);
glVertex3f( 1.0f,-1.0f, -10.0f);
glEnd();
glFlush();
SwapBuffers(wglGetCurrentDC());
}
//---------------------------------------------------------------------------
void __fastcall TFmDraw3D::Panel1_NewProc(Messages::TMessage &Message)
{
if(Message.Msg == WM_PAINT) DrawScene();
}
|