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 the 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

Your GL_LINE is apparently coincident with the z axis; in the x-y plane it will not be visible at all.

Also, the values for the vertex (z = 500 and -500) are way out of the near-far plane sandwich defined by gluPerspective (I think, I haven’t checked carefully). This is just an observation; it should just crop the line, not making it disappear.

And another thing: gtkglarea is deprecated. Use gtkglext instead.

[This message has been edited by FermatSpiral (edited 10-23-2003).]

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.