FLTK logo

Re: How to draw “fixed” text in OpenGL windows

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.opengl  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: How to draw “fixed” text in OpenGL windows D. Zimmer Mar 03, 2006  
 
> I searched the previous articles in the forum. Now I understant why the text is transformed just like an object. My question still remains. How to draw the text specified in screen coordinates? Thanks for all helps.
>
> With best wishes,
>
> Linda

Linda,

Solution 1:


My_GL_Window::draw()
{
  glViewport(0, 0, w(), h());

  setup_3D_projection();
  setup_3D_view();
  draw_3D_stuff();

  // setup 2D projection
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0, w(), 0, h(), -1, 1);

  // setup 2D view
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  draw_2D_Stuff();
}


However, if your draw() currently looks like this:


My_GL_Window::draw()
{
  if(!valid)
  {
    glViewport(0, 0, w(), h());
    setup_3D_projection();
  }

  setup_3D_view();
  draw_3D_stuff();
}


then you will need solution 2:


My_GL_Window::draw()
{
  if(!valid)
  {
    glViewport(0, 0, w(), h());
    setup_3D_projection();
  }

  setup_3D_view();
  draw_3D_stuff();

  // save and setup 2D projection
  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  glOrtho(0, w(), 0, h(), -1, 1);

  // save and setup 2D view
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glLoadIdentity();

  draw_2D_Stuff();

  // restore 3D state
  glPopMatrix();
  glMatrixMode(GL_PROJECTION);
  glPopMatrix();
}


Don.




Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.