82 satır
2.1 KiB

  1. #include <SDL.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include "gtkvideo.h"
  5. #include "game.h"
  6. #include <math.h>
  7. #include <gtk/gtk.h>
  8. #include <gtkgl/gtkglarea.h>
  9. #include <GL/gl.h>
  10. volatile int quit = 0;
  11. static gint main_quit(GtkWidget *widget, GdkEventExpose *event)
  12. {
  13. quit = 1;
  14. return FALSE;
  15. }
  16. int main(int argc, char **argv)
  17. {
  18. GtkWidget *window, *glarea;
  19. /* initialize gtk */
  20. gtk_init(&argc, &argv);
  21. /* Create new top level window. */
  22. window = gtk_window_new( GTK_WINDOW_TOPLEVEL);
  23. gtk_window_set_title(GTK_WINDOW(window), "Simple");
  24. gtk_container_set_border_width(GTK_CONTAINER(window), 10);
  25. /* Quit form main if got delete event */
  26. gtk_signal_connect(GTK_OBJECT(window), "delete_event",
  27. GTK_SIGNAL_FUNC(main_quit), NULL);
  28. /* You should always delete gtk_gl_area widgets before exit or else
  29. GLX contexts are left undeleted, this may cause problems (=core dump)
  30. in some systems.
  31. Destroy method of objects is not automatically called on exit.
  32. You need to manually enable this feature. Do gtk_quit_add_destroy()
  33. for all your top level windows unless you are certain that they get
  34. destroy signal by other means.
  35. */
  36. gtk_quit_add_destroy(1, GTK_OBJECT(window));
  37. /* Create new OpenGL widget. */
  38. GtkVideo *video = new GtkVideo("LOL", 640, 480);
  39. glarea = GTK_WIDGET(video->GetWidget());
  40. /* put glarea into window and show it all */
  41. gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(glarea));
  42. gtk_widget_show(GTK_WIDGET(glarea));
  43. gtk_widget_show(GTK_WIDGET(window));
  44. while (g_main_context_iteration(NULL, FALSE));
  45. if (gtk_gl_area_make_current(GTK_GL_AREA(glarea))) fprintf(stderr, "OK\n");
  46. Game *game = new Game("maps/testmap.tmx");
  47. for (;;)
  48. {
  49. // Do GTK stuff until the user wants to quit
  50. while (g_main_context_iteration(NULL, FALSE));
  51. if (quit)
  52. break;
  53. video->PreRender();
  54. game->SetMouse(0, 0);
  55. game->Render();
  56. video->PostRender(33.33333f);
  57. }
  58. delete game;
  59. delete video;
  60. return 0;
  61. }