将 window 选项添加到我的 openGL 渲染器 window

Adding window options to my openGL renderer window

我已经花了大约 3 个小时来安装 GTK 并且它可以工作,但我不知道如何将它添加到 openGL 渲染器,而且我没有找到任何带有简单示例的好教程...有人可以告诉我一个好用且易于安装的库?我认为这并不困难,但我找不到任何可以帮助我的东西。这就是我想要的 http://gyazo.com/543b66d1d1da8c9e05bda62d2663778f I have everything in openGL now my objetive at the moment is something like this: http://tombraiders.net/stella/images/TRLE/trle_screenshot_lg.jpg 但更容易上手...感谢阅读。 PD:我不想要 CEGUI,因为它重叠并且对我不起作用...

我想你有 3.16 版的 gtk。您需要使用 gtk opengl 渲染器,在您的 gtk 代码中使用 GtkGLArea 小部件。您可以使用 Glade 构建您的界面,但我不知道最新版本是否已经支持 GtkGLArea。

gtk3 reference manual gives a small example of code. Here is a small tutorial: tutorial and the files of the example. Another simple code on this .

你可以测试下面的代码,显示一个三角形,但我没有测试它,因为 GtkGLArea 在我的 mingw 系统上不起作用,但它可能对你有帮助,你可能需要通过 -lopengl或 -lopengl32 或 -lepoxy 编译:

#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <GL/gl.h>
#include <GL/glu.h>

static gboolean
render (GtkGLArea *area, GdkGLContext *context) {
  // inside this function it's safe to use GL; the given
  // #GdkGLContext has been made current to the drawable
  // surface used by the #GtkGLArea and the viewport has
  // already been set to be the size of the allocation

  // we can start by clearing the buffer
  glClearColor (0, 0, 0, 0);
  glClear (GL_COLOR_BUFFER_BIT);

  // draw your object
  // draw_an_object ();
  glBegin(GL_TRIANGLES);
    glColor3ub(255,0,0);    glVertex2d(-0.75,-0.75);
    glColor3ub(0,255,0);    glVertex2d(0,0.75);
    glColor3ub(0,0,255);    glVertex2d(0.75,-0.75);
  glEnd();

  glFlush();

  // we completed our drawing; the draw commands will be
  // flushed at the end of the signal emission chain, and
  // the buffers will be drawn on the window
  return TRUE;
}

GtkWidget * create_window1() {
  GtkWidget * window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window1), "test gtk3");
  gtk_window_set_has_resize_grip(GTK_WINDOW (window1), false);

  GtkWidget * vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
  gtk_widget_show (vbox);
  gtk_container_add (GTK_CONTAINER (window1), vbox);

  // create a GtkGLArea instance:
  GtkWidget *gl_area = gtk_gl_area_new ();
  gtk_widget_show (gl_area);
  // add it to the vbox:
  gtk_container_add (GTK_CONTAINER (vbox), gl_area);

  // connect to the "render" signal:
  g_signal_connect (gl_area, "render", G_CALLBACK (render), NULL);

  return window1;
}



int main(int argc, char *argv[]) {
  gtk_init (&argc, &argv);

  GtkWidget * window1 = create_window1 ();
  gtk_widget_show (window1);
  g_signal_connect ((gpointer) window1, "destroy", G_CALLBACK(gtk_main_quit), NULL);

  gtk_main ();
}