Simple GLUT in Borland Builder 6

Hello everyone, first of all I must say it’s a pleasure to finally become a part of this forum. I’m Bruno from Argentina, and I’m a biomedical engineering student. This year will be my last one, so I’m starting to create my degree project. The idea is a freeware program to visualize volumetric MRI/PET/CT/SPECT data from slices, also making possible to merge different studies and volume segmentation. I’ve made a ray casting engine for this purpose, and now I want to go up one level and use openGL for real-time visualization.

I started with the openGL redbook and another guide (made by a guy named Jose Garcia), and (not surprisingly) got stuck in the first example code. This is my main.cpp :

#include <vcl.h>
#pragma hdrstop
#define GLUT_BUILDING_LIB
#include <GL/glut.h>
#include “main.h”

#pragma package(smart_init)
#pragma resource “*.dfm”

TForm1 Form1;
__fastcall TForm1::TForm1(TComponent
Owner)
: TForm(Owner)
{
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowPosition(20,20);
glutInitWindowSize(500,500);
glutCreateWindow(“OGL”);
glutDisplayFunc(display);
glutMainLoop();
}

void TForm1::display()
{
// a lot of init things here
}

My idea is to create an openGL window when clicking Button1 and draw there. I get these errors:

[C++ Error] Unit1.cpp(26): E2034 Cannot convert ‘void (* (_closure )())()’ to ‘void (*)()’

[C++ Error] Unit1.cpp(26): E2342 Type mismatch in parameter ‘func’ (wanted ‘void (*)()’, got ‘void’)

I hope you can help me! Thank you in advance.

GLUT expects a global function, not a function that is part of a class.
Functions that are part of a class have a different parameter signature (they always have a this pointer as a parameter).

If you want it to be part of a class, I think one solution is to declare the member function as “static”.

Functions that are part of a class have a different parameter signature

Pedantic note: functions that are non-static members are not function pointers. They are member pointers, which are not really “pointers” in the traditional sense. The size of void* is not required to be the size of a member pointer.

In short, you can’t just use a member pointer in the same place you would use a function pointer.

It’s not about the function’s signature. It’s about what you get when you dereference the function/member.

That did the trick! Thank you so much, I’ll use this thread in the near future to keep asking questions :slight_smile:

I’ll use this thread in the near future to keep asking questions

No. Create new threads if you have new questions.