Absolute begginner help

Forgive me but we all have to start somewhere. I am totally new to opengl

I am trying to create the simplest window as a starting point. Compiling is ok. Linking fails. I need some help.

Details

Windows XP, Borland C++ Builder version 6
Code has been copied from one of the many web tutorials and it compiles fine.

The link error is as follows (2 errors)

[Linker Error] Unresolved external ‘_Form1’ referenced from …myfile.obj

and then a repeat with ‘TForm1’ instead of ‘_Form1’

Firstly I do not understand the error fully and secondly I have no direct references to these forms in the code.

Can anyone shed some light on this for me. Sorry if this is a dumb question. I have been looking at open gl for about 4 hours now (including getting C++ up and running) and most of that time has been on help and web to try to resolve this.

If it helps I have copied the full code used to www.good-image.co.uk (no formatting)

I may have been a little premature!

I have started again as I made a guess that the code was conflicting with something else that may have been left behind from another test.

I get it to compile, link, build and run now.

BUT

All I get is a blank window, no pretty triangle. I will keep looking at it. If anyone can help in this new aspect please see the code at good-image.co.uk and offer any advice.

Thanks

Gwynnnn,
I don’t see projection settings in your code. The eye (viewpoint) is at (0,0,0) and looking along -Z axis by default. The view point may be on the same plane where the pretty triagle is placed.

Try to move the triangle backward a little, for example:

void display()
{
    /* rotate a triangle around */
    glClear(GL_COLOR_BUFFER_BIT);

    glBegin(GL_TRIANGLES);
    glColor3f(1.0f, 0.0f, 0.0f);
    glVertex3i(0, 1, -3);
    glColor3f(0.0f, 1.0f, 0.0f);
    glVertex3i(-1, -1, -3);
    glColor3f(0.0f, 0.0f, 1.0f);
    glVertex3i(1, -1, -3);
    glEnd();

    glFlush();
}

Thanks for looking. I think my problems are way more basic than that. But I will appreciate your help never the less.

When I do a run I get a blank form (Form1) no colours, no trinagles, nothing. So my guess is that I am really doing something basic wrongly.

I notice that I have a bit more code that I should have put on to good-image that I had thought was irrelevant. Wrong probalby, so I will put up the complete code.

Please have a look and tell me why it draws up Form1 and does not attempt (apprantly) to draw any coloured triangle.

I think it explains why Form1 appears, but I am stumped as to where the triangle or window with a triangle is.

Sorry I am having a bit of a panic attack. Copied the wrong file up. I have now copied the right file.

I suspect that i need to put something onto Form1, presently I have put nothing at all. Any suggestions?

I believe that the code shown does not touch the windowing or display parts when running. This is my own error thoughg a lack of understanding.

Can anyone suggest what I should be writing in order to get things up on the desired window?

I think I have completely lost it.

Is there anyone I can ask to lead me through these initial stages.

I can’t even get it to ‘like’ references to glut.

I despair right now.

With default projection matrix (identity matrix) you need to have Z coordinate of the vertices inside the <-1,1> range. After that change (and removal of Borland specific stuff from file beginning) the triangle was shown when I compiled your source in Microsoft Visual C++.

While not directly related, the ReleaseDC expects hwnd as first parameter.

Thank you for at least replying. I will be fine once i get at least one working situation.

I have now removed the borland specific stuff

(I presume you mean this part shown at the end of this text

however, I am totally new to open gl, how do I make the z coordinate range acceptable? Can you give me the example?

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

#include <vcl.h>
#pragma hdrstop

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

ok this is showing just how little I understand at this time. I will get there but right now I’m on very thin ice.

I removed the offending code (At least I think that was the code I think you meant) and we went right back to the linker error problem of referencing a form being unresolved.

So can I go back to the very start. What sort of item do i create? Is it an application? A Unit? simple text?

All compile, none link without the top code added.

How about a simple 1,2,3 guide

Sorry to be so dumb.

Just how did you get yours to work. Can you help me. Perhaps post the code as is? and let me know what sort of application you created to make it work?

Ok things are better.

I have removed the offending code at the top.

I have created a cpp file and it compiles, and builds. We are now back to the blank screen.

If it is just a coordinate problem then just to help me out can you let me know which lines need changing to what.

I will continue to bash away at it.

As I hav eno visual clues it is difficult for me to see where I may be going wrong

I presume the z plane references you are referring to are here

void display()
{
/* rotate a triangle around */
glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3i(0, 1, 0.5);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3i(-1, -1, -0.5);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3i(1, -1, -0.5);
glEnd();

glFlush();
}

Have I changed them (0.5, -0.5) in a way that will help or wreck it?

It still gives me a blank window anyway, whatever values I try.

Can you tell me exactly what I should be seeing when the program runs? as it would help.

Should I be seeing a form only? Should there be another box or window inside that? (I think not). Should there be a coloured triangle only inside the form? (I think so).

To start out I think you should keep everything very simple, now I’m not sure about your code, but here is some very simple code all it does is initialize OGL and display a yellow rectangle.

In your header file define the following;

HDC m_hdc;
HGLRC m_glrc;

then in 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                               
};
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(m_hdc); // make it visible

}

Thank you for taking the trouble to post up the example code. I had taken the simplest code I could find previously.

I have now entered your code into a header file and a code fle. It compliles, makes and builds fine.

Unfortunately I still only get a Form1 which is very nice shade of buff brown, but absolutely nothing drawn inside it.

This is beggining to sound a lot more fundamental but i have absolutely no idea what is wrong at this stage.

Any ideas?

Originally posted by Gwynnnn:
[b] Can you tell me exactly what I should be seeing when the program runs? as it would help.

Should I be seeing a form only? Should there be another box or window inside that? (I think not). Should there be a coloured triangle only inside the form? (I think so). [/b]
I am seeing this image . I uploaded modified source code and compiled program to that page so you can try it if it works for you.

What graphic card do you have?

Oh now that is the sort of thing I was expecting and wanting to see.

I have only recently built the new PC. It has an NVIDIA GeForce 7900 GT card. It is GL enabled as I have run a pre compiled item I found on the net yesterday.

My problems seem to be stemming from my lack of understanding of Borland C++ version 6. There must be something that i have not set or done.

What i see is like a normal empty form. I could be creating an dbuilding all wrong. The small window in your example image is what I expected to see but it is absent (or not visible).

Anyone want to take it step by step from opening the C++ IDe to the run itself?

Ah ha. A step further. I deleted all forms that were present on start up of the C++ IDE. I then loaded up the example. Built it. and then ran it.

What did I get -

Absolutely nothing at all! A blink of the object viewer window 9as expected) and then all back to the code window.

My conclusion from this is that if the porogram is running then it is going straight through it and ending before i can see anything at all.

Any help?