source: trunk/src/gtk/editor.cpp @ 106

Last change on this file since 106 was 106, checked in by sam, 11 years ago

Make the Game class an asset like the others.

  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1//
2// Deus Hax (working title)
3// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
4//
5
6#if defined HAVE_CONFIG_H
7#   include "config.h"
8#endif
9
10#include <cstdio>
11#include <cmath>
12
13#include <gtk/gtk.h>
14#include <gtkgl/gtkglarea.h>
15
16#include "gtkvideo.h"
17#include "ticker.h"
18#include "game.h"
19
20volatile int quit = 0;
21
22static gint main_quit(GtkWidget *widget, GdkEventExpose *event)
23{
24    quit = 1;
25    return FALSE;
26}
27
28int main(int argc, char **argv)
29{
30    GtkWidget *window, *glarea;
31
32    /* initialize gtk */
33    gtk_init(&argc, &argv);
34
35    /* Create new top level window. */
36    window = gtk_window_new( GTK_WINDOW_TOPLEVEL);
37    gtk_window_set_title(GTK_WINDOW(window), "Simple");
38    gtk_container_set_border_width(GTK_CONTAINER(window), 5);
39
40    /* Quit form main if got delete event */
41    gtk_signal_connect(GTK_OBJECT(window), "delete_event",
42                       GTK_SIGNAL_FUNC(main_quit), NULL);
43
44
45    /* You should always delete gtk_gl_area widgets before exit or else
46       GLX contexts are left undeleted, this may cause problems (=core dump)
47       in some systems.
48       Destroy method of objects is not automatically called on exit.
49       You need to manually enable this feature. Do gtk_quit_add_destroy()
50       for all your top level windows unless you are certain that they get
51       destroy signal by other means.
52    */
53    gtk_quit_add_destroy(1, GTK_OBJECT(window));
54
55
56    /* Create new OpenGL widget. */
57    GtkVideo *video = new GtkVideo("LOL", 640, 480);
58    glarea = GTK_WIDGET(video->GetWidget());
59
60    /* put glarea into window and show it all */
61    gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(glarea));
62    gtk_widget_show(GTK_WIDGET(glarea));
63    gtk_widget_show(GTK_WIDGET(window));
64
65    Game *game = new Game("maps/testmap.tmx");
66
67    for (;;)
68    {
69        // Do GTK stuff until the user wants to quit
70        while (g_main_context_iteration(NULL, FALSE));
71
72        if (quit)
73            break;
74
75        game->SetMouse(0, 0);
76        Ticker::TickGame(33.33333f);
77
78        video->PreRender();
79        Ticker::TickRender(33.33333f);
80        video->PostRender(33.33333f);
81    }
82
83    delete video;
84
85    return 0;
86}
Note: See TracBrowser for help on using the repository browser.