source: trunk/src/editor.cpp @ 93

Last change on this file since 93 was 93, checked in by sam, 10 years ago

The GTK loop now works. Sort of.

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