Windows 98, CBuilder, wglCreateContext prob

Dear all,

I am using Borland C++ Builder (I’m afraid I don’t have a choice of compiler ( ). If I start Builder and literally in my main file I have the following code:-

#include “gl/gl.h”
#include “gl/glu.h”
#include <windows.h>
#pragma package(smart_init)
#pragma resource “*.dfm”
TForm1 Form1;
__fastcall TForm1::TForm1(TComponent
: TForm(Owner)
HWND hwnd = NULL;
hwnd = Handle;
HDC hdc = NULL;
hdc = GetDeviceContext(hwnd);
HGLRC hglrc = NULL;
hglrc = wglCreateContext(hdc);

then hglrc is NULL!!! What am I doing wrong?

Yours Sincerely,
Matthew Banham

Incidentally, I was GREPping through the old archives of this forum (for a solution) and found a lot of references to NeHe tutorials.

I used OpenGL on Delphi a long long time ago with very little difficulty ) and never had to refer to any tutorials!!!

Basically - where do I find these tutorials?

Before you can use wglCreateContext, you must setup the pixel format of the HDC. You do that by doing something like so…

int pf;

ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));

pfd.nVersion = 1;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 16;

pf = ChoosePixelFormat(hdc, &pfd);

DescribePixelFormat(hdc, pf, sizeof(PIXELFORMATDESCRIPTOR),&pfd);
SetPixelFormat(hdc, pf, &pfd);

The Nehe tutorials are at

Cheers Dessium! That worked a treat (and seems very obvious in hindsight!!!). Now I can port my Delphi code over to CBuilder with ease!