Absolute begginner help

To run the source code from me you probably need to select some sort of “Windows application without forms” build/linking option otherwise the builder will create its own initialization code that tries to run the forms and will ignore the WinMain function.

I never used the Borland compiler so I do not know how to select that.

EDID: I read some tutorial on net and it appears that you need to create new application project using the “Console Wizard” type.

Mmm that seems logical. So I have now created a console unit in borland C++.

The code compiles, makes, builds, runs and we now get a console window (as expected)

BUT

No graphics.

I really think that this is a very basic fundamental cock up on my part.

I am very grateful for your help and please keep it coming. At some point it must crack.

Other points: the black console window appears to be very large. GFar larger than I woudl have expected.

It certainly is not 0,0,256,256

It seems wider and I have to scroll down a long way to get to the bottom.

So it may jus tbe a normal sized console window. ie not drawn up by the graphics application code.

Incidentally I am still using the code kindly posted here by an earlier contributor if you are interested.

Yes, I think I am right as the console window shown when running has no title (Minimal) at all. Its just a console window. So this may or may not be the right direction.

There are two application types you can create. With console (this is the one you created) and without console, both should be creatable using the “Console Wizard” (at least according to the tutorials I read). In MSVC they each expect different main function and only the one without console expect the WinMain.

Code from marc2718 on the other hand requires the Borland forms however I do not have that compiler so I can not try that by myself.

Is there anyone out there who has Borland C++ Builder version 6 and can lead me through setting up a siomple gl app (ie a window and a cbe of colour), step by step?

Gwynnn, sorry my code was inconsistent (the variable names), actually it should not have compiled for you.
Anyhow, the following is correct.
( I think this is as simple as it can get)

The best thing for this code just create a new regular c++ builder application.
NOT a console application, that is not the way you will be using C++ Builder.

Cut and paste this code into your app.
You need to create the OnCreate event and the OnPaint event then just add the code in there.
The only function you need to create manually is
the SetPixelFormatDescriptor function.

in the header file;

#include <gl\gl.h>

//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall FormPaint(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
private: // User declarations

HDC hdc; // device context
HGLRC hrc; //rendering context

void SetPixelFormatDescriptor();

public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

Now the source code file;

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include “Unit1.h”
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource “*.dfm”
TForm1 Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent
Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void TForm1::SetPixelFormatDescriptor()
{

PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |

PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
32,
//use the default bit planes
0,0,0,0,0,0,
0,
0,
0,
0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
int PixelFormat = ChoosePixelFormat(hdc, &pfd); // choose and set the
SetPixelFormat(hdc, PixelFormat, &pfd); // appropriate pixelformat

}

void __fastcall TForm1::FormCreate(TObject *Sender)
{

hdc = GetDC(Handle); // get device context from main window
SetPixelFormatDescriptor();
hrc = wglCreateContext(hdc); // use device context to create
// a rendering context
if(hrc == NULL)
ShowMessage(“Creating Rendering Context failed.”);
wglMakeCurrent(hdc,hrc); // tell windows to use hdc and rdc
if(wglMakeCurrent(hdc, hrc) == false)
ShowMessage(“MakeCurrent of rendering context failed.”);

}

void __fastcall TForm1::FormPaint(TObject *Sender)
{

glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0, 0.0, 0.0, 0.0);//black background

glColor3f(1.0,1.0,0.0); //draw yellow

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glOrtho(0.0,10.0,0.0,10.0,-1.0,1.0);
glBegin(GL_POLYGON);
glVertex3f(2.0,4.0,0.0);
glVertex3f(8.0,4.0,0.0);
glVertex3f(8.0,6.0,0.0);
glVertex3f(2.0,6.0,0.0);
glEnd();

glFlush();
SwapBuffers(hdc); // make it visible

}

You lost me a little

You need to create the OnCreate event and the OnPaint event then just add the code in there.

Not sure what code you mean here

The only function you need to create manually is
the SetPixelFormatDescriptor function.

How and what do i put in it.

Sorry but I am really very new to all of this.

Thanks though

I am looking at it right now anyway to see if I can blunder my way through

By the way I tested this code in the compiler,I know it compiles, your video card is fine.
It has to work! :slight_smile:

You should see a window with yellow rectangle in the center with a black background.

Ah getting a bit clearer. Found the on create evewnt in the object inspector. I will shove the code into that.

ok created the events, not sure what code exactly to shove in.

Worked that one out too now.

Nearer to compiling - not ready to try just yet

Only the pixeldescriptor bit left to figure out.

Well bless me. It all works. I have a black rectangular box with an inner yellow box (both filled).

Oh yesssss.

I am so very very grateful to you all.

I felt that it was a bit tough going but then we all have ot go through the ‘hello world’ stage.

Thanks for your patience and advice

This has been a good and helpful thread to me.

Now all I have ot do is climb the rest of the 160000000 mile mountain.

Noooo disaster.

I saved the files and reopened them and now I have 18 errors and nothing works.

Agh!!

Phew, just a mild panic.

I redid the whole thing and had named the header file wrongly in my panic.

It’s amazing how importnat a name can be!

I really must go and have a quiet drink!

Thanks once again.

Its nearly midnight here so I may just give it a rest until tomorrow night.

Goodnight to you all. I will now sleep a lot more soundly. I have made some real progress this evening. Thank you