BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

OpenGL on TPaintBox (long)

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
Przemo B.
Guest





PostPosted: Tue Oct 28, 2003 4:49 pm    Post subject: OpenGL on TPaintBox (long) Reply with quote



Dear Programmers,

I would like creating a simple OpenGL program based on TPaintBox control
(drawing only solid filled rectangle). There are a lot of examples of OpenGL
but most of them using TForm->Canvas as a render context. So, I wrote
bellowed code and (as I supposed) does not work:

From header file:
class TForm1 : public TForm
{
__published: // IDE-managed Components
TPaintBox *PaintBox1;
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormPaint(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
private: // User declarations
HDC hCanvas;
HGLRC hRC;
int PixelFormat;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void __fastcall SetPixelFormatDescriptor();
void __fastcall SetupColor();
};

From source file:
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}

void __fastcall TForm1::FormCreate(TObject *Sender)
{
hCanvas = PaintBox1->Canvas->Handle;
SetPixelFormatDescriptor();
hRC = wglCreateContext(hCanvas);
wglMakeCurrent(hCanvas, hRC);
SetupColor();
}

void __fastcall TForm1::SetPixelFormatDescriptor()
{
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,
PFD_TYPE_RGBA,
24,
0, 0, 0, 0, 0, 0,
0, 0,
0, 0, 0, 0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0, 0, 0
};

PixelFormat = ChoosePixelFormat(hCanvas, &pfd);
SetPixelFormat(hCanvas, PixelFormat, &pfd);
}

void __fastcall TForm1::SetupColor()
{
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}

void __fastcall TForm1::FormPaint(TObject *Sender)
{
glColor3f(1.0f, 0.0f, 0.0f);
glRectf(10.0f, 10.0f, 50.0f, 50.0f);
glFlush();
}

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
wglMakeCurrent(hCanvas, NULL);
wglDeleteContext(hRC);
}

May I ask you for suggestions?
I will by very appreciate

Przemo


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.