Problem with 3D

Hi all

I have made small program using OpenGL under Linux using GTKGLarea.

D works fine, but when I try to write 3D, then it doesn’t show up at all.

Here is code:

gint glarea_init (GtkWidget* widget) {
if (gtk_gl_area_make_current (GTK_GL_AREA(widget))) {
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glShadeModel(GL_SMOOTH); glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_DEPTH_TEST);
}
return true
}

gint glarea_reshape (GtkWidget* widget, GdkEventConfigure* event) {
int w = widget->allocation.width;
int h = widget->allocation.height;
if (gtk_gl_area_make_current (GTK_GL_AREA(widget))) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective( 55.0f, (GLfloat)w/(GLfloat)h, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
}
return (TRUE);
}

gint glarea_draw (GtkWidget* widget, GdkEventExpose* event) {
int w = widget->allocation.width;
int h = widget->allocation.height;
if (event->count > 0) {
return(TRUE);
}

if (gtk_gl_area_make_current(GTK_GL_AREA(widget))) {
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glBegin(GL_LINES);
  glVertex3f(  0.0, 0.0, 500.0);
  glVertex3f(0.0,0.0, -500.0);
  glEnd();

  gtk_gl_area_swapbuffers (GTK_GL_AREA(widget));

}
return (TRUE);
}

That’s about it.

Any sugestions?

Thanx

With that setup, you won’t see anything except maybe a tiny little dot. You are looking directly down the Z axis at a line drawn right along the Z axis. If you were looking slightly off-center of the Z-axis, or your line was drawn a bit off-center from the Z-axis, then you would see something.

Yes, you are right,it is a bad example. But still do not work.

More info needed. What did you do to “make it work?”