Ignore:
Timestamp:
07/18/13 00:50:12 (12 years ago)
Author:
epyon
Message:
  • sdl - full 2.0 version implemented in the same header
  • sdl - nova fully runs on SDL 2.0 *also*
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gl/gl_window.cc

    r170 r171  
    1818        kevent.key.code    = KEY_NONE;
    1919
     20#if NV_SDL_VERSION == NV_SDL_20
     21        uint32 ucode = ke.keysym.sym;
     22#else
     23        uint32 ucode = ke.keysym.unicode;
     24#endif
     25
    2026        // if result is a typable char place it into the structure
    21         if (ke.keysym.unicode >= 32 && ke.keysym.unicode < 128 )
    22         {
    23                 kevent.key.ascii = static_cast<char8>( ke.keysym.unicode );
     27        if (ucode >= 32 && ucode < 128 )
     28        {
     29                kevent.key.ascii = static_cast<char8>( ucode );
    2430        }
    2531
     
    6773        case SDLK_DELETE       : kevent.key.code = KEY_DELETE; break;
    6874        case SDLK_INSERT       : kevent.key.code = KEY_INSERT; break;
    69         case SDLK_KP5          : kevent.key.code = KEY_CENTER; break;
     75        //case SDLK_KP5          : kevent.key.code = KEY_CENTER; break;
    7076        case SDLK_ESCAPE       : kevent.key.code = KEY_ESCAPE; break;
    7177        case SDLK_QUOTE        : kevent.key.code = KEY_QUOTE; break;
     
    9197        mevent.mbutton.button  = MOUSE_NONE;
    9298        mevent.mbutton.pressed = (mb.state != SDL_RELEASED);
    93         mevent.mbutton.x       = mb.x;
    94         mevent.mbutton.y       = mb.y;
     99        mevent.mbutton.x       = static_cast< uint16 >( mb.x );
     100        mevent.mbutton.y       = static_cast< uint16 >( mb.y );
    95101
    96102        switch ( mb.button )
     
    99105        case SDL_BUTTON_MIDDLE    : mevent.mbutton.button = MOUSE_MIDDLE; break;
    100106        case SDL_BUTTON_RIGHT     : mevent.mbutton.button = MOUSE_RIGHT; break;
    101         case SDL_BUTTON_WHEELUP   : mevent.mbutton.button = MOUSE_WHEEL_UP; break;
    102         case SDL_BUTTON_WHEELDOWN : mevent.mbutton.button = MOUSE_WHEEL_DOWN; break;
     107        //case SDL_BUTTON_WHEELUP   : mevent.mbutton.button = MOUSE_WHEEL_UP; break;
     108        //case SDL_BUTTON_WHEELDOWN : mevent.mbutton.button = MOUSE_WHEEL_DOWN; break;
    103109        default : break;
    104110        }
     
    111117        mevent.type          = EV_MOUSE_MOVE;
    112118        mevent.mmove.pressed = (mm.state != SDL_RELEASED);
    113         mevent.mmove.x       = mm.x;
    114         mevent.mmove.y       = mm.y;
     119        mevent.mmove.x       = static_cast< uint16 >( mm.x );
     120        mevent.mmove.y       = static_cast< uint16 >( mm.y );
    115121        return true;
    116122}
     
    125131        case SDL_MOUSEBUTTONDOWN : return sdl_mouse_button_to_io_event( e.button, ioevent );
    126132        case SDL_MOUSEBUTTONUP   : return sdl_mouse_button_to_io_event( e.button, ioevent );
     133/* // SDL 2.0 incompatible
    127134        case SDL_ACTIVEEVENT     :
    128135                ioevent.type = EV_ACTIVE;
     
    134141                ioevent.resize.y = e.resize.h;
    135142                return true;
     143        case SDL_NOEVENT         : return false;
     144        case SDL_VIDEOEXPOSE     : return false;
     145*/
    136146        case SDL_SYSWMEVENT      : ioevent.type = EV_SYSTEM; return true;
    137147        case SDL_QUIT            : ioevent.type = EV_QUIT;   return true;
    138         case SDL_NOEVENT         : return false;
    139         case SDL_VIDEOEXPOSE     : return false;
    140148        case SDL_JOYAXISMOTION   : return false;
    141149        case SDL_JOYBALLMOTION   : return false;
     
    149157
    150158gl_window::gl_window( device* dev, uint16 width, uint16 height )
    151         : m_device( dev ), m_width( width ), m_height( height ), m_title("NV Engine"), m_screen( nullptr )
    152 {
     159        : m_device( dev ), m_width( width ), m_height( height ), m_title("NV Engine"), m_handle( nullptr )
     160{
     161#if NV_SDL_VERSION == NV_SDL_12
    153162        uint32 flags = SDL_OPENGL;
    154        
    155         m_screen = SDL_SetVideoMode( width, height, 32, flags );
    156        
    157         if ( m_screen == 0 )
     163        m_handle = SDL_SetVideoMode( width, height, 32, flags );
     164#elif NV_SDL_VERSION == NV_SDL_20
     165        uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
     166        m_handle = SDL_CreateWindow("Nova Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
     167                width, height, flags );
     168#endif
     169        if ( m_handle == 0 )
    158170        {
    159171                NV_LOG( LOG_CRITICAL, "Video mode set failed: " << SDL_GetError( ) );
     
    161173        }
    162174
    163         nv::load_gl_library();
    164         NV_LOG( LOG_INFO, "OpenGL Vendor       : " << glGetString(GL_VENDOR) );
    165         NV_LOG( LOG_INFO, "OpenGL Renderer     : " << glGetString(GL_RENDERER) );
    166         NV_LOG( LOG_INFO, "OpenGL Version      : " << glGetString(GL_VERSION) );
    167         NV_LOG( LOG_INFO, "OpenGL GLSL Version : " << glGetString(GL_SHADING_LANGUAGE_VERSION) );
    168 
    169         m_context = new gl_context( m_device );
     175        m_context = new gl_context( m_device, m_handle );
    170176        m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) );
    171177}
     
    188194void gl_window::set_title( const string& title )
    189195{
     196#if NV_SDL_VERSION == NV_SDL_20
     197        SDL_SetWindowTitle( static_cast<SDL_Window*>( m_handle ), title.c_str() );
     198#else
    190199        SDL_WM_SetCaption( title.c_str(), title.c_str() );
     200#endif
    191201        m_title = title;
    192202}
     
    206216void gl_window::swap_buffers()
    207217{
     218#if NV_SDL_VERSION == NV_SDL_20
     219        SDL_GL_SwapWindow( static_cast<SDL_Window*>( m_handle ) );
     220#else
    208221        SDL_GL_SwapBuffers();
     222#endif
    209223}
    210224
     
    212226{
    213227        delete m_context;
    214 }
     228#if NV_SDL_VERSION == NV_SDL_20
     229        SDL_DestroyWindow( static_cast<SDL_Window*>( m_handle ) );
     230#endif
     231}
Note: See TracChangeset for help on using the changeset viewer.