PDA

View Full Version : Windows 98, CBuilder, wglCreateContext prob



matb
11-08-2000, 12:26 PM
Dear all,

I am using Borland C++ Builder (I'm afraid I don't have a choice of compiler http://www.opengl.org/discussion_boards/ubb/redface.gif( ). 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* Owner)
: 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

matb
11-08-2000, 12:30 PM
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 http://www.opengl.org/discussion_boards/ubb/redface.gif) and never had to refer to any tutorials!!!

Basically - where do I find these tutorials?

Deiussum
11-09-2000, 08:38 AM
Before you can use wglCreateContext, you must setup the pixel format of the HDC. You do that by doing something like so...

PIXELFORMATDESCRIPTOR pfd;
int pf;

ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));

pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
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 http://nehe.gamedev.net/opengl.asp.

matb
11-10-2000, 09:26 AM
Cheers Dessium! That worked a treat (and seems very obvious in hindsight!!!). Now I can port my Delphi code over to CBuilder with ease!