#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
#include <Ogre.h> #include <SDL.h> #ifdef _WINDOWS #include <SDL_syswm.h> #endif ... // SDL SDL_Init(SDL_INIT_VIDEO); // SDL_putenv(( char *) "SDL_VIDEO_CENTERED=true" ); // 800x600@16 OpenGL SDL_SetVideoMode(800, 600, 16, SDL_OPENGL); // SDL_WM_SetCaption( "Demo window" , NULL); * This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- // Start the initialization of OGRE by creating a Root object
- Ogre :: Root * root = new Ogre :: Root ();
- // Load the OpenGL visualization plugin from the current folder (or from another location)
- #ifdef _WINDOWS
- root-> loadPlugin ( "./RenderSystem_GL.dll" );
- #else
- root-> loadPlugin ( "./RenderSystem_GL.so" );
- #endif
- // Create the visualizer itself
- Ogre :: RenderSystem * rs = root-> getRenderSystemByName ( "OpenGL Rendering Subsystem" );
- // ... make it current
- root-> setRenderSystem (rs);
- // ... and set up the video mode
- rs-> setConfigOption ( "Full Screen" , "no" );
- rs-> setConfigOption ( "Video Mode" , "800 x 600 16-bit color" );
- // Initialize OGRE, but without automatic window creation
- root-> initialise ( false );
* This source code was highlighted with Source Code Highlighter .
- // Set the parameters for creating the OGRE window.
- // Actually no window is created. We just point OGRE where
- // make it visualize
- Ogre :: NameValuePairList params ;
- #ifdef _WINDOWS
- SDL_SysWMinfo info;
- SDL_VERSION (& info.version);
- SDL_GetWMInfo (& info);
- params [ "externalWindowHandle" ] = Ogre :: StringConverter :: toString (reinterpret_cast <size_t> (info.window));
- params [ "externalGLContent" ] = Ogre :: StringConverter :: toString (reinterpret_cast <size_t> (info.hglrc));
- params [ "externalGLControl" ] = Ogre :: String ( "True" );
- #else
- // Under Linux a little easier
- params [ "currentGLContext" ] = Ogre :: String ( "True" );
- #endif
- // Create a "virtual" window with the selected parameters
- Ogre :: RenderWindow * wnd = root-> createRenderWindow ( "Main window" , 800, 600, false , & params );
- wnd-> setVisible ( true );
* This source code was highlighted with Source Code Highlighter .
- // Here we will add the next event for processing
- SDL_Event evt;
- // Yes, the loop should go on
- bool running = true ;
- // The main rendering cycle
- while (running)
- {
- // Read the system events and input events received since the previous frame
- while (SDL_PollEvent (& evt))
- {
- // If the user closed the window, stop the cycle
- if (evt.type == SDL_QUIT)
- running = false ;
- }
- // Draw one frame
- root-> renderOneFrame ();
- // For some reason, the need to call SDL_GL_SwapBuffers (); There is only in Windows.
- // On Linux, it works fine without it and is buggy if you use it.
- #ifdef _WINDOWS
- SDL_GL_SwapBuffers ();
- #endif
- }
* This source code was highlighted with Source Code Highlighter .
- // Delete the main OGRE object, freeing up all the resources used by the engine
- delete root;
- // Close SDL
- SDL_Quit ();
* This source code was highlighted with Source Code Highlighter .
- // Input.h
- #include <list>
- #include <SDL.h>
- /// Keyboard Event Listener Interface
- class KeyboardListener
- {
- public :
- virtual ~ KeyboardListener () {}
- virtual void onKeyboardEvent ( const SDL_KeyboardEvent & evt) = 0;
- };
- /// Mouse Event Listener Interface
- class MouseListener
- {
- public :
- virtual ~ MouseListener () {}
- virtual void onMouseMotion ( const SDL_MouseMotionEvent & evt) = 0;
- virtual void onMouseBtn ( const SDL_MouseButtonEvent & evt) = 0;
- };
- /// Listener interface for all other types of events
- class EventListener
- {
- public :
- virtual ~ EventListener () {}
- virtual void onEvent ( const SDL_Event & evt) = 0;
- };
* This source code was highlighted with Source Code Highlighter .
- class InputManager
- {
- private :
- typedef std :: list <KeyboardListener *> KeyboardListenersList;
- typedef std :: list <MouseListener *> MouseListenersList;
- typedef std :: list <EventListener *> OtherEventsListenersList;
- private :
- KeyboardListenersList kb_listeners;
- MouseListenersList mouse_listeners;
- OtherEventsListenersList other_listeners;
- public :
- InputManager () {}
- ~ InputManager () {}
- /// Captures and handles events
- void capture ();
- /// Registers the event listener keyboard
- void regKeyboardListener (KeyboardListener * l);
- /// Unregisters the keyboard event listener
- void unregKeyboardListener (KeyboardListener * l);
- /// Registers a mouse event listener.
- void regMouseListener (MouseListener * l);
- /// Unregisters the mouse event listener.
- void unregMouseListener (MouseListener * l);
- /// Registers a general event listener
- void regEventListener (EventListener * l);
- /// Unregisters an event listener of any type
- void unregEventListener (EventListener * l);
- };
* This source code was highlighted with Source Code Highlighter .
- SDL_Event evt;
- while (SDL_PollEvent (& evt))
- {
- switch (evt.type)
- {
- // keyboard event
- case SDL_KEYUP: case SDL_KEYDOWN:
- {
- KeyboardListenersList :: const_iterator kb_it = kb_listeners.begin (), kb_end = kb_listeners.end ();
- for (; kb_it! = kb_end; ++ kb_it)
- (* kb_it) -> onKeyboardEvent (evt.key);
- break ;
- }
- // Mouse event
- case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: case SDL_MOUSEMOTION:
- {
- MouseListenersList :: const_iterator m_it = mouse_listeners.begin (), m_end = mouse_listeners.end ();
- for (; m_it! = m_end; ++ m_it)
- {
- if (evt.type == SDL_MOUSEBUTTONDOWN || evt.type == SDL_MOUSEBUTTONUP)
- (* m_it) -> onMouseBtn (evt.button);
- if (evt.type == SDL_MOUSEMOTION)
- (* m_it) -> onMouseMotion (evt.motion);
- }
- break ;
- }
- // All other events
- default :
- OtherEventsListenersList :: const_iterator other_it = other_listeners.begin (), other_end = other_listeners.end ();
- for (; other_it! = other_end; ++ other_it)
- (* other_it) -> onEvent (evt);
- }
- }
* This source code was highlighted with Source Code Highlighter .
- void InputManager :: regKeyboardListener (KeyboardListener * l)
- {
- if (l && std :: find (kb_listeners.begin (), kb_listeners.end (), l) == kb_listeners.end ())
- kb_listeners.push_back (l);
- }
- void InputManager :: unregKeyboardListener (KeyboardListener * l)
- {
- if (l)
- kb_listeners.remove (l);
- }
* This source code was highlighted with Source Code Highlighter .
- InputManager * imgr = new InputManager ();
- while (! stop)
- {
- imgr-> capture ();
- root-> renderOneFrame ();
- ...
- }
- delete imgr;
Source: https://habr.com/ru/post/86207/
All Articles