コード例 #1
0
ファイル: viewlw.c プロジェクト: inniyah/gtkglext3
static gboolean
draw(GtkWidget *widget,
     cairo_t   *cr,
     gpointer   data)
{
  GdkGLContext *glcontext = gtk_widget_get_gl_context(widget);
  GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(widget);

  GLfloat m[4][4];
  mesh_info *info = (mesh_info*)g_object_get_data(G_OBJECT(widget), "mesh_info");

  /*** OpenGL BEGIN ***/
  if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
    goto NO_GL;

  /* basic initialization */
  if (info->do_init == TRUE) {
    initgl();
    info->do_init = FALSE;
  }

  /* view */
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(info->zoom, VIEW_ASPECT, 1,100);
  glMatrixMode(GL_MODELVIEW);

  /* draw object */
  glClearColor(.3,.4,.6,1);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

  glLoadIdentity();
  glTranslatef(0,0,-30);
  add_quats(info->dquat, info->quat, info->quat);
  build_rotmatrix(m,info->quat);
  glMultMatrixf(&m[0][0]);

  lw_object_show(info->lwobject);

  /* swap backbuffer to front */
  if (gdk_gl_drawable_is_double_buffered(gldrawable))
    gdk_gl_drawable_swap_buffers(gldrawable);
  else
    glFlush();

  gdk_gl_drawable_gl_end(gldrawable);
  /*** OpenGL END ***/

 NO_GL:

  return TRUE;
}
コード例 #2
0
void TestGLCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
{
    /* must always be here */
    wxPaintDC dc(this);

#ifndef __WXMOTIF__
    if (!GetContext()) return;
#endif

    SetCurrent();

    // Initialize OpenGL
    if (info.do_init)
    {
        InitGL();
        info.do_init = false;
    }

    // View
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( info.zoom, VIEW_ASPECT, 1.0, 100.0 );
    glMatrixMode( GL_MODELVIEW );

    // Clear
    glClearColor( 0.3f, 0.4f, 0.6f, 1.0f );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    // Transformations
    GLfloat m[4][4];
    glLoadIdentity();
    glTranslatef( 0.0f, 0.0f, -30.0f );
    build_rotmatrix( m,info.quat );
    glMultMatrixf( &m[0][0] );

    // Draw object
    lw_object_show( info.lwobject );

    // Flush
    glFlush();

    // Swap
    SwapBuffers();
}
コード例 #3
0
ファイル: viewlw.c プロジェクト: alexmurray/gtkglext
static gboolean
draw(GtkWidget *widget,
     cairo_t   *cr,
     gpointer   data)
{
  GLfloat m[4][4];
  mesh_info *info = (mesh_info*)g_object_get_data(G_OBJECT(widget), "mesh_info");

  /*** OpenGL BEGIN ***/
  if (!gtk_widget_begin_gl (widget))
    goto NO_GL;

  /* basic initialization */
  if (info->do_init == TRUE) {
    initgl();
    info->do_init = FALSE;
  }

  /* view */
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(info->zoom, VIEW_ASPECT, 1,100);
  glMatrixMode(GL_MODELVIEW);

  /* draw object */
  glClearColor(.3,.4,.6,1);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

  glLoadIdentity();
  glTranslatef(0,0,-30);
  add_quats(info->dquat, info->quat, info->quat);
  build_rotmatrix(m,info->quat);
  glMultMatrixf(&m[0][0]);

  lw_object_show(info->lwobject);

  gtk_widget_end_gl(widget, TRUE);
  /*** OpenGL END ***/

 NO_GL:

  return TRUE;
}