OpenGL - displayList - gl_draw

17 views
Skip to first unread message

holm.h...@gmail.com

unread,
Sep 25, 2020, 12:13:32 PM9/25/20
to fltk.general

Hello,

I tried to call gl_draw into a displaylist. That was not a sucsess.Can be examplified by the cube.cxx test-code. I but the gl_draw in a displaylist (code below), but then nothing show in the screen.

Suprise to me. Should that be expected, or is this a bug? Btw. to me it seems like gl_draw is pretty he heavy function/draw a lot of cpu.

  static GLuint DisplayList=-1;
  if (DisplayList<0){ glDeleteLists(DisplayList, 1);
    DisplayList = glGenLists (1);
    glNewList(DisplayList, GL_COMPILE);
    gl_draw(wire ? "Cube: wire" : "Cube: flat", -4.5f, -4.5f );
    glEndList();
  }
  glCallList(DisplayList);
 
Best regards
Håvard

Greg Ercolano

unread,
Sep 25, 2020, 12:32:51 PM9/25/20
to fltkg...@googlegroups.com
Would need to see more code to weigh in.. can you supply a minimal
complete, compilable program so we can build and replicate?
Sometimes the problem is elsewhere, e.g. during setup.

holm.h...@gmail.com

unread,
Sep 25, 2020, 1:44:43 PM9/25/20
to fltk.general
Hi,

Here comes the whole cube_box::draw( routine from test/cube.cxx

void cube_box::draw() {
  lasttime = lasttime+speed;
  if (!valid()) {
    glLoadIdentity();
    glViewport(0,0,pixel_w(),pixel_h());
    glEnable(GL_DEPTH_TEST);
    glFrustum(-1,1,-1,1,2,10000);
    glTranslatef(0,0,-10);
    glClearColor(0.4, 0.4, 0.4, 0);
  }
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glPushMatrix();
  glRotatef(float(lasttime*1.6),0,0,1);
  glRotatef(float(lasttime*4.2),1,0,0);
  glRotatef(float(lasttime*2.3),0,1,0);
  glTranslatef(-1.0, 1.2f, -1.5);
  glScalef(float(size),float(size),float(size));
  drawcube(wire);
  glPopMatrix();
  gl_color(FL_GRAY);
  glDisable(GL_DEPTH_TEST);
  gl_font(FL_HELVETICA_BOLD, 16 );

  static GLuint DisplayList=-1;
  if (DisplayList<0){ glDeleteLists(DisplayList, 1);
    DisplayList = glGenLists (1);
    glNewList(DisplayList, GL_COMPILE);
    gl_draw(wire ? "Cube: wire" : "Cube: flat", -4.5f, -4.5f );
    glEndList();
  }
  glCallList(DisplayList);
 
  glEnable(GL_DEPTH_TEST);

  // if an OpenGL graphics driver is installed, give it a chance
  // to draw additional graphics
  if (Fl::cfg_gfx_opengl) Fl_Gl_Window::draw();

Ian MacArthur

unread,
Sep 25, 2020, 3:13:31 PM9/25/20
to fltkg...@googlegroups.com
On 25 Sep 2020, at 18:44, holm.haavard wrote:
>

Given the usual caveat that no one should take GL advice from me, since I’m rubbish at it...

> static GLuint DisplayList=-1;
> if (DisplayList<0){ glDeleteLists(DisplayList, 1);


Is that even valid? Here you will be deleting a list that has never been created, which seems... wrong...

> DisplayList = glGenLists (1);
> glNewList(DisplayList, GL_COMPILE);
> gl_draw(wire ? "Cube: wire" : "Cube: flat", -4.5f, -4.5f );


I’m not sure it makes sense to put this a list anyway, as the whole point is that it might change from one draw() to another, so needs to be checked on each iteration...


Also, if I understand properly, your concern is that gl_draw() is too heavy to call every time. Do you have actual measurements to show this?
In practice the gl_draw() in 1.4 generally caches it’s output texture buffer, so if the text string does not change, it should be pretty cheap to call.

What do your timings show?


duncan

unread,
Sep 25, 2020, 3:35:05 PM9/25/20
to fltk.general
  static GLuint DisplayList=-1;
  if (DisplayList<0){ glDeleteLists(DisplayList, 1);

 Surely a GLuint is an unsigned int, so assigning -1 will cause rollover and the test can never be satisfied?

D.

holm.h...@gmail.com

unread,
Sep 25, 2020, 4:08:32 PM9/25/20
to fltk.general
Duncan, I'm so embarrased you are right, the test can never be satisfied. However with these corrected lines still the text do still not show :
  static GLuint DisplayList=1000;
  if (DisplayList==1000){
    printf("Hi\n");

    DisplayList = glGenLists (1);
    glNewList(DisplayList, GL_COMPILE);
    gl_draw("FLTK is great!", -4.5f, -4.5f );
    glEndList();
  }
  glCallList(DisplayList);

Ian, you may be right that gl_draw is not slow. Still in my code I would like to put opengl-calls in a displaylist.

Ian MacArthur

unread,
Sep 25, 2020, 4:20:19 PM9/25/20
to fltkg...@googlegroups.com
On 25 Sep 2020, at 21:08, holm.haavard wrote:
>
> Ian, you may be right that gl_draw is not slow. Still in my code I would like to put opengl-calls in a displaylist.


Careful, I do not think that will work - gl_draw() is *not* an OpenGL call, it’s a fltk method, with a "gl-like” name; in effect it is a substitute for fl_draw() that is intended to work in the GL context if a Fl_Gl_Window.

But it is not implemented as “pure” GL because it needs to interact with the fltk environment (e.g. for the text rendering, since the GL text rendering is... um... less capable... shall we say.)

So I doubt putting gl_draw() in a display list will ever work, frankly.



Reply all
Reply to author
Forward
0 new messages