To start out I think you should keep everything very simple, now I’m not sure about your code, but here is some very simple code all it does is initialize OGL and display a yellow rectangle.
In your header file define the following;
HDC m_hdc;
HGLRC m_glrc;
then in the source code file;
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include “Unit1.h”
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource “*.dfm”
TForm1 Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TForm1::SetPixelFormatDescriptor()
{
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
//use the default bit planes
0,0,0,0,0,0,
0,
0,
0,
0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
PixelFormat = ChoosePixelFormat(hdc, &pfd); // choose and set the
SetPixelFormat(hdc, PixelFormat, &pfd); // appropriate pixelformat
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
hdc = GetDC(Handle); // get device context from main window
SetPixelFormatDescriptor();
hrc = wglCreateContext(hdc); // use device context to create
// a rendering context
if(hrc == NULL)
ShowMessage(“Creating Rendering Context failed.”);
wglMakeCurrent(hdc,hrc); // tell windows to use hdc and rdc
if(wglMakeCurrent(hdc, hrc) == false)
ShowMessage(“MakeCurrent of rendering context failed.”);
}
void __fastcall TForm1::FormPaint(TObject *Sender)
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0, 0.0, 0.0, 0.0);//black background
glColor3f(1.0,1.0,0.0); //draw yellow
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0,10.0,0.0,10.0,-1.0,1.0);
glBegin(GL_POLYGON);
glVertex3f(2.0,4.0,0.0);
glVertex3f(8.0,4.0,0.0);
glVertex3f(8.0,6.0,0.0);
glVertex3f(2.0,6.0,0.0);
glEnd();
glFlush();
SwapBuffers(m_hdc); // make it visible
}