Cmilak344 Temat założony przez niniejszego użytkownika |
[OpenGL] SDL + AntTweakBar - obsługa menu za pomocą myszy » 2017-06-16 14:08:40 Witam Próbuję dodać jakieś menu do projektu w OpenGL. Postanowiłem użyć gotowej biblioteki AntTweakBar. Udało mi się zmieniać wartości w menu za pomocą klawiatury, lecz niestety menu kompletnie nie reaguje na mysz. Proszę o pomoc. Pozdrawiam #include <iostream> #include "SDL_events.h" #include "Display.h" #include "Projection.h" #include "Camera.h" #include "Mouse.h" #include "ObjectManager.h" #include "Line.h" #include "Options.h" #include <AntTweakBar.h>
#pragma comment(lib, "opengl32.lib") #pragma comment(lib, "glu32.lib")
int main( int argc, char ** argv ) { std::string kolor, kolory[ 6 ] = { "Czerwony", "Czarny", "Zielony", "Bialy", "Zolty", "Cyjan" }; Display display( Options::GetInstance().GetScreenWidth(), Options::GetInstance().GetScreenHeight(), "OpenGL Projekt" ); SDL_WarpMouseInWindow( display.Window(), WIDTH / 2, HEIGHT / 2 ); SDL_Event e; TwBar * myBar; bool quit; int i = 0, j = 0, numCubes = 1; Camera camera( glm::vec3( 3.0f, 5.0f, 10.0f ) ); Mouse mouse( Options::GetInstance().GetScreenWidth() / 2, Options::GetInstance().GetScreenHeight() / 2 ); ObjectManager objManager; GLfloat deltaTime = 0.0f; GLfloat lastFrame = 0.0f; float counter = 0.0f; Projection projection( camera.m_zoom, 0.1f, 1000.0f ); TwInit( TW_OPENGL, NULL ); TwWindowSize( Options::GetInstance().GetScreenWidth(), Options::GetInstance().GetScreenHeight() ); myBar = TwNewBar( "Menu drukarki" ); TwDefine( " GLOBAL help='This example shows how to integrate AntTweakBar with SDL and OpenGL.\nPress [Space] to toggle fullscreen.' " ); TwAddVarRW( myBar, "kol1", TW_TYPE_INT8, & i, "label='Kolor filamentu' " ); TwAddVarRW( myBar, "kol2", TW_TYPE_INT8, & j, "label='Kolor oswietlenia' " ); TwAddVarRW( myBar, "NumCubes", TW_TYPE_INT32, & numCubes, " label='Number of cubes' min=1 max=100 keyIncr=c keyDecr=C help='Defines the number of cubes in the scene.' " ); TwAddVarRW( myBar, "Quit", TW_TYPE_BOOL32, & quit, " label='Quit?' true='+' false='-' key='ESC' help='Quit program.' " ); std::queue < glm::vec3 > route; route.push( glm::vec3( 5, 0, 0 ) ); route.push( glm::vec3( 0, 5, 0 ) ); route.push( glm::vec3( 0, 0, 5 ) ); std::queue < glm::vec3 > route2; int x = - 1; route2.push( glm::vec3( 0, 0, 5 ) ); for( int i = 0; i < 4; i++ ) { route2.push( glm::vec3( 1, 0, 0 ) ); route2.push( glm::vec3( 0, 0, x * 4 ) ); x *= - 1; } for( int j = 0; j < 5; j++ ) { route2.push( glm::vec3( 0, 3, 0 ) ); route2.push( glm::vec3( 0, 0, - 4 ) ); route2.push( glm::vec3( - 4, 0, 0 ) ); route2.push( glm::vec3( 0, 0, 4 ) ); route2.push( glm::vec3( 4, 0, 0 ) ); } objManager.SetRoute( route2 ); while( !display.IsClosed() ) { int handled; GLfloat currentFrame = SDL_GetTicks(); deltaTime =( currentFrame - lastFrame ) * 0.001f; lastFrame = currentFrame; SDL_PumpEvents(); if( SDL_PollEvent( & e ) ) { int x, y; SDL_GetMouseState( & x, & y ); const Uint8 * currentKeyStates = SDL_GetKeyboardState( NULL ); if( e.type == SDL_QUIT ) display.Close(); handled = TwEventSDL( & e, SDL_MAJOR_VERSION, SDL_MINOR_VERSION ); if( !handled ) { switch( e.type ) { case SDL_KEYDOWN: if( e.key.keysym.sym == 'p' ) { if( i < 7 ) i++; else i = 0; } if( e.key.keysym.sym == 'o' ) { if( j < 7 ) j++; else j = 0; } break; } } objManager.Events( currentKeyStates, deltaTime ); if( currentKeyStates[ SDL_SCANCODE_UP ] ) { camera.ProcessKeyboard( FORWARD, deltaTime ); } if( currentKeyStates[ SDL_SCANCODE_DOWN ] ) { camera.ProcessKeyboard( BACKWARD, deltaTime ); } if( currentKeyStates[ SDL_SCANCODE_LEFT ] ) { camera.ProcessKeyboard( LEFT, deltaTime ); } if( currentKeyStates[ SDL_SCANCODE_RIGHT ] ) { camera.ProcessKeyboard( RIGHT, deltaTime ); } if( e.type == SDL_MOUSEWHEEL ) { camera.ProcessMouseScroll( e.wheel.y ); } if( e.button.button == SDL_BUTTON_LEFT ) { if( mouse.IsPositionChanged( x, y ) ) { glm::vec2 offset = mouse.UpdatePosition( x, y ); camera.ProcessMouseMovement( offset.x, offset.y ); } } else { mouse.SetPosX( x ); mouse.SetPosY( y ); } } if( currentFrame > 2000 ) { objManager.PrintCubes(); } display.UpdateSize(); display.Clear( 0.85f, 0.98f, 0.98f, 1.0f ); projection.SetFov( camera.m_zoom ); objManager.Draw( camera, projection ); TwRefreshBar( myBar ); TwDraw(); display.Update(); counter += 0.01f; } TwTerminate(); return 0; }
|