what is the problem with this little program ?

With Borland c++ or Visual C++ there are several errors with compilation :

#include <iostream.h>
#include <gl.h>

main ()
{
InitializeAWindowPlease() ;
glClearColor (0.0, 0.0, 0.0, 0.0) ;
glClear (GL_COLOR_BUFFER_BIT) ;
glColor3f (1.0, 1.0, 1.0 ) ;
glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0) ;
glBegin (GL_POLYGON) ;
glVertex3f (0.25, 0.25, 0.0) ;
glVertex3f (0.75, 0.25, 0.0) ;
glVertex3f (0.75, 0.75, 0.0) ;
glVertex3f (0.25, 0.75, 0.0) ;
glEnd () ;
glFlush () ;
UpdateTheWindowAndCheckForEvents ();
}

#include <gl/gl.h>

There is more to the program then you are showing correct?

One error right of the bat is the include file should look like this #include<GL/gl.h>

Also if you post what the error are would also be helpful.

Originally posted by airseb:
[b]With Borland c++ or Visual C++ there are several errors with compilation :

#include <iostream.h>
#include <gl.h>

main ()
{
InitializeAWindowPlease() ;
glClearColor (0.0, 0.0, 0.0, 0.0) ;
glClear (GL_COLOR_BUFFER_BIT) ;
glColor3f (1.0, 1.0, 1.0 ) ;
glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0) ;
glBegin (GL_POLYGON) ;
glVertex3f (0.25, 0.25, 0.0) ;
glVertex3f (0.75, 0.25, 0.0) ;
glVertex3f (0.75, 0.75, 0.0) ;
glVertex3f (0.25, 0.75, 0.0) ;
glEnd () ;
glFlush () ;
UpdateTheWindowAndCheckForEvents ();
}[/b]

Originally posted by airseb:
Topic: what is the problem with this little program ?
}

… a lot … (if this is your code word for word …)

Try This;


#include <glut.h>

void Init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0) ;
}

void Reshape(int w, int h)
{
glMatrixMode(GL_PROJECTION);
glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0) ;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void Display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0 );
glBegin (GL_POLYGON);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
glEnd();
glFlush();
}

void main (int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowSize(300, 300); // Any Window Size will do
glutInitWindowPosition(100, 100); // Again any Window position will do
glutCreateWindow(“Any Name you like”);
glutDisplayFunc(Display);
glutReshapeFunc(Reshape);
glutMainLoop();
}


A FEW POINTERS:
You neither registered a diplay function nor a Reshape function (glutDisplayFunc() & glutReshapeFunc() respectively).

Your projection transform (glOrtho)was concatenated with the model commands

(Minor) you leave spaces between commands and the semi-colon e.g. glWhatever(void)_;

You did not include the header file glut.h, assuming that’s what you wanted to use …

'Looks as if you’re very very new to OpenGL. I suggest you study the 1st 4 chapters of the OpenGL programming guide (aka. the Red Book) before trying to write any more programs …

Sorry to blow your bubble Olumide but that is only if you are using GLUT. Otherwise the code could work properly using straight OpenGL if properly initialised.

First your program is from an example of how Opengl functions and it not a complete program. I found your example here is the program that you are suppost to compile:
Putting it All Together

#include <GL/glut.h>

void display (void) {

/* clear all pixels */
glClear (GL_COLOR_BUFFER_BIT);

/* draw white polygon (rectangle) with corners at

  • (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0) */

    glColor3f (1.0, 1.0, 1.0);
    glBegin (GL_POLYGON);
    glVertex3f (0.25, 0.25, 0.0);
    glVertex3f (0.75, 0.25, 0.0);
    glVertex3f (0.75, 0.75, 0.0);
    glVertex3f (0.25, 0.75, 0.0);
    glEnd ();

/* don’t wait, start processing buffered OpenGL routines */
glFlush ();
}

void init (void) {

/* select clearing (background) color */
glClearColor (0.0, 0.0, 0.0, 1.0);

/* initialize viewing values */
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

/* Declare initial window size, position, and display mode

  • (single buffer and RGBA). Open window with “hello”
  • in its title bar. Call initialization routines.
  • Register callback function to display graphics.
  • Enter main loop and process events. */

int main(int argc, char** argv) {
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow (“hello”);
init ();
glutDisplayFunc (display);
glutMainLoop ();
return 0; /* ISO C requires main to return int. */
}

Originally posted by airseb:
[b]With Borland c++ or Visual C++ there are several errors with compilation :

#include <iostream.h>
#include <gl.h>

main ()
{
InitializeAWindowPlease() ;
glClearColor (0.0, 0.0, 0.0, 0.0) ;
glClear (GL_COLOR_BUFFER_BIT) ;
glColor3f (1.0, 1.0, 1.0 ) ;
glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0) ;
glBegin (GL_POLYGON) ;
glVertex3f (0.25, 0.25, 0.0) ;
glVertex3f (0.75, 0.25, 0.0) ;
glVertex3f (0.75, 0.75, 0.0) ;
glVertex3f (0.25, 0.75, 0.0) ;
glEnd () ;
glFlush () ;
UpdateTheWindowAndCheckForEvents ();
}[/b]

Originally posted by Furrage:
Sorry to blow your bubble Olumide but that is only if you are using GLUT. Otherwise the code could work properly using straight OpenGL if properly initialised.

I would love to see how that could be done … Care to post some code? …


I see Ive been promoted to “Frequent Contributor” status … just for airing my ignorance more than once?!? Now people will actually begin to think I know something … (that’s not fair to the rest of you guys …)

[This message has been edited by Olumide (edited 03-26-2002).]

As long as the function InitializeAWindowPlease() does exactly what is says, and a little more like creating a rendering context, the program will work without any problems.

If you want actual code that initializes a window and creates a rendering context, have a look at NeHe 's site.

The thing about it Bob, is the poster tried to use code that was meant as an example of how to program, but it was not a complete program. Later in the lesson the author goes and gives a working example of the program, which looks like your stander GLUT example of window control and object creation. Which I have posted, I think if we are to give examples, it should be of the correct way of programming a GLUT program.

I wonder if the guy is still wondering why the function InitializeAWindowPlease() is not working.

Originally posted by Bob:
[b]As long as the function InitializeAWindowPlease() does exactly what is says, and a little more like creating a rendering context, the program will work without any problems.

If you want actual code that initializes a window and creates a rendering context, have a look at NeHe 's site.[/b]

Originally posted by Olumide:
I would love to see how that could be done … Care to post some code? …

NeHe’s Tutorials all (well all that I’ve seen) have tuts that don’t use GLUT.