|
아래 소스가 뼈대라고해서 해보았지만 그림이 그려지지 않습니다.
패널에 그려보려했는데
인터넷 여러가지 소스들 많이 해보았지만 그림이 그려지지 않네요
3D Box를 그려야 하는데.. 반응조차 없으니..도와주세요~
class TFmDraw3D : public TForm
{
__published: // IDE-managed Components
TPanel *Panel1;
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
private: // User declarations
HGLRC hRC;
HDC hDC;
PIXELFORMATDESCRIPTOR pfd;
public: // User declarations
void __fastcall GLInit(void);
void __fastcall FormResize(TObject *Sender);
void __fastcall PaintBox1Paint(TObject *Sender);
void __fastcall DrawScene(void);
__fastcall TFmDraw3D(TComponent* Owner);
};
#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);
}
//---------------------------------------------------------------------------
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());
}
|