demotool/window.cc

57 lines
1.2 KiB
C++
Raw Normal View History

#include "externals.hh"
#include "window.hh"
#include "imgui_impl_sdl.h"
T_Window::T_Window( )
{
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER , 1 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE , 24 );
SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE , 8 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION , 2 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION , 2 );
SDL_DisplayMode current;
SDL_GetCurrentDisplayMode( 0 , &current );
window = SDL_CreateWindow( "DEMO",
SDL_WINDOWPOS_CENTERED , SDL_WINDOWPOS_CENTERED ,
1280 , 720 ,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE );
gl = SDL_GL_CreateContext( window );
glewInit( );
if ( !GLEW_VERSION_4_5 ) {
fprintf( stderr , "OpenGL 4.5 required\n" );
exit( 1 );
}
ImGui_ImplSdl_Init( window );
}
T_Window::~T_Window( )
{
ImGui_ImplSdl_Shutdown( );
SDL_GL_DeleteContext( gl );
SDL_DestroyWindow( window );
SDL_Quit( );
}
void T_Window::startFrame(
2017-11-03 09:08:19 +01:00
const bool capture ,
ImVec2 const& mouseInitial ) const
{
ImGui_ImplSdl_NewFrame( window , capture , mouseInitial );
}
void T_Window::warpMouse(
2017-11-03 09:08:19 +01:00
ImVec2 const& pos ) const
{
SDL_WarpMouseInWindow( window , pos.x , pos.y );
}
void T_Window::swap( ) const
{
SDL_GL_SwapWindow( window );
}