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

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

Slightly improve the documentation in a few files, add the missing
joystick class, and put a header in each source file.

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