Board index » cppbuilder » OpenGL integration problem..

OpenGL integration problem..

First, I DON'T WANT TO TOpenGL COMPONENT!!!!!!!!!!!!!!!!!!!!!!!!!!

Secondly, i would like that someone tell me how to compile openGL program's
from the "OpenGL Programming Guide" on Borland C++ Builder.
Thank you in advance
                Jean-Francois!!!

 

Re:OpenGL integration problem..


I can recommend the soon to be published Borland C++ Builder3 Unleashed book
from SAMS/Borland Press. It will cover using SGI's implementation of OpenGL
strictly within Builder. It will also cover DirectDraw and Direct3D Retained
Mode. It should be available in the coming months. Keep an eye out for the
announcement  in borland.public.cppbuilder.announce.
//jt

Re:OpenGL integration problem..


Quote
Jean-Francois Morneau wrote in message <6cd67h$r...@forums.borland.com>...
>First, I DON'T WANT TO TOpenGL COMPONENT!!!!!!!!!!!!!!!!!!!!!!!!!!

>Secondly, i would like that someone tell me how to compile openGL program's
>from the "OpenGL Programming Guide" on Borland C++ Builder.
>Thank you in advance

I really wonder why you don't want to use my TOpenGL component. Is that
because it's not free?? Cuz otherwise, it works fine, as far as I know.
Furthermore most of the examples from the OpenGL Programming Guide have been
converted to work with TOpenGL. So, what's the problem?? Well, actually, the
problem is that my site is down, so that's maybe why you are not happy...
<g>

    Regards, Alan.

--
Alan GARNY
http://pc-heartbreak.physiol.ox.ac.uk/
Oxford University                              Job Phone: +44 (0)1865
272-501
Department of Physiology                         Job Fax: +44 (0)1865
272-554
Parks Road, Oxford, OX1 3PT, England          Home Phone: +44 (0)1865
370-240

Re:OpenGL integration problem..


I don't think its the "price" of the component, per say..  I my-self am trying
to get OpenGL to compile under BCB..  I'm sure TOpenGL is great, and it probably
does what I'm having problems with now..  However, if I can't figure out how to
do it "my self" (with or without some help) then why bother going in further
into OpenGL?

Speaking of problems.. I'm having problems linking.. I get a weird error
pointing to my Project1.obj..  It says:

[Linker Error] Unresolved external '_Form1' referenced from PROJECT1.OBJ

What does this mean? (This is the last bug in my own opengl program.. sigh..

Thanks in advance, and please reply to:

ug...@ibm.net

Quote
Alan GARNY wrote:
> I really wonder why you don't want to use my TOpenGL component. Is that
> because it's not free?? Cuz otherwise, it works fine, as far as I know.
> Furthermore most of the examples from the OpenGL Programming Guide have been
> converted to work with TOpenGL. So, what's the problem?? Well, actually, the
> problem is that my site is down, so that's maybe why you are not happy...
> <g>

>     Regards, Alan.

> --
> Alan GARNY
> http://pc-heartbreak.physiol.ox.ac.uk/
> Oxford University                              Job Phone: +44 (0)1865
> 272-501
> Department of Physiology                         Job Fax: +44 (0)1865
> 272-554
> Parks Road, Oxford, OX1 3PT, England          Home Phone: +44 (0)1865
> 370-240

Re:OpenGL integration problem..


I don't think its the "price" of the component, per say..  I my-self am trying
to get OpenGL to compile under BCB..  I'm sure TOpenGL is great, and it probably
does what I'm having problems with now..  However, if I can't figure out how to
do it "my self" (with or without some help) then why bother going in further
into OpenGL?

Speaking of problems.. I'm having problems linking.. I get a weird error
pointing to my Project1.obj..  It says:

[Linker Error] Unresolved external '_Form1' referenced from PROJECT1.OBJ

What does this mean? (This is the last bug in my own opengl program.. sigh..

Thanks in advance, and please reply to:

ug...@ibm.net

Quote
Alan GARNY wrote:
> I really wonder why you don't want to use my TOpenGL component. Is that
> because it's not free?? Cuz otherwise, it works fine, as far as I know.
> Furthermore most of the examples from the OpenGL Programming Guide have been
> converted to work with TOpenGL. So, what's the problem?? Well, actually, the
> problem is that my site is down, so that's maybe why you are not happy...
> <g>

>     Regards, Alan.

> --
> Alan GARNY
> http://pc-heartbreak.physiol.ox.ac.uk/
> Oxford University                              Job Phone: +44 (0)1865
> 272-501
> Department of Physiology                         Job Fax: +44 (0)1865
> 272-554
> Parks Road, Oxford, OX1 3PT, England          Home Phone: +44 (0)1865
> 370-240

Re:OpenGL integration problem..


Quote
>I don't think its the "price" of the component, per say..  I my-self am
trying
>to get OpenGL to compile under BCB..  I'm sure TOpenGL is great, and it
probably
>does what I'm having problems with now..  However, if I can't figure out
how to
>do it "my self" (with or without some help) then why bother going in
further
>into OpenGL?

Because it could save you lots of time, if you were not as stubborn as I am
(I also like to understand everything... :)). Otherwise, I don't think to be
more intelligent than anyone else around here, but how do you think I wrote
TOpenGL?? Yes, by having a look at MS on-line help, Win32 documentation,
etc. There is everything one might need in that...

Quote
>Speaking of problems.. I'm having problems linking.. I get a weird error
>pointing to my Project1.obj..  It says:

>[Linker Error] Unresolved external '_Form1' referenced from PROJECT1.OBJ

>What does this mean? (This is the last bug in my own opengl program..

sigh..

By default, BCB creates an external declaration of your form (extern TForm
*Form1;) in your header file (Form1.h). It sounds like you removed the
declaration from your .cpp file (Form1.cpp) that should be: TForm1 *Form1;

    Alan.

Quote
>Alan GARNY wrote:

>> I really wonder why you don't want to use my TOpenGL component. Is that
>> because it's not free?? Cuz otherwise, it works fine, as far as I know.
>> Furthermore most of the examples from the OpenGL Programming Guide have
been
>> converted to work with TOpenGL. So, what's the problem?? Well, actually,
the
>> problem is that my site is down, so that's maybe why you are not happy...
>> <g>

Re:OpenGL integration problem..


Hi, Jean-Francois
I ported  an OpenGl program from the book "OpenGL super bible" to BCB 1.0.
It uses Win32 api and Opengl api directly. There is no component involved.
Quite a bit of code were to do with Palette. If you are not planning to run
the program under 8bits or less video mode, you can strip all Palette
related code. It will be simplified a lot.
By the way, BCB++ 1.0 come with an older version of OpenGL library
(v1.0). Get an updated version from MS or SGI. Then use implib to create
their IMPORT library.
    implib opengl.lib opengl.dll or, implib opengl32.lib opengl32.dll
    implib glu.lib glu32.dll          or, implib glu32.lib glu32.dll
    note: MS version has 32 while SGI version has none.
They both 32 bits DLL.
Any way, You need to set PIXELFORMAT, set Palette if you want your program
to work on any computer that are not capable of displaying more than 256
colors, get handle to the device context of the window you are planning to
render GL to. create GL rendering context. you need to handle On Paint
message. etc.
"OpenGL super bible" is An Excellent book ! if you are working with OPENGL
under MS WINDOWS. It explains all the details
about setting up PIXELFORMAT, Pallete, etc.  I'm deeply thankful the WORKS
of its Authors!

By the way, it probably a good exercise for you to port the codes from the
Red Book over to BCB++.

Enjoy using OPENGL and BCB++! Hope this Help!

Long To (l...@worldnet.att.net)

header file:
// glmain.h. ported by Long To 1/10/98
//--------------------------------------------------------------------------
-
#ifndef glmainH
#define glmainH
//--------------------------------------------------------------------------
-
#include <vcl\Classes.hpp>
#include <vcl\Controls.hpp>
#include <vcl\StdCtrls.hpp>
#include <vcl\Forms.hpp>
#include <vcl\ExtCtrls.hpp>
//--------------------------------------------------------------------------
-
class Tglmain_frm : public TForm
{
__published: // IDE-managed Components
TPanel *Panel1;
TButton *Button1;
void __fastcall FormDestroy(TObject *Sender);
void __fastcall FormResize(TObject *Sender);
void __fastcall FormPaint(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
void __fastcall CreateParams(TCreateParams &Params);
void __fastcall OnQueryNewPalette(TWMQueryNewPalette& Message);
    void __fastcall OnPaletteChanged(TWMPaletteChanged& Message);
    void __fastcall OnEraseBkgnd(TWMEraseBkgnd& Message);
void SetDCPixelFormat(HDC);
    void RenderScene(void);
    HPALETTE GetOpenGLPalette(HDC);
public:  // User declarations
HDC   hDC;
HGLRC hRC;
HPALETTE hPalette;
__fastcall Tglmain_frm(TComponent* Owner);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_QUERYNEWPALETTE,TWMQueryNewPalette,OnQueryNewPalette)
    MESSAGE_HANDLER(WM_PALETTECHANGED,TWMPaletteChanged,OnPaletteChanged)
MESSAGE_HANDLER(WM_ERASEBKGND,TWMEraseBkgnd,OnEraseBkgnd)
END_MESSAGE_MAP(TForm)

Quote
};

//--------------------------------------------------------------------------
-
extern Tglmain_frm *glmain_frm;
//--------------------------------------------------------------------------
-
#endif

application code:
// gltest.cpp. ported by Long To 1/10/98
#include <vcl\vcl.h>
#pragma hdrstop
//--------------------------------------------------------------------------
-
USEFORM("glmain.cpp", glmain_frm);
USERES("gltest.res");
USELIB("\Program Files\Borland\CBuilder\LIB\glu.lib");
USELIB("\Program Files\Borland\CBuilder\LIB\opengl.lib");
//--------------------------------------------------------------------------
-
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
  Application->Initialize();
  Application->CreateForm(__classid(Tglmain_frm), &glmain_frm);
  Application->Run();

Quote
}

catch (Exception &exception)
{
  Application->ShowException(&exception);

Quote
}
return 0;
}

working code:
// glmain.cpp. ported by Long To 1/10/98
//--------------------------------------------------------------------------
-
#include <vcl\vcl.h>
#pragma hdrstop

#include <gl\gl.h>
#include <gl\glu.h>

#include "glmain.h"
//--------------------------------------------------------------------------
-
#pragma resource "*.dfm"

Tglmain_frm *glmain_frm;
//--------------------------------------------------------------------------
-
__fastcall Tglmain_frm::Tglmain_frm(TComponent* Owner)
: TForm(Owner)
{
hDC = GetDeviceContext(Handle);
SetDCPixelFormat(hDC);
    hPalette = GetOpenGLPalette(hDC);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC,hRC);

Quote
}

void __fastcall Tglmain_frm::CreateParams(TCreateParams &Params)
{
TForm::CreateParams(Params); // call base class first
    Params.Style |= (WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
Quote
}

void __fastcall Tglmain_frm::OnEraseBkgnd(TWMEraseBkgnd& Message)
{
  Message.Result = false;
Quote
}

void __fastcall Tglmain_frm::OnQueryNewPalette(TWMQueryNewPalette& Message)
{
   // If the palette was created.
   if(hPalette)
    {
    int nRet;

    // Selects the palette into the current device context
    SelectPalette(hDC, hPalette, FALSE);

    // Map entries from the currently selected palette to
    // the system palette.  The return value is the number
    // of palette entries modified.
    nRet = RealizePalette(hDC);

    // Repaint, forces remap of palette in current window
    Invalidate();

    Message.Result = nRet;
            }

Quote
}

void __fastcall Tglmain_frm::OnPaletteChanged(TWMPaletteChanged& Message)
{
    // Don't do anything if the palette does not exist, or if
   // this is the window that changed the palette.
   if((hPalette != NULL) && (Message.PalChg != Handle))
    {
    // Select the palette into the device context
    SelectPalette(hDC,hPalette,FALSE);

    // Map entries to system palette
    RealizePalette(hDC);

    // Remap the current colors to the newly realized palette
    UpdateColors(hDC);
    Message.Result = NULL;
       }

Quote
}

//--------------------------------------------------------------------------
-
void __fastcall Tglmain_frm::FormDestroy(TObject *Sender)
{
    wglMakeCurrent(NULL,NULL);
wglDeleteContext(hRC);
if(hPalette != NULL)
     DeleteObject(hPalette);
    if(hDC != NULL)
     DeleteObject(hDC);
Quote
}

//--------------------------------------------------------------------------
-
void __fastcall Tglmain_frm::FormResize(TObject *Sender)
{
  GLfloat windowHeight,windowWidth;

GLsizei w,h;
    w = (GLsizei)Width;
    h = (GLsizei)Height-2*Panel1->Height;

// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if(h == 0)
  h = 1;

// Set the viewport to be the entire window
    glViewport(0, 0, w, h);

// Reset the coordinate system before modifying
    glLoadIdentity();

// Keep the square square.

// Window is higher than wide
if (w <= h)
  {
  windowHeight = 250.0f*h/w;
  windowWidth = 250.0f;
  }
    else
  {
  // Window is wider than high
  windowWidth = 250.0f*w/h;
  windowHeight = 250.0f;
  }

// Set the clipping volume
glOrtho(-windowWidth, windowWidth, -windowHeight, windowHeight,
1.0f, -1.0f);

Invalidate();

Quote
}

//--------------------------------------------------------------------------
-
void __fastcall Tglmain_frm::FormPaint(TObject *Sender)
{
RenderScene();

SwapBuffers(hDC);

Quote
}

void Tglmain_frm::RenderScene(void)
{
  glClearColor(1.0f,1.0f,1.0f,1.0f);

// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);

// Enable smooth shading
glShadeModel(GL_SMOOTH);

// Draw the triangle
glBegin(GL_TRIANGLES);
  // Red Apex
  glColor3f(1.0f,0.0f,0.0f);
  glVertex3f(0.0f,200.0f,0.0f);

  // Green on the right bottom corner
  glColor3f(0.0f,1.0f,0.0f);
  glVertex3f(200.0f,-70.0f,0.0f);

  // Blue on the left bottom corner
  glColor3f(0.0f,0.0f,1.0f);
  glVertex3f(-200.0f, -70.0f, 0.0f);

glEnd();

// Flush drawing commands
glFlush();

Quote
}

//-----------------------------------------
// Select the pixel format for a given device context
void Tglmain_frm::SetDCPixelFormat(HDC hDC)
{
int nPixelFormat;

static PIXELFORMATDESCRIPTOR pfd = {
  sizeof(PIXELFORMATDESCRIPTOR), // Size of this structure
  1,        // Version of this structure
  PFD_DRAW_TO_WINDOW |   // Draw to Window (not to bitmap)
  PFD_SUPPORT_OPENGL |   // Support OpenGL calls in window
  PFD_DOUBLEBUFFER,    // Double buffered mode
  PFD_TYPE_RGBA,     // RGBA Color mode
  24,        // Want 24bit color
  0,0,0,0,0,0,     // Not used to select mode
  0,0,       // Not used to select mode
  0,0,0,0,0,      // Not used to select mode
  32,        // Size of depth buffer
  0,        // Not used to select mode
  0,        // Not used to select mode
  PFD_MAIN_PLANE,     // Draw in main plane
  0,        // Not used to select mode
  0,0,0 };      // Not used to select mode

// Choose a pixel format that best matches that described in pfd
nPixelFormat = ChoosePixelFormat(hDC, &pfd);

// Set the pixel format for the device context
SetPixelFormat(hDC, nPixelFormat, &pfd);

Quote
}

// If necessary, creates a 3-3-2 palette for the device context listed.
HPALETTE Tglmain_frm::GetOpenGLPalette(HDC hDC)
{
HPALETTE hRetPal = NULL; // Handle to palette to be created
PIXELFORMATDESCRIPTOR pfd; // Pixel Format Descriptor
LOGPALETTE *pPal;   // Pointer to memory for logical palette
int nPixelFormat;   // Pixel format index
int nColors;    // Number of entries in palette
int i;      // Counting variable
BYTE RedRange,GreenRange,BlueRange;
        // Range for each color entry (7,7,and 3)

// Get the pixel format index and retrieve the pixel format description
nPixelFormat = GetPixelFormat(hDC);
DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR),
&pfd);

// Does this pixel format require a palette?  If not, do not create a
// palette and just return NULL
if(!(pfd.dwFlags & PFD_NEED_PALETTE))
  return NULL;

// Number of entries in palette.  8 bits yeilds 256 entries
nColors = 1 << pfd.cColorBits;

// Allocate space for a logical palette structure plus all the palette
entries
pPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE)
+nColors*sizeof(PALET{*word*249}TRY));

// Fill in palette header
pPal->palVersion = 0x300;  //
...

read more »

Re:OpenGL integration problem..


Hi, Jean-Francois,
One thing I forgot to mention on last post. 2nd edition of "OpenGL
Programming Guide" use a Utility library to simplify coding for OpenGL. It's
called GLUT, written and maitained by Mark Kilgard. It hides all the details
regard message loop, palette, etc. and let you concentrate on learning GL
API. You can obtain GLUT library with source from SGI's website. I've
compiled the GLUT library for BCB++ 1.0. And it works GREAT! This is another
option for you to experiment with GL on BCB++ 1.0 without using Component
Model. I believe one should know how to program the GL API and Win32 API.
Good Luck!

Long

Quote
Jean-Francois Morneau wrote in message <6cd67h$r...@forums.borland.com>...
>First, I DON'T WANT TO TOpenGL COMPONENT!!!!!!!!!!!!!!!!!!!!!!!!!!

>Secondly, i would like that someone tell me how to compile openGL program's
>from the "OpenGL Programming Guide" on Borland C++ Builder.
>Thank you in advance
>                Jean-Francois!!!

Other Threads