Hi… I’m trying to create an OpenGL App. with Borland C++Builder 6.0. As far as I read I get to these:
Unit1.cpp
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
Application->OnIdle = IdleLoop;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdleLoop(TObject*, bool& done)
{
RenderGLScene();
SwapBuffers(hdc);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RenderGLScene()
{
glRectf(-5.0, 5.0, 5.0, -5.0);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
hdc = GetDC(Handle);
SetPixelFormatDescriptor();
hrc = wglCreateContext(hdc);
wglMakeCurrent(hdc, hrc);
SetupRC();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetupRC()
{
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
ReleaseDC(Handle,hdc);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hrc);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetPixelFormatDescriptor()
{
PIXELFORMATDESCRIPTOR pfd;
ZeroMemory( &pfd, 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.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
int iFormat = ChoosePixelFormat( hdc, &pfd );
SetPixelFormat( hdc, iFormat, &pfd );
}
Unit1.h
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <gl/gl.h>
#include <gl/glu.h>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
private:
HDC hdc;
HGLRC hrc;
int PixelFormat;
public:
__fastcall TForm1(TComponent* Owner);
void __fastcall IdleLoop(TObject*, bool&);
void __fastcall RenderGLScene();
void __fastcall SetPixelFormatDescriptor();
void __fastcall SetupRC();
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
but only the window appears… not the OpenGL and the rect it has to draw… can anyone help me solv the problem… Thanks beforehand