Changeset 93


Ignore:
Timestamp:
Aug 11, 2010, 6:18:28 PM (10 years ago)
Author:
sam
Message:

The GTK loop now works. Sort of.

Location:
trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/editor.cpp

    r92 r93  
    5252    glarea = GTK_WIDGET(video->GetWidget());
    5353
    54 
    5554    /* put glarea into window and show it all */
    5655    gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(glarea));
     
    5857    gtk_widget_show(GTK_WIDGET(window));
    5958
    60     while (!quit)
     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 (;;)
    6164    {
     65        // Do GTK stuff until the user wants to quit
    6266        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);
    6375    }
     76
     77    delete game;
     78    delete video;
    6479
    6580    return 0;
  • trunk/src/gtkvideo.cpp

    r91 r93  
    2929    static gint init(GtkWidget *widget)
    3030    {
     31        GtkVideoData *data = (GtkVideoData *)
     32            gtk_object_get_data(GTK_OBJECT(widget), "data");
     33
    3134        /* OpenGL functions can be called only if make_current returns true */
    3235        if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))
     
    3942            glMatrixMode(GL_MODELVIEW);
    4043            glLoadIdentity();
     44
     45    glMatrixMode(GL_PROJECTION);
     46    glLoadIdentity();
     47    glOrtho(0, data->widget->allocation.width,
     48               data->widget->allocation.height, 0, -1, 10);
     49    glMatrixMode(GL_MODELVIEW);
     50    glLoadIdentity();
     51
     52    glEnable(GL_TEXTURE_2D);
     53    glShadeModel(GL_SMOOTH);
     54    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
     55    glClearDepth(1.0);
     56    glEnable(GL_DEPTH_TEST);
     57    glDepthFunc(GL_LEQUAL);
     58    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
     59
     60    glEnable(GL_BLEND);
     61    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     62
    4163        }
    4264        return TRUE;
     
    4567    static gint draw(GtkWidget *widget, GdkEventExpose *event)
    4668    {
    47         if (event->count == 0 && gtk_gl_area_make_current(GTK_GL_AREA(widget)))
     69        GtkVideoData *data = (GtkVideoData *)
     70            gtk_object_get_data(GTK_OBJECT(widget), "data");
     71
     72        if (event->count == 0 && data->drawing == 2
     73             && gtk_gl_area_make_current(GTK_GL_AREA(widget)))
    4874        {
     75#if 0
    4976            /* Draw simple triangle */
    5077            glClearColor(0,0,0,1);
     
    5683            glVertex2f(90,90);
    5784            glEnd();
     85#endif
     86
     87            data->drawing = 0;
    5888
    5989            /* Swap backbuffer to front */
     
    6696    static gint reshape(GtkWidget *widget, GdkEventConfigure *event)
    6797    {
     98        GtkVideoData *data = (GtkVideoData *)
     99            gtk_object_get_data(GTK_OBJECT(widget), "data");
     100
    68101        if (gtk_gl_area_make_current(GTK_GL_AREA(widget)))
    69102        {
    70103            glViewport(0,0, widget->allocation.width,
    71104                            widget->allocation.height);
     105
     106    glMatrixMode(GL_PROJECTION);
     107    glLoadIdentity();
     108    glOrtho(0, data->widget->allocation.width,
     109               data->widget->allocation.height, 0, -1, 10);
     110    glMatrixMode(GL_MODELVIEW);
     111    glLoadIdentity();
     112
     113    glEnable(GL_TEXTURE_2D);
     114    glShadeModel(GL_SMOOTH);
     115    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
     116    glClearDepth(1.0);
     117    glEnable(GL_DEPTH_TEST);
     118    glDepthFunc(GL_LEQUAL);
     119    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
     120
     121    glEnable(GL_BLEND);
     122    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     123
    72124        }
    73125        return TRUE;
     
    75127
    76128    GtkWidget *widget;
     129    int drawing;
    77130};
    78131
     
    103156
    104157    data->widget = gtk_gl_area_new(attrlist);
     158    data->drawing = 0;
     159
     160    gtk_object_set_data(GTK_OBJECT(data->widget), "data", data);
    105161    gtk_widget_set_events(GTK_WIDGET(data->widget),
    106162                          GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
     
    153209}
    154210
    155 void GtkVideo::Clear()
    156 {
     211void GtkVideo::PreRender()
     212{
     213/// XXX: is this right?
     214gtk_gl_area_make_current(GTK_GL_AREA(data->widget));
     215
    157216    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    158217    glLoadIdentity();
    159 }
    160 
    161 void GtkVideo::Refresh(float milliseconds)
    162 {
     218
     219    data->drawing = 1;
     220}
     221
     222void GtkVideo::PostRender(float milliseconds)
     223{
     224    data->drawing = 2;
     225
     226    gtk_widget_draw(GTK_WIDGET(data->widget), NULL);
    163227#if 0
    164228    if (milliseconds > 0.0f)
  • trunk/src/gtkvideo.h

    r91 r93  
    2323    virtual int GetWidth() const;
    2424    virtual int GetHeight() const;
    25     virtual void Clear();
    26     virtual void Refresh(float milliseconds);
     25    virtual void PreRender();
     26    virtual void PostRender(float milliseconds);
    2727    virtual void FullScreen();
    2828
  • trunk/src/sdlvideo.cpp

    r90 r93  
    9090}
    9191
    92 void SdlVideo::Clear()
     92void SdlVideo::PreRender()
    9393{
    9494    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    9696}
    9797
    98 void SdlVideo::Refresh(float milliseconds)
     98void SdlVideo::PostRender(float milliseconds)
    9999{
    100100    if (milliseconds > 0.0f)
  • trunk/src/sdlvideo.h

    r90 r93  
    1919    virtual int GetWidth() const;
    2020    virtual int GetHeight() const;
    21     virtual void Clear();
    22     virtual void Refresh(float milliseconds);
     21    virtual void PreRender();
     22    virtual void PostRender(float milliseconds);
    2323    virtual void FullScreen();
    2424
  • trunk/src/test-map.cpp

    r90 r93  
    1212{
    1313    Video *video = new SdlVideo("Deus Hax", 640, 480);
    14     Game *game = new Game("maps/testmap-library.tmx");
     14    Game *game = new Game("maps/testmap.tmx");
    1515
    1616    for (int done = 0; !done; )
    1717    {
    18         video->Clear();
     18        video->PreRender();
    1919
    2020        /* Test stuff */
     
    2424
    2525        game->Render();
    26         video->Refresh(33.33333f);
     26        video->PostRender(33.33333f);
    2727
    2828        /* This could go in a separate function */
  • trunk/src/tileset.cpp

    r87 r93  
    2727
    2828private:
    29     static int Compare(void const *p1, void const *p2)
    30     {
    31         int const *n1 = (int const *)p1;
    32         int const *n2 = (int const *)p2;
    33 
    34         return n1[2] + 32 * n1[3] - (n2[2] + 32 * n2[3]);
    35     }
    36 
    3729    char *name;
    3830    int ref;
  • trunk/src/video.h

    r90 r93  
    1515    virtual int GetWidth() const = 0;
    1616    virtual int GetHeight() const = 0;
    17     virtual void Clear() = 0;
    18     virtual void Refresh(float milliseconds) = 0;
     17    virtual void PreRender() = 0;
     18    virtual void PostRender(float milliseconds) = 0;
    1919    virtual void FullScreen() = 0;
    2020};
Note: See TracChangeset for help on using the changeset viewer.