[38] | 1 | // Copyright (C) 2012-2013 Kornel Kisielewicz
|
---|
| 2 | // This file is part of NV Libraries.
|
---|
| 3 | // For conditions of distribution and use, see copyright notice in nv.hh
|
---|
| 4 |
|
---|
| 5 | #include "nv/gl/gl_window.hh"
|
---|
| 6 |
|
---|
| 7 | #include "nv/logging.hh"
|
---|
| 8 | #include "nv/lib/gl.hh"
|
---|
| 9 | #include "nv/lib/sdl12.hh"
|
---|
| 10 |
|
---|
| 11 | using namespace nv;
|
---|
| 12 |
|
---|
| 13 | gl_window::gl_window( uint16 width, uint16 height )
|
---|
| 14 | : m_width( width ), m_height( height ), m_title("NV Engine"), m_screen( nullptr )
|
---|
| 15 | {
|
---|
| 16 | int flags = SDL_OPENGL;
|
---|
| 17 |
|
---|
| 18 | m_screen = SDL_SetVideoMode( width, height, 32, flags );
|
---|
| 19 |
|
---|
| 20 | if ( m_screen == 0 )
|
---|
| 21 | {
|
---|
| 22 | NV_LOG( LOG_CRITICAL, "Video mode set failed: " << SDL_GetError( ) );
|
---|
| 23 | return; // TODO: Error report
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | nv::load_gl_library();
|
---|
| 27 | NV_LOG( LOG_INFO, "OpenGL Vendor : " << glGetString(GL_VENDOR) );
|
---|
| 28 | NV_LOG( LOG_INFO, "OpenGL Renderer : " << glGetString(GL_RENDERER) );
|
---|
| 29 | NV_LOG( LOG_INFO, "OpenGL Version : " << glGetString(GL_VERSION) );
|
---|
| 30 | NV_LOG( LOG_INFO, "OpenGL GLSL Version : " << glGetString(GL_SHADING_LANGUAGE_VERSION) );
|
---|
[44] | 31 |
|
---|
| 32 | m_context = new gl_context();
|
---|
| 33 | m_context->set_viewport( nv::ivec4( 0, 0, m_width, m_height ) );
|
---|
[38] | 34 | }
|
---|
| 35 |
|
---|
| 36 | uint16 gl_window::get_width() const
|
---|
| 37 | {
|
---|
| 38 | return m_width;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | uint16 gl_window::get_height() const
|
---|
| 42 | {
|
---|
| 43 | return m_height;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | string gl_window::get_title() const
|
---|
| 47 | {
|
---|
| 48 | return m_title;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | void gl_window::set_title( const string& title )
|
---|
| 52 | {
|
---|
| 53 | SDL_WM_SetCaption( title.c_str(), title.c_str() );
|
---|
| 54 | m_title = title;
|
---|
| 55 | }
|
---|
[44] | 56 |
|
---|
| 57 | gl_window::~gl_window()
|
---|
| 58 | {
|
---|
| 59 | delete m_context;
|
---|
| 60 | }
|
---|