matb
November 8, 2000, 11:26am
1
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 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
November 8, 2000, 11:30am
2
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…
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
November 10, 2000, 8:26am
4
Cheers Dessium! That worked a treat (and seems very obvious in hindsight!!!). Now I can port my Delphi code over to CBuilder with ease!