why won't this super-simple glut program run right?

The following code builds with no warnings, but when run displays nothing.

I’m on Redhat9, glxinfo tells me direct rendering is working fine, glxgears runs wildly fast, it’s a 106 miles to Chicago, we’ve got a full tank of gas, half-a-pack of cigarettes,… oh wait.

// tester.cpp

#include <GL/glut.h>

//================================================
void my_init();
void my_display_func();
void my_reshape_func( int w, int h );

//================================================
int main( int argc, char * argv[] )
{
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
    glutInitWindowSize( 600, 600 );
    glutInitWindowPosition( 50, 50 );
    glutCreateWindow( "tester" );
    
    my_init();
    
    glutDisplayFunc( my_display_func );
    glutReshapeFunc( my_reshape_func );
    
    glutMainLoop();
    return 0;
}

//================================================
void my_init()
{
    glClearColor( 0.0, 0.0, 0.0, 0.0 );
    glEnable( GL_DEPTH_TEST );
}

//================================================
void my_display_func()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    
    glColor3f( 0.1, 0.7, 0.3 );
    glBegin( GL_LINE_STRIP );    
        glVertex3d(  0.2,  0.2, 0.0 );
        glVertex3d( -0.2,  0.2, 0.0 );
        glVertex3d( -0.2, -0.2, 0.0 );
        glVertex3d(  0.2, -0.2, 0.0 );
    glEnd();
    
    glutSwapBuffers();
}

//================================================
void my_reshape_func( int w, int h )
{
    if ( w > h )
    {
        glViewport( w/2 - h/2, // x_bottom_left_corner
                    0,         // y_bottom_left_corner
                    h,         // width (x, to the left)
                    h );       // height (y, up)
    }
    else
    {
        glViewport( 0, h/2 - w/2, w, w );
    }
    
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 35.0,  // fovy
                    1.0,   // aspect
                    2.0,   // near
                    6.0 ); // far
 
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    gluLookAt( 0.0, 0.0, 4.0,   // eye position
               0.0, 0.0, 0.0,   // looking at
               0.0, 1.0, 0.0 ); // which way is up
               
    glutPostRedisplay();
}

and makefile is

# makefile for glut_tester
#

APP_NAME = glut_tester
LIBS = -lglut -lGLU -lGL -L/usr/X11R6/lib -lXmu -lXi

$(APP_NAME): main.o
	g++ main.o -Wall -ansi -pedantic-errors -o $(APP_NAME) $(LIBS)

main.o: main.cpp
	g++ -c main.cpp

clean:
	rm -f $(APP_NAME)
	rm -f *.o

Ignore thi
Its probably because your z coords are set to 0.0. They are being culled by the frustum. Try putting them at -3.0 in your glVertex calls.

Edit:
Ooops. Just saw your gluLookAt. I’ll test it for you. No problems. I see 3 green lines as would be expected. Unfortunately that is on Windows using VC++7.

Put the following just after glClearColor in your myinit func.

GLenum err = glGetError();
if (err)
{
const GLubyte* errstr = gluErrorString(err);
printf((char*)errstr);
}

If you get an error then it is likely that a valid context could not be created by GLUT, so you may need to update your video drivers or OpenGL is not supported by your video card or I have no clue and hopefully someone else with more Linux experience than myself will come along.

If you do not get an error, then I still don’t know because I copied your code exactly and only added #pragma comments to link libraries and it worked.

[This message has been edited by shinpaughp (edited 04-08-2003).]

I have redhat 8 at home, later can see what is going on.

I just posted some of my linux GLUT code on my website, would like some feed back from other linux users.
www.angelfire.com/linux/nexusone/

Thanks shinpaughp. I’m at work, but I tried this code here on Solaris 8 sparc and it works fine.

nexusone, is your glut stuff working fine on RH8?

Looks like this is linux-specific, so I’ll ask about it in the linux forum. Thanks again.

Yes, only had to add a header that was not needed with DEV-C++, I think it was something like stdlib.h and string.h.

I have three programs running under glut in RH 8.0 linux, with two of them posted on my website.
I had done some simple stuff under 7.2, but did not use glut, just used KDE framework code to open a window.

Also I downloaded the glut rpm’s from redhat, both the runtime and dev lib’s.

Originally posted by jmg:
[b]Thanks shinpaughp. I’m at work, but I tried this code here on Solaris 8 sparc and it works fine.

nexusone, is your glut stuff working fine on RH8?

Looks like this is linux-specific, so I’ll ask about it in the linux forum. Thanks again.[/b]

try to add glDisable(GL_CULL_FACE) in your gl inits

cb