Example #1
0
//---------------CPU Functions---------------//
void initTweakMenu()
{
	if(!TwInit(TW_OPENGL, NULL))
	{
		fprintf(stderr, "AntTwekBar fails to initialize! Info: %s\n", TwGetLastError());
		exit(0);
	}

	bar = TwNewBar("Scene Parameters");
	//Camera attributes
	TwAddVarRW(bar, "View Direction", TW_TYPE_DIR3F, &viewdir, "group = 'Camera Attribute'");
	TwAddVarRW(bar, "Move Speed", TW_TYPE_UINT8, &movespeed, " min = 0 max = 25 step = 1 group = 'Camera Attribute' ");

	TwAddVarRW(bar, "Position x", TW_TYPE_FLOAT, &camera.getPosition().x,
		" min = -100 max = 100 step = 0.01 group = 'Camera Attribute' ");
	TwAddVarRW(bar, "Position y", TW_TYPE_FLOAT, &camera.getPosition().y,
		" min = -100 max = 100 step = 0.01 group = 'Camera Attribute' ");
	TwAddVarRW(bar, "Position z", TW_TYPE_FLOAT, &camera.getPosition().z,
		" min = -100 max = 100 step = 0.01 group = 'Camera Attribute' ");
	
	TwAddVarRW(bar, "Aperture", TW_TYPE_FLOAT, &aperture,
		" min = 0.001 max = 10 step = 0.001 group = 'Camera Attribute' ");
	TwAddVarRW(bar, "Focal", TW_TYPE_FLOAT, &focal,
		" min = 0.0001 max = 0.9999 step = 0.0001 group = 'Camera Attribute' ");
	/*//Light attributes
	TwAddVarRW(bar, "position x", TW_TYPE_FLOAT, &light.getPosition().x,
		" min = -100 max = 100 step = 0.01 group = 'Light Attribute' ");
	TwAddVarRW(bar, "position y", TW_TYPE_FLOAT, &light.getPosition().y,
		" min = -100 max = 100 step = 0.01 group = 'Light Attribute' ");
	TwAddVarRW(bar, "position z", TW_TYPE_FLOAT, &light.getPosition().z,
		" min = -100 max = 100 step = 0.01 group = 'Light Attribute' ");
	//Light color
	TwAddVarRW(bar, "Color", TW_TYPE_COLOR3F, &light.getColor(), "group = 'Light Attribute'");//*/
}
Example #2
0
bool Game::Initialize()
{
	DX11Application::Initialize();
	ShaderManager::GetInstance()->Initialize(mDevice, mDeviceContext);
	Camera::GetInstance()->Init(AglVector3(0, 0.0f, -2.25f), AglVector3(0, 0.0f, 0), AglVector3(0, 1, 0), mScreenWidth, mScreenHeight);
	TextureManager::GetInstance()->Init(mDevice, mDeviceContext);
	RasterManager::getInstance()->initialize(mDevice, mDeviceContext);

	ParticleStates::Init(mDevice, mDeviceContext);
	
	AGLLoader::GetInstance()->Init(mDevice, mDeviceContext);

	// Initialize AntTweakBar
    if (!TwInit(TW_DIRECT3D11, mDevice))
    {
        MessageBoxA(mWindowHandle, TwGetLastError(), "AntTweakBar initialization failed", MB_OK|MB_ICONERROR);
        Cleanup();
        return 0;
    }
	SceneDialog::GetInstance();


	m_cameraController = new CameraController(mWindowHandle);

	SPHEREMESH = new SphereMesh(mDevice, mDeviceContext);
	BOXMESH = new BoxMesh(mDevice, mDeviceContext);

	return true;
}
void ofxTweakbars::init() {
	visible = true;
	is_initialized = true;
	if (!TwInit(TW_OPENGL, NULL)) {
		throw TwGetLastError();
	}
	TwWindowSize(ofGetWidth(), ofGetHeight());
	setEventHandlers();

}
void CDebugHelperImplementation::Render()
{
	// TODO: pintar el AntTweakBar
	
	int status = TwDraw();
	if (!status)
	{
		const char* error = TwGetLastError();
		Log(error);
	}
	
}
Example #5
0
int createTweakBar(context_t *ctx, int scene) {
  const char me[]="createTweakBar";
  char buff[128];
  int EE;  /* we have an error */

  EE = 0;

  // NOTE: these are nice to have
  twBumpMappingModes=TwDefineEnum("BumpMappingModes", twBumpMappingModesEV, 3);
  twFilteringModes=TwDefineEnum("FilteringModes", twFilteringModesEV, 4);
  twObjects=TwDefineEnum("Objects", twObjectsEV, 10);
  twCubeMaps=TwDefineEnum("CubeMap", twCubeMapsEV, 3);
  twShaders=TwDefineEnum("Shader", twShadersEV, 3);
  
  /* Create a tweak bar for interactive parameter adjustment */
  if (!EE) EE |= !(ctx->tbar = TwNewBar(TBAR_NAME));
  /* documentation for the TwDefine parameter strings here:
     http://www.antisphere.com/Wiki/tools:anttweakbar:twbarparamsyntax */
  /* add a message to be seen in the "help" window */
  if (!EE) EE |= !TwDefine(" GLOBAL help='This description of Project 2 "
                           "has not been changed by anyone but students "
                           "are encouraged to write something descriptive "
                           "here.' ");
  /* change location where bar will be drawn, over to the right some
     to expose more of the left edge of window.  Note that we are
     exploiting the automatic compile-time concatentation of strings
     in C, which connects TBAR_NAME with the rest of the string to
     make one contiguous string */
  sprintf(buff, TBAR_NAME " position='%d %d' ",
          ctx->winSizeX - ctx->tbarSizeX - ctx->tbarMargin,
          ctx->tbarMargin);
  if (!EE) EE |= !TwDefine(buff);
  /* adjust other aspects of the bar */
  sprintf(buff, TBAR_NAME " color='0 0 0' alpha=10 size='%d %d' ",
          ctx->tbarSizeX, ctx->tbarSizeY);
  if (!EE) EE |= !TwDefine(buff);
  
  // NOTE: we broke this section out for easy update of tweak bar vars per-scene
  if (!EE) EE |= updateTweakBarVars(scene);

  /* see also:
     http://www.antisphere.com/Wiki/tools:anttweakbar:twtype
     http://www.antisphere.com/Wiki/tools:anttweakbar:twdefineenum
  */

  if (EE) {
    spotErrorAdd("%s: AntTweakBar initialization failed:\n\t%s", me, TwGetLastError());
    return 1;
  }
  return 0;
}
Example #6
0
bool Tweaker::Init(int window_width, int window_height)
{
	if(s_isInit) {
		return true;
	}
	s_gameDataFS = new FileSystem::FileSourceFS(FileSystem::GetDataDir(), true);
    
    if(s_doNotUseLib) {
        s_isInit = true;
        return true;
    }
    
	int success;
	if(Graphics::Hardware::context_CoreProfile) {
		TWEAKER(success = TwInit(TW_OPENGL_CORE, nullptr));
	} else {
		TWEAKER(success = TwInit(TW_OPENGL, nullptr));
	}
	assert(success);
	if(success) {
		s_isInit = true;
		TwWindowSize(window_width, window_height);
		return true; 
	} else {
#ifndef NDEBUG
		std::ostringstream ss;
		const char* last_error = TwGetLastError();
		if(last_error) {
			ss << "Could not initialize AntTweakBar: " << last_error;
		} else {
			ss << "Could not initialize AntTweakBar";
		}
		throw new std::runtime_error(ss.str().c_str());
#endif
		return false;
	}
}
Example #7
0
int main (int argc, const char * argv[])
{

	TwBar *myBar;
	float bgColor[] = { 0.0f, 0.0f, 0.0f, 0.1f };

	glm::mat4 mat;
	float axis[] = { 0.7f, 0.7f, 0.7f }; // initial model rotation
    float angle = 0.8f;

	double FT  = 0;
	double FPS = 0;

	double starting = 0.0;
	double ending   = 0.0;
	int rate = 0;
	int fr = 0;

	zNear = 0.1f;
	zFar  = 100.0f;
	FOV   = 45.0f; 

	// Current time
	double time = 0;

	 // initialise GLFW
    int running = GL_TRUE;

    if (!glfwInit()) {
        exit(EXIT_FAILURE);
    }
    
    //only for OpenGL 2.1
#ifdef USE_OPENGL21
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 2);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1);
#endif
    
    //Only for OpenGL 3.2
#ifdef USE_OPENGL32
    glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
    glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, 1);
#endif

	GLFWvidmode mode;
    glfwGetDesktopMode(&mode);
    if( !glfwOpenWindow(windowWidth, windowHeight, mode.RedBits, mode.GreenBits, mode.BlueBits, 0, 32, 0, GLFW_WINDOW /* or GLFW_FULLSCREEN */) )
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    glfwEnable(GLFW_MOUSE_CURSOR);
    glfwEnable(GLFW_KEY_REPEAT);
    // Ensure we can capture the escape key being pressed below
	glfwEnable( GLFW_STICKY_KEYS );
	glfwSetMousePos(windowWidth/2, windowHeight/2);
    glfwSetWindowTitle("Chapter-11");

	// Initialize AntTweakBar
    if ( !TwInit(TW_OPENGL_CORE, NULL))
	{
		fprintf(stderr,"AntweakBar initialiazation failed: %s\n",TwGetLastError());
		exit(1);
	}

    // Create a tweak bar
	myBar = TwNewBar("TweakBar");

    //init GLEW and basic OpenGL information
    // VERY IMPORTANT OTHERWISE GLEW CANNOT HANDLE GL3
#ifdef USE_OPENGL32
    glewExperimental = true; 
#endif
    glewInit();
    std::cout<<"\nUsing GLEW "<<glewGetString(GLEW_VERSION)<<std::endl;
    if (GLEW_VERSION_2_1)
    {
        std::cout<<"\nYay! OpenGL 2.1 is supported and GLSL 1.2!\n"<<std::endl;
    }
    if (GLEW_VERSION_3_2)
    {
        std::cout<<"Yay! OpenGL 3.2 is supported and GLSL 1.5!\n"<<std::endl;
    }
    
    /*
     This extension defines an interface that allows various types of data
     (especially vertex array data) to be cached in high-performance
     graphics memory on the server, thereby increasing the rate of data
     transfers.
     Chunks of data are encapsulated within "buffer objects", which
     conceptually are nothing more than arrays of bytes, just like any
     chunk of memory.  An API is provided whereby applications can read
     from or write to buffers, either via the GL itself (glBufferData,
     glBufferSubData, glGetBufferSubData) or via a pointer to the memory.
     */
	if (glewIsSupported("GL_ARB_vertex_buffer_object"))
		std::cout<<"ARB VBO's are supported"<<std::endl;
    else if (glewIsSupported("GL_APPLE_vertex_buffer_object"))
		std::cout<<"APPLE VBO's are supported"<<std::endl;
	else
		std::cout<<"VBO's are not supported,program will not run!!!"<<std::endl; 
    
    /* 
     This extension introduces named vertex array objects which encapsulate
     vertex array state on the client side. The main purpose of these 
     objects is to keep pointers to static vertex data and provide a name 
     for different sets of static vertex data.  
     By extending vertex array range functionality this extension allows multiple
     vertex array ranges to exist at one time, including their complete sets of
     state, in manner analogous to texture objects. 
     GenVertexArraysAPPLE creates a list of n number of vertex array object
     names.  After creating a name, BindVertexArrayAPPLE associates the name with
     a vertex array object and selects this vertex array and its associated
     state as current.  To get back to the default vertex array and its
     associated state the client should bind to vertex array named 0.
     */
    
	if (glewIsSupported("GL_ARB_vertex_array_object"))
        std::cout<<"ARB VAO's are supported\n"<<std::endl;
    else if (glewIsSupported("GL_APPLE_vertex_array_object"))//this is the name of the extension for GL2.1 in MacOSX
		std::cout<<"APPLE VAO's are supported\n"<<std::endl;
	else
		std::cout<<"VAO's are not supported, program will not run!!!\n"<<std::endl;
    
    
    std::cout<<"Vendor: "<<glGetString (GL_VENDOR)<<std::endl;
    std::cout<<"Renderer: "<<glGetString (GL_RENDERER)<<std::endl;
    std::cout<<"Version: "<<glGetString (GL_VERSION)<<std::endl;
   
	std::ostringstream stream1,stream2;

	stream1 << glGetString(GL_VENDOR);
	stream2 << glGetString(GL_RENDERER);

	std::string vendor ="Title : Chapter-11   Vendor : " + stream1.str() + "   Renderer : " +stream2.str();

	const char *tit = vendor.c_str();
	glfwSetWindowTitle(tit);
    // Set GLFW event callbacks
    // - Redirect window size changes to the callback function WindowSizeCB
    glfwSetWindowSizeCallback(WindowSizeCB);
    
    // - Directly redirect GLFW mouse button events to AntTweakBar
    glfwSetMouseButtonCallback((GLFWmousebuttonfun)TwEventMouseButtonGLFW);
    
    // - Directly redirect GLFW mouse position events to AntTweakBar
    glfwSetMousePosCallback((GLFWmouseposfun)TwEventMousePosGLFW);
    
    // - Directly redirect GLFW mouse wheel events to AntTweakBar
    glfwSetMouseWheelCallback((GLFWmousewheelfun)TwEventMouseWheelGLFW);
    
    // - Directly redirect GLFW key events to AntTweakBar
    glfwSetKeyCallback((GLFWkeyfun)TwEventKeyGLFW);
    
    // - Directly redirect GLFW char events to AntTweakBar
    glfwSetCharCallback((GLFWcharfun)TwEventCharGLFW);


	TwDefine("TweakBar label='Main TweakBar' alpha=0 help='Use this bar to control the objects of the scene.' ");

	// Add 'wire' to 'myBar': it is a modifable variable of type TW_TYPE_BOOL32 (32 bits boolean). Its key shortcut is [w].
    TwAddVarRW(myBar, "wireframe mode", TW_TYPE_BOOL32, &wireFrame," label='Wireframe mode' key=w help='Toggle wireframe display mode.' ");

	// Add 'bgColor' to 'myBar': it is a modifable variable of type TW_TYPE_COLOR3F (3 floats color)
    TwAddVarRW(myBar, "bgColor", TW_TYPE_COLOR3F, &bgColor, " label='Background color' ");

	// Add 'Rotation' to 'myBar': this is a variable of type TW_TYPE_QUAT4F which defines the scene's orientation
    TwAddVarRW(myBar, "SceneRotation", TW_TYPE_QUAT4F, &Rotation," label='Scene rotation' opened=true help='Change the scenes orientation.' ");

	TwAddButton(myBar, "Reset", ResetView,NULL," label='Reset View' ");

	TwAddVarRW(myBar, "Near Clip Plane", TW_TYPE_FLOAT, &zNear,"min=0.5 max=100 step=0.5 label='Near Clip' group='Projection Properties'");

	TwAddVarRW(myBar, "Far Clip Plane", TW_TYPE_FLOAT, &zFar," min=0.5 max=1000 step=0.5 label='Far Clip' group='Projection Properties'");

	TwAddVarRW(myBar, "Field of View", TW_TYPE_FLOAT, &FOV," label='FoV' readonly=true group='Projection Properties'");

	TwAddVarRW(myBar, "MS per 1 Frame" , TW_TYPE_DOUBLE, &FPS, "label='MS per 1 Frame' readonly=true group='Frame Rate'");

	TwAddVarRW(myBar, "Frames Per Second" , TW_TYPE_INT32, &rate, "label='FPS' readonly=true group='Frame Rate'");

	TwAddVarRW(myBar, "vSYNC" , TW_TYPE_BOOL8, &SYNC, "label='vSync' readonly=true group='Frame Rate'");
	
	 // Enable depth test
	glEnable(GL_DEPTH_TEST);
	// Accept fragment if it closer to the camera than the former one
	glDepthFunc(GL_LESS);

	initPlane(); //initialize Plane

	init3Dmodel(); // initialize 3D model

	create_Bump_bar();

	GLfloat rat = 0.001f;

	if(SYNC == false)
	{
		rat = 0.001f;
	}
	else
	{
		rat = 0.01f;
	}

	// Initialize time
    time = glfwGetTime();
	double currentTime;
	float lastTime = 0.0f;

	int Frames = 0;
	double LT = glfwGetTime();
	starting = glfwGetTime();

	setVSync(SYNC);

	while (running) {

		glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
        glClearColor( bgColor[0], bgColor[1], bgColor[2], bgColor[3]); //black color

		FOV = initialFoV - 5 * glfwGetMouseWheel();

		if(camera == true)
		{
			glfwGetMousePos(&xpos,&ypos);
			glfwSetMousePos(windowWidth/2, windowHeight/2);
		
			horizAngle  += mouseSpeedo * float(windowWidth/2 - xpos );
			verticAngle += mouseSpeedo * float( windowHeight/2 - ypos );
		}

		glm::vec3 direction(cos(verticAngle) * sin(horizAngle),sin(verticAngle),cos(verticAngle) * cos(horizAngle));

		glm::vec3 right = glm::vec3(sin(horizAngle - 3.14f/2.0f),0,cos(horizAngle - 3.14f/2.0f));

		glm::vec3 up = glm::cross( right, direction );

		currentTime = glfwGetTime();
		float dTime = float(currentTime - lastTime);
		lastTime = (float)currentTime;

		// Move forward
		if (glfwGetKey( GLFW_KEY_UP ) == GLFW_PRESS){
			pos += direction * dTime* speedo;
		}
		// Move backward
		if (glfwGetKey( GLFW_KEY_DOWN ) == GLFW_PRESS){
			pos -= direction * dTime * speedo;
		}
		// Strafe right
		if (glfwGetKey( GLFW_KEY_RIGHT ) == GLFW_PRESS){
			pos += right * dTime * speedo;
		}
		//Strafe left
		if (glfwGetKey( GLFW_KEY_LEFT ) == GLFW_PRESS){
				pos -= right * dTime * speedo;
		}

		if (glfwGetKey(GLFW_KEY_SPACE) == GLFW_PRESS){

			if(camera == false)
			{
				camera=true;
				glfwSetMousePos(windowWidth/2, windowHeight/2);
				glfwGetMousePos(&xpos,&ypos);
			}
			else
			{
				camera=false;
				glfwSetMousePos(windowWidth/2, windowHeight/2);
				glfwGetMousePos(&xpos,&ypos);
			}
		}

		mat = ConvertQuaternionToMatrix(Rotation, mat);

		glm::mat4 cube;

		glm::mat4 translateMat = glm::mat4();
		translateMat = glm::translate(translateMat,glm::vec3(5.0,3.0,4.0));

		cube  = mat * translateMat;

		displayPlane(mat,pos,direction,up);

		display3Dmodel(cube,mat,pos,direction,up);

		// drawing the AntWeakBar
		if (wireFrame)
		{
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
			TwDraw();
		}
		else
		{
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
			TwDraw();
		}
		fr++;
		ending = glfwGetTime();

		if(ending - starting >= 1)
		{
			rate = fr;
			fr = 0;
			starting = glfwGetTime();
		}

		double CT = glfwGetTime();
		Frames++;
		if(CT -LT >= 1.0)
		{
			FPS = 1000.0 / (double)Frames;
			Frames = 0;
			LT += 1.0f;
		}

        glfwSwapBuffers();
        //check if ESC was pressed
        running=!glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
    }

	//close OpenGL window and  terminate AntTweakBar and GLFW
    TwTerminate();
    glfwTerminate();
    
    
    exit(EXIT_SUCCESS);
    
}
int main()
{
    const SDL_VideoInfo* video = NULL;
    int width  = 480, height = 480;
    int bpp, flags;
    int quit = 0;

    // Initialize SDL, then get the current video mode and use it to create a SDL window.
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError());
        SDL_Quit();
        exit(1);
    }
    video = SDL_GetVideoInfo();
    if (!video) 
    {
        fprintf(stderr, "Video query failed: %s\n", SDL_GetError());
        SDL_Quit();
        exit(1);
    }
    // Request GL context to be OpenGL 3.2 Core Profile
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
    // Other GL attributes
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
    //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    bpp = video->vfmt->BitsPerPixel;
    flags = SDL_OPENGL | SDL_HWSURFACE;
    if (!SDL_SetVideoMode(width, height, bpp, flags))
    {
        fprintf(stderr, "Video mode set failed: %s\n", SDL_GetError());
        SDL_Quit();
        exit(1);
    }
    SDL_WM_SetCaption("AntTweakBar example using OpenGL Core Profile and SDL", "AntTweakBar+GLCore+SDL");

    // Enable SDL unicode and key-repeat
    SDL_EnableUNICODE(1);
    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);

    // Load some OpenGL core functions
    if (!LoadGLCoreFunctions())
    {
        fprintf(stderr, "OpenGL 3.2 not supported.\n");
        SDL_Quit();
        exit(1);
    }

    // Initialize AntTweakBar
    if (!TwInit(TW_OPENGL_CORE, NULL)) {
        fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError());
        SDL_Quit();
        exit(1);
    }
    // Tell the window size to AntTweakBar
    TwWindowSize(width, height);
    // Create a tweak bar
    CreateTweakBar();

    // Set OpenGL viewport
    glViewport(0, 0, width, height);

    // Prepare GL shaders and programs for drawing
    InitRender();

    // Main loop:
    // - Draw scene
    // - Process events
    while (!quit)
    {
        SDL_Event event;
        int handled;
        GLenum error;

        // Clear screen
        glClearColor(0.5f, 0.75f, 0.8f, 1);
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

        // Update angle and draw geometry
        angle = (float)SDL_GetTicks()/25.0f * (FLOAT_PI/180.0f);
        quat[0] = quat[1] = 0;
        quat[2] = (float)sin(angle/2.0f);
        quat[3] = (float)cos(angle/2.0f);
        Render();

        // Draw tweak bars
        TwDraw();

        // Present frame buffer
        SDL_GL_SwapBuffers();

        // Process incoming events
        while (SDL_PollEvent(&event)) 
        {
            // Send event to AntTweakBar
            handled = TwEventSDL(&event, SDL_MAJOR_VERSION, SDL_MINOR_VERSION);

            // If event has not been handled by AntTweakBar, process it
            if (!handled)
            {
                switch (event.type)
                {
                case SDL_QUIT:  // Window is closed
                    quit = 1;
                    break;

                case SDL_VIDEORESIZE:   // Window size has changed
                    // Resize SDL video mode
                    width = event.resize.w;
                    height = event.resize.h;
                    if (!SDL_SetVideoMode(width, height, bpp, flags))
                        fprintf(stderr, "WARNING: Video mode set failed: %s\n", SDL_GetError());

                    // Resize OpenGL viewport
                    glViewport(0, 0, width, height);
                    
                    // Restore OpenGL states
                    InitRender();
                    
                    // TwWindowSize has been called by TwEventSDL, 
                    // so it is not necessary to call it again here.

                    break;
                }
            }
        }

        while ((error = glGetError()) != GL_NO_ERROR) 
            fprintf(stderr, "GL error detected: 0x%04X\n", error);

    } // End of main loop

    // Terminate AntTweakBar
    TwTerminate();

    // Delete GL shaders and buffer
    UninitRender();

    // Terminate SDL
    SDL_Quit();

    return 0;
}  
bool AngelCore::AngelSubSystem::SubSystemManager::StartUpEngineSubSystem()
{

	this->m_fileSystemManager = std::make_shared<FileSystemManager>();
	if (this->m_fileSystemManager)
	{
		/*auto func = std::bind(&FileSystemManager::StartUp, this, std::placeholders::_1);
		auto f = std::async(std::launch::async, &FileSystemManager::StartUp, &m_fileSystemManager);*/
		if (!this->m_fileSystemManager->StartUp())
		{
			AngelCore::AngelSubSystem::AngelLog::WriteErrorMessage("Failed Start Up FileSystemManager.");
			return false;
		}

		AngelCore::AngelSubSystem::AngelLog::WriteLogMessage("File System Manager Started.");
	}

	this->m_renderManager = new RenderManager();

	if (this->m_renderManager)
	{
		if (!this->m_renderManager->StartUp())
		{
			AngelCore::AngelSubSystem::AngelLog::WriteErrorMessage("Failed Start Up RenderManager.");
			return false;
		}
		AngelCore::AngelSubSystem::AngelLog::WriteLogMessage("Render Manager Started.");
	}

	if (!AngelGUISystem::AngelGUI::StartUp
		(AngelCore::AngelSubSystemResources::WindowProperties::GetHWND()
			, AngelCore::AngelSubSystemResources::GraphicDeviceResources::Device.Get(),
			AngelCore::AngelSubSystemResources::GraphicDeviceResources::DeviceContext.Get(),
			AngelCore::AngelSubSystemResources::GraphicDeviceResources::SwapChain.Get()))
	{
		AngelCore::AngelSubSystem::AngelLog::WriteErrorMessage("Failed Start Up AngelGUISystem.");
		return false;
	}

	AngelCore::AngelSubSystem::AngelLog::WriteLogMessage("AngelGUISystem Started.");

	if (!TwInit(TW_DIRECT3D11, AngelCore::AngelSubSystemResources::GraphicDeviceResources::Device.Get()))
	{
		MessageBoxA(NULL, TwGetLastError(), "AntTweakBar initialization failed", MB_OK | MB_ICONERROR);
	}


	this->m_physicManager = std::make_shared<PhysicManager>();
	if (this->m_physicManager)
	{
		if (!this->m_physicManager->StartUp())
		{
			AngelCore::AngelSubSystem::AngelLog::WriteErrorMessage("Failed Start Up PhysicManager.");
			return false;
		}
		AngelCore::AngelSubSystem::AngelLog::WriteLogMessage("Physic Manager Started.");
	}

	this->m_actorFactory = new AngelCore::AngelWorldSystem::ActorFactory();
	if (this->m_actorFactory)
	{
		if (!this->m_actorFactory->StartUp())
		{
			AngelCore::AngelSubSystem::AngelLog::WriteErrorMessage("Failed Start Up ActorFactory.");
			return false;
		}
		AngelCore::AngelSubSystem::AngelLog::WriteLogMessage("ActorFactory Started.");
	}

	this->m_inputManager = std::make_shared<InputManager>();
	if (this->m_inputManager)
	{
		if (!this->m_inputManager->StartUp())
		{
			AngelCore::AngelSubSystem::AngelLog::WriteErrorMessage("Failed Start Up InputManager.");
			return false;
		}
		AngelCore::AngelSubSystem::AngelLog::WriteLogMessage("InputManager Started.");

		AngelSubSystem::inputManager = this->m_inputManager.get();
	}

	this->m_timeManager = new TimeManager();
	if (this->m_timeManager)
	{
		if (!this->m_timeManager->StartUp())
		{
			AngelCore::AngelSubSystem::AngelLog::WriteErrorMessage("Failed Start Up TimeManager.");
			return false;
		}
		this->m_timeManager->SetFixedTimeStep(false);
		AngelCore::AngelSubSystem::AngelLog::WriteLogMessage("TimeManager Started.");
	}

	this->m_levelManager = new LevelManager();
	if (this->m_levelManager)
	{
		if (!this->m_levelManager->StartUp())
		{
			AngelCore::AngelSubSystem::AngelLog::WriteErrorMessage("Failed Start Up LevelManager.");
			return false;
		}
		AngelCore::AngelSubSystem::AngelLog::WriteLogMessage("LevelManager Started.");
	}

	this->m_worldManager = new WorldManager();
	if (this->m_worldManager)
	{
		if (!this->m_worldManager->StartUp())
		{
			AngelCore::AngelSubSystem::AngelLog::WriteErrorMessage("Failed Start Up WorldManager.");
			return false;
		}
		AngelCore::AngelSubSystem::AngelLog::WriteLogMessage("WorldManager Started.");
	}

	this->m_scriptManager = std::make_shared<ScriptManager>();
	if (this->m_scriptManager)
	{
		if (!this->m_scriptManager->StartUp())
		{
			AngelCore::AngelSubSystem::AngelLog::WriteErrorMessage("Failed Start Up ScriptManager.");
			return false;
		}
		AngelCore::AngelSubSystem::AngelLog::WriteLogMessage("ScriptManager Started.");
	}

	

	AngelCore::AngelSubSystemResources::AudioEngineProperties::aduioManager = new DirectX::AudioManager();
	if (!AngelCore::AngelSubSystemResources::AudioEngineProperties::aduioManager)
	{
		AngelCore::AngelSubSystem::AngelLog::WriteErrorMessage("Failed Start Up AudioManager.");
		return false;
	}

	this->m_mediaManager = new MediaManager();
	if (this->m_mediaManager)
	{
		if (!this->m_mediaManager->StartUp())
		{
			AngelCore::AngelSubSystem::AngelLog::WriteErrorMessage("Failed Start Up MediaManager.");
			return false;
		}
		AngelCore::AngelSubSystem::AngelLog::WriteLogMessage("MediaManager Started.");
	}

	this->m_vrManager = new VRManager();
	if (this->m_vrManager)
	{
		if (!this->m_vrManager->StartUp())
		{
			AngelCore::AngelSubSystem::AngelLog::WriteErrorMessage("Failed Start Up VRManager.");
			return false;
		}
		AngelCore::AngelSubSystem::AngelLog::WriteLogMessage("VRManager Started.");
	}

	m_initialized = true;

	return true;
}
Example #10
0
int main()
{
    SDL_Window *window = NULL;
    int width  = 480, height = 480;
    int flags;
    int quit = 0;

    // Initialize SDL, then get the current video mode and use it to create a SDL window.
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError());
        SDL_Quit();
        exit(1);
    }

    // Request GL context to be OpenGL 3.2 Core Profile
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
    // Other GL attributes
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
    //SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
    window = SDL_CreateWindow("AntTweakBar example using OpenGL Core Profile and SDL",
        SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
        width, height,
        flags);
    if (window == NULL)
    {
        fprintf(stderr, "Video mode set failed: %s\n", SDL_GetError());
        SDL_Quit();
        exit(1);
    }

    // Initialize AntTweakBar
    if (!TwInit(TW_OPENGL_CORE, NULL)) {
        fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError());
        SDL_Quit();
        exit(1);
    }
    // Tell the window size to AntTweakBar
    TwWindowSize(width, height);
    // Create a tweak bar
    CreateTweakBar();

    // Set OpenGL viewport
    glViewport(0, 0, width, height);

    // Prepare GL shaders and programs for drawing
    InitRender();

    // Main loop:
    // - Draw scene
    // - Process events
    while (!quit)
    {
        SDL_Event event;
        int handled;
        GLenum error;

        // Clear screen
        glClearColor(0.5f, 0.75f, 0.8f, 1);
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

        // Update angle and draw geometry
        angle = (float)SDL_GetTicks()/25.0f * (FLOAT_PI/180.0f);
        quat[0] = quat[1] = 0;
        quat[2] = (float)sin(angle/2.0f);
        quat[3] = (float)cos(angle/2.0f);
        Render();

        // Draw tweak bars
        TwDraw();

        // Present frame buffer
        SDL_GL_SwapWindow(window);

        // Process incoming events
        while (SDL_PollEvent(&event))
        {
            // Send event to AntTweakBar
            handled = TwEventSDL(&event);

            // If event has not been handled by AntTweakBar, process it
            if (!handled)
            {
                switch (event.type)
                {
                case SDL_QUIT:  // Window is closed
                    quit = 1;
                    break;

                case SDL_WINDOWEVENT:   // Window size has changed
                    // Resize SDL video mode
                    if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
                        width = event.window.data1;
                        height = event.window.data2;

                        // Resize OpenGL viewport
                        glViewport(0, 0, width, height);

                        // Restore OpenGL states
                        InitRender();

                        // TwWindowSize has been called by TwEventSDL,
                        // so it is not necessary to call it again here.

                    }
                    break;
                }
            }
        }

        while ((error = glGetError()) != GL_NO_ERROR)
            fprintf(stderr, "GL error detected: 0x%04X\n", error);

    } // End of main loop

    // Terminate AntTweakBar
    TwTerminate();

    // Delete GL shaders and buffer
    UninitRender();

    // Terminate SDL
    SDL_Quit();

    return 0;
}
Example #11
0
int main(int argc, const char* argv[]) {
  const char *me;
  me = argv[0];
  // NOTE: we now allow you to either pass in an "invoked" or default shader to render, or to let
  //       us just set up our stack; hence you either pass 2 additional arguments or none at all
  // NOTE: we aren't explicity defining this functionality, but obviously `proj2 -h' will show the
  //       usage pattern
  if (1!=argc && 3!=argc) {
    usage(me);
    exit(1);
  }

  if (!(gctx = contextNew(10, 10))) {
    fprintf(stderr, "%s: context set-up problem:\n", me);
    spotErrorPrint();
    spotErrorClear();
    exit(1);
  }

  if (argc==3) {
    gctx->vertFname = argv[1];
    gctx->fragFname = argv[2];
  } else {
    // NOTE: if invoked with no shaders, set these to NULL; `contextGlInit()' will catch these
    gctx->vertFname = NULL;
    gctx->fragFname = NULL;
  }

  if (!glfwInit()) {
    fprintf(stderr, "Failed to initialize GLFW\n");
    exit(1);
  }

  /* Make sure we're using OpenGL 3.2 core.  NOTE: Changing away from
     OpenGL 3.2 core is not needed and not allowed for this project */
  glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
  glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
  glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  if (!glfwOpenWindow(gctx->winSizeX, gctx->winSizeY, 0, 0, 0, 0, 32, 0, GLFW_WINDOW)) {
    fprintf(stderr, "Failed to open GLFW window\n");
    glfwTerminate();
    exit(1);
  }

  glfwSetWindowTitle("Project 2: Shady");
  glfwEnable(GLFW_MOUSE_CURSOR);
  glfwEnable(GLFW_KEY_REPEAT);
  glfwSwapInterval(1);

  /* Initialize AntTweakBar */
  if (!TwInit(TW_OPENGL_CORE, NULL)) {
    fprintf(stderr, "AntTweakBar initialization failed: %s\n",
            TwGetLastError());
    exit(1);
  }

  printf("GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
  printf("GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
  printf("GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
  printf("PNG_LIBPNG_VER_STRING = %s\n", PNG_LIBPNG_VER_STRING);
  
  /* set-up and initialize the global context */
  if (contextGLInit(gctx)) {
    fprintf(stderr, "%s: context OpenGL set-up problem:\n", me);
    spotErrorPrint(); spotErrorClear();
    TwTerminate();
    glfwTerminate();
    exit(1);
  }

  // NOTE: when we create the tweak bar, either load in scene 1 or default, depending
  //       on whether we were passing a pair of shaders
  if (createTweakBar(gctx, (gctx->vertFname==NULL?1:0))) {
    fprintf(stderr, "%s: AntTweakBar problem:\n", me);
    spotErrorPrint(); spotErrorClear();
    TwTerminate();
    glfwTerminate();
    exit(1);
  }

  glfwSetWindowSizeCallback(callbackResize);
  glfwSetKeyCallback(callbackKeyboard);
  glfwSetMousePosCallback(callbackMousePos);
  glfwSetMouseButtonCallback(callbackMouseButton);

  /* Redirect GLFW mouse wheel events directly to AntTweakBar */
  glfwSetMouseWheelCallback((GLFWmousewheelfun)TwEventMouseWheelGLFW);
  /* Redirect GLFW char events directly to AntTweakBar */
  glfwSetCharCallback((GLFWcharfun)TwEventCharGLFW);

  /* Main loop */
  while (gctx->running) {
    // NOTE: we update UVN every step
    updateUVN(gctx->camera.uvn, gctx->camera.at, gctx->camera.from, gctx->camera.up);

    // Update time
    if (!gctx->paused) {
      gctx->time += 0.1;
      if (gctx->time == 10) { gctx->time = 0; }
    }
    /* render */
    if (contextDraw(gctx)) {
      fprintf(stderr, "%s: trouble drawing:\n", me);
      spotErrorPrint(); spotErrorClear();
      /* Can comment out "break" so that OpenGL bugs are reported but
         do not lead to the termination of the program */
      /* break; */
    }
    /* Draw tweak bar last, just prior to buffer swap */
    if (!TwDraw()) {
      fprintf(stderr, "%s: AntTweakBar error: %s\n", me, TwGetLastError());
      break;
    }
    /* Display rendering results */
    glfwSwapBuffers();
    /* NOTE: don't call glfwWaitEvents() if you want to redraw continuously */
//    glfwWaitEvents();
    /* quit if window was closed */
    if (!glfwGetWindowParam(GLFW_OPENED)) {
      gctx->running = 0;
    }
  }
  
  contextGLDone(gctx);
  contextNix(gctx);
  TwTerminate();
  glfwTerminate();

  exit(0);
}
Example #12
0
// Main
int main(int argc, char *argv[])
{
    TwBar *bar; // Pointer to the tweak bar
    float axis[] = { 0.7f, 0.7f, 0.0f }; // initial model rotation
    float angle = 0.8f;

    // Initialize AntTweakBar
    // (note that AntTweakBar could also be intialized after GLUT, no matter)
    if( !TwInit(TW_OPENGL, NULL) )
    {
        // A fatal error occured    
        fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError());
        return 1;
    }

    // Initialize GLUT
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(640, 480);
    glutCreateWindow("AntTweakBar simple example using GLUT");
    glutCreateMenu(NULL);

    // Set GLUT callbacks
    glutDisplayFunc(Display);
    glutReshapeFunc(Reshape);
    atexit(Terminate);  // Called after glutMainLoop ends

    // Set GLUT event callbacks
    // - Directly redirect GLUT mouse button events to AntTweakBar
    glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT);
    // - Directly redirect GLUT mouse motion events to AntTweakBar
    glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
    // - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion)
    glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
    // - Directly redirect GLUT key events to AntTweakBar
    glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT);
    // - Directly redirect GLUT special key events to AntTweakBar
    glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT);
    // - Send 'glutGetModifers' function pointer to AntTweakBar;
    //   required because the GLUT key event functions do not report key modifiers states.
    TwGLUTModifiersFunc(glutGetModifiers);

    // Create some 3D objects (stored in display lists)
    glNewList(SHAPE_TEAPOT, GL_COMPILE);
    glutSolidTeapot(1.0);
    glEndList();
    glNewList(SHAPE_TORUS, GL_COMPILE);
    glutSolidTorus(0.3, 1.0, 16, 32);
    glEndList();
    glNewList(SHAPE_CONE, GL_COMPILE);
    glutSolidCone(1.0, 1.5, 64, 4);
    glEndList();

    // Create a tweak bar
    bar = TwNewBar("TweakBar");
    TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar with GLUT and OpenGL.' "); // Message added to the help bar.
    TwDefine(" TweakBar size='200 400' color='96 216 224' "); // change default tweak bar size and color

    // Add 'g_Zoom' to 'bar': this is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [z] and [Z].
    TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom, 
               " min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z help='Scale the object (1=original size).' ");

    // Add 'g_Rotation' to 'bar': this is a variable of type TW_TYPE_QUAT4F which defines the object's orientation
    TwAddVarRW(bar, "ObjRotation", TW_TYPE_QUAT4F, &g_Rotation, 
               " label='Object rotation' open help='Change the object orientation.' ");

    // Add callback to toggle auto-rotate mode (callback functions are defined above).
    TwAddVarCB(bar, "AutoRotate", TW_TYPE_BOOL32, SetAutoRotateCB, GetAutoRotateCB, NULL, 
               " label='Auto-rotate' key=space help='Toggle auto-rotate mode.' ");

    // Add 'g_LightMultiplier' to 'bar': this is a variable of type TW_TYPE_FLOAT. Its key shortcuts are [+] and [-].
    TwAddVarRW(bar, "Multiplier", TW_TYPE_FLOAT, &g_LightMultiplier, 
               " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' help='Increase/decrease the light power.' ");

    // Add 'g_LightDirection' to 'bar': this is a variable of type TW_TYPE_DIR3F which defines the light direction
    TwAddVarRW(bar, "LightDir", TW_TYPE_DIR3F, &g_LightDirection, 
               " label='Light direction' open help='Change the light direction.' ");

    // Add 'g_MatAmbient' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into a group named 'Material'.
    TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &g_MatAmbient, " group='Material' ");

    // Add 'g_MatDiffuse' to 'bar': this is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored)
    // and is inserted into group 'Material'.
    TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &g_MatDiffuse, " group='Material' ");

    // Add the enum variable 'g_CurrentShape' to 'bar'
    // (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
    {
        // ShapeEV associates Shape enum values with labels that will be displayed instead of enum values
        TwEnumVal shapeEV[NUM_SHAPES] = { {SHAPE_TEAPOT, "Teapot"}, {SHAPE_TORUS, "Torus"}, {SHAPE_CONE, "Cone"} };
        // Create a type for the enum shapeEV
        TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
        // add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
        TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, " keyIncr='<' keyDecr='>' help='Change object shape.' ");
    }

    // Store time
    g_RotateTime = glutGet(GLUT_ELAPSED_TIME);
    // Init rotation
    SetQuaternionFromAxisAngle(axis, angle, g_Rotation);
    SetQuaternionFromAxisAngle(axis, angle, g_RotateStart);

    // Call the GLUT main loop
    glutMainLoop();

    return 0;
}
// Main
int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int cmdShow)
{
    // Register our window class
    WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_HREDRAW|CS_VREDRAW, MessageProc,
                        0L, 0L, instance, NULL, NULL, NULL, NULL, L"TwDX11", NULL };
    RegisterClassEx(&wcex);

    // Create a window
    RECT rc = { 0, 0, 640, 480 };
    AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);
    HWND wnd = CreateWindow(L"TwDX11", L"AntTweakBar simple example using DirectX11", 
                            WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 
                            rc.right-rc.left, rc.bottom-rc.top, NULL, NULL, instance, NULL);
    if (!wnd)
    {
        MessageBox(NULL, L"Cannot create window", L"Error", MB_OK|MB_ICONERROR);
        return 0;
    }
    ShowWindow(wnd, cmdShow);
    UpdateWindow(wnd);

    // Initialize D3D11
    if (FAILED(InitDevice(wnd)))
    {
        MessageBox(wnd, L"Cannot create D3D11 device", L"Error", MB_OK|MB_ICONERROR);
        Cleanup();
        return 0;
    }

    // Initialize the 3D scene
    if (FAILED(InitScene()))
    {
        MessageBox(wnd, L"Scene initialization failed.", L"Error", MB_OK|MB_ICONERROR);
        Cleanup();
        return 0;
    }

    // Initialize AntTweakBar
    if (!TwInit(TW_DIRECT3D11, g_D3DDev))
    {
        MessageBoxA(wnd, TwGetLastError(), "AntTweakBar initialization failed", MB_OK|MB_ICONERROR);
        Cleanup();
        return 0;
    }

    // Create a tweak bar
    TwBar *bar = TwNewBar("TweakBar");
    TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar into a DirectX11 application.' "); // Message added to the help bar.
    int barSize[2] = {224, 320};
    TwSetParam(bar, NULL, "size", TW_PARAM_INT32, 2, barSize);

    // Add variables to the tweak bar
    TwAddVarCB(bar, "Level", TW_TYPE_INT32, SetSpongeLevelCB, GetSpongeLevelCB, NULL, "min=0 max=3 group=Sponge keyincr=l keydecr=L");
    TwAddVarCB(bar, "Ambient Occlusion", TW_TYPE_BOOLCPP, SetSpongeAOCB, GetSpongeAOCB, NULL, "group=Sponge key=o");
    TwAddVarRW(bar, "Rotation", TW_TYPE_QUAT4F, &g_SpongeRotation, "opened=true axisz=-z group=Sponge");
    TwAddVarRW(bar, "Animation", TW_TYPE_BOOLCPP, &g_Animate, "group=Sponge key=a");
    TwAddVarRW(bar, "Animation speed", TW_TYPE_FLOAT, &g_AnimationSpeed, "min=-10 max=10 step=0.1 group=Sponge keyincr=+ keydecr=-");
    TwAddVarRW(bar, "Light direction", TW_TYPE_DIR3F, &g_LightDir, "opened=true axisz=-z showval=false");
    TwAddVarRW(bar, "Camera distance", TW_TYPE_FLOAT, &g_CamDistance, "min=0 max=4 step=0.01 keyincr=PGUP keydecr=PGDOWN");
    TwAddVarRW(bar, "Background", TW_TYPE_COLOR4F, &g_BackgroundColor, "colormode=hls");

    // Main message loop
    MSG msg = {0};
    while (WM_QUIT != msg.message)
    {
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
        {
            Anim();
            Render(); 
        }
    }

    TwTerminate();
    Cleanup();

    return (int)msg.wParam;
}
Example #14
0
// Main
int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int cmdShow)
{
    // Register our window class
    WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_CLASSDC|CS_DBLCLKS, MessageProc, 0L, 0L, 
                        instance, NULL, NULL, NULL, NULL, "TwDX9", NULL };
    RegisterClassEx(&wcex);

    // Create a window
    const int W = 640;
    const int H = 480;
    BOOL fullscreen = FALSE; // Set to TRUE to run in fullscreen
    RECT rect = { 0, 0, W, H };
    DWORD style = fullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW;
    AdjustWindowRect(&rect, style, FALSE);
    HWND wnd = CreateWindow("TwDX9", "AntTweakBar simple example using DirectX9", 
                            style, CW_USEDEFAULT, CW_USEDEFAULT, 
                            rect.right-rect.left, rect.bottom-rect.top, NULL, NULL, instance, NULL);
    if( !wnd )
    {
        MessageBox(NULL, "Cannot create window", "Error", MB_OK|MB_ICONERROR);
        return FALSE;
    }
    ShowWindow(wnd, cmdShow);
    UpdateWindow(wnd);

    // Initialize Direct3D
    g_D3D = Direct3DCreate9(D3D_SDK_VERSION);
    if( !g_D3D )
    {
        MessageBox(wnd, "Cannot initialize DirectX", "Error", MB_OK|MB_ICONERROR);
        return FALSE;
    }

    // Create a Direct3D device
    ZeroMemory( &g_D3Dpp, sizeof(D3DPRESENT_PARAMETERS) );
    g_D3Dpp.Windowed = !fullscreen;
    if( fullscreen )
    {
        g_D3Dpp.BackBufferWidth = W;
        g_D3Dpp.BackBufferHeight = H;
    }
    g_D3Dpp.BackBufferCount = 1;
    g_D3Dpp.SwapEffect = D3DSWAPEFFECT_FLIP;
    if( fullscreen )
        g_D3Dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    else
        g_D3Dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    g_D3Dpp.hDeviceWindow = wnd;

    g_D3Dpp.EnableAutoDepthStencil = TRUE;
    g_D3Dpp.AutoDepthStencilFormat = D3DFMT_D16;
    g_D3Dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    HRESULT hr = g_D3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, 
                                     D3DCREATE_SOFTWARE_VERTEXPROCESSING, &g_D3Dpp, &g_D3DDev);
    if( FAILED(hr) )
    {
        //DXTRACE_ERR_MSGBOX("Cannot create DirectX device", hr);
        MessageBox(wnd, "Cannot create DirectX device", "Error", MB_OK|MB_ICONERROR);
        g_D3D->Release();
        g_D3D = NULL;
        return FALSE;
    }

    // This example draws a moving strip;
    // create a buffer of vertices for the strip
    struct Vertex
    {
        float x, y, z;
        DWORD color;
    };
    Vertex vertices[2002];
    int numSec = 100;            // number of strip sections
    float color[] = { 1, 0, 0 }; // strip color
    unsigned int bgColor = D3DCOLOR_ARGB(255, 128, 196, 196); // background color

    // Init some D3D states
    InitD3D();

    // Initialize AntTweakBar
    // (note that the Direct3D device pointer must be passed to TwInit)
    if( !TwInit(TW_DIRECT3D9, g_D3DDev) )
    {
        MessageBox(wnd, TwGetLastError(), "Cannot initialize AntTweakBar", MB_OK|MB_ICONERROR);
        g_D3DDev->Release();
        g_D3DDev = NULL;
        g_D3D->Release();
        g_D3D = NULL;
        return FALSE;
    }

    
    // Create a tweak bar
    TwBar *bar = TwNewBar("TweakBar");
    TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar in a DirectX9 application.' "); // Message added to the help bar.
    TwDefine(" TweakBar color='128 224 160' text=dark "); // Change TweakBar color and use dark text

    // Add 'numSec' to 'bar': it is a modifiable (RW) variable of type TW_TYPE_INT32. Its shortcuts are [s] and [S].
    TwAddVarRW(bar, "NumSec", TW_TYPE_INT32, &numSec, 
               " label='Strip length' min=1 max=1000 keyIncr=s keyDecr=S help='Number of segments of the strip.' ");

    // Add 'color' to 'bar': it is a modifiable variable of type TW_TYPE_COLOR3F (3 floats color)
    TwAddVarRW(bar, "Color", TW_TYPE_COLOR3F, &color, " label='Strip color' ");

    // Add 'bgColor' to 'bar': it is a modifiable variable of type TW_TYPE_COLOR32 (32 bits color)
    TwAddVarRW(bar, "BgColor", TW_TYPE_COLOR32, &bgColor, " label='Background color' ");

    // Add 'width' and 'height' to 'bar': they are read-only (RO) variables of type TW_TYPE_INT32.
    TwAddVarRO(bar, "Width", TW_TYPE_INT32, &g_D3Dpp.BackBufferWidth, 
               " label='wnd width' help='Current graphics window width.' ");
    TwAddVarRO(bar, "Height", TW_TYPE_INT32, &g_D3Dpp.BackBufferHeight, 
               " label='wnd height' help='Current graphics window height.' ");


    // Main loop
    bool quit = false;
    while( !quit )
    {
        // Clear screen and begin draw
        g_D3DDev->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, bgColor, 1.0f, 0);
        g_D3DDev->BeginScene();

        // Draw scene
        float s, t = (float)GetTickCount()/1000.0f;
        for( int i=0; i<=numSec; ++i )  // update vertices
        {
            s = (float)i/100;
            vertices[2*i+0].x = 0.05f+0.7f*cosf(2.0f*s+5.0f*t);
            vertices[2*i+1].x = vertices[2*i+0].x + (0.25f+0.1f*cosf(s+t));
            vertices[2*i+0].y = vertices[2*i+1].y = 0.7f*(0.7f+0.3f*sinf(s+t))*sinf(1.5f*s+3.0f*t);
            vertices[2*i+0].z = vertices[2*i+1].z = 0;
            s = (float)i/numSec;
            vertices[2*i+0].color = vertices[2*i+1].color = 
                D3DCOLOR_XRGB((int)(255*color[0]*s), (int)(255*color[1]*s), (int)(255*color[2]*s));
        }
        g_D3DDev->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE);
        g_D3DDev->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2*numSec, vertices, sizeof(Vertex)); // draw strip
 
        // Draw tweak bars
        TwDraw();

        // End draw
        g_D3DDev->EndScene();

        // Present frame buffer
        g_D3DDev->Present(NULL, NULL, NULL, NULL);

        // Process windows messages
        MSG msg;
        while( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
        {
            if( msg.message==WM_QUIT )
                quit = true;
            else if( !TranslateAccelerator(msg.hwnd, NULL, &msg) ) 
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
    } // End of main loop


    // Terminate AntTweakBar
    TwTerminate();

    // Release Direct3D
    g_D3DDev->Release();
    g_D3DDev = NULL;
    g_D3D->Release();
    g_D3D = NULL;

    return 0;
}
Example #15
0
// Main
int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int cmdShow)
{
    // Register our window class
    WNDCLASSEX wcex = { sizeof(WNDCLASSEX), CS_HREDRAW|CS_VREDRAW, MessageProc,
                        0L, 0L, instance, NULL, NULL, NULL, NULL, L"TwDX10", NULL };
    RegisterClassEx(&wcex);

    // Create a window
    RECT rc = { 0, 0, 640, 480 };
    AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE);
    HWND wnd = CreateWindow(L"TwDX10", L"AntTweakBar simple example using DirectX10", 
                            WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 
                            rc.right-rc.left, rc.bottom-rc.top, NULL, NULL, instance, NULL);
    if( !wnd )
    {
        MessageBox(NULL, L"Cannot create window", L"Error", MB_OK|MB_ICONERROR);
        return 0;
    }

    // Initialize D3D10
    if( FAILED(InitDevice(wnd)) )
    {
        Cleanup();
        MessageBox(wnd, L"Cannot create D3D10 device", L"Error", MB_OK|MB_ICONERROR);
        return 0;
    }

    // Initialize the 3D scene
    if( FAILED(InitScene()) )
    {
        Cleanup();
        MessageBox(wnd, L"Scene initialization failed.", L"Error", MB_OK|MB_ICONERROR);
        return 0;
    }


    // Initialize AntTweakBar
    if( !TwInit(TW_DIRECT3D10, g_D3DDevice) )
    {
        Cleanup();
        MessageBoxA(wnd, TwGetLastError(), "AntTweakBar initialization failed", MB_OK|MB_ICONERROR);
        return 0;
    }

    // Create a tweak bar
    TwBar *bar = TwNewBar("TweakBar");
    TwDefine(" GLOBAL help='This example shows how to integrate AntTweakBar in a DirectX10 application.' "); // Message added to the help bar.

    // Add rotation and scale vars to bar
    TwAddVarRW(bar, "Rotation", TW_TYPE_INT32, &g_Angle, 
               " KeyIncr=r KeyDecr=R Help='Rotates the triangle (angle in degree).' ");
    TwAddVarRW(bar, "Scale", TW_TYPE_FLOAT, &g_Scale, 
               " Min=-2 Max=2 Step=0.01 KeyIncr=s KeyDecr=S Help='Scales the triangle (1=original size).' ");

    // Create a new TwType to edit 2D points: a struct that contains two floats
    TwStructMember pointMembers[] = { 
        { "X", TW_TYPE_FLOAT, offsetof(Point, X), " Min=-1 Max=1 Step=0.01 " },
        { "Y", TW_TYPE_FLOAT, offsetof(Point, Y), " Min=-1 Max=1 Step=0.01 " } };
    TwType pointType = TwDefineStruct("POINT", pointMembers, 2, sizeof(Point), NULL, NULL);

    // Add color and position of the 3 vertices of the triangle
    TwAddVarRW(bar, "Color0", TW_TYPE_COLOR4F, &g_Colors[0], " Alpha HLS Group='Vertex 0' Label=Color ");
    TwAddVarRW(bar, "Pos0", pointType, &g_Positions[0], " Group='Vertex 0' Label='Position' ");
    TwAddVarRW(bar, "Color1", TW_TYPE_COLOR4F, &g_Colors[1], " Alpha HLS Group='Vertex 1' Label=Color ");
    TwAddVarRW(bar, "Pos1", pointType, &g_Positions[1], " Group='Vertex 1' Label='Position' ");
    TwAddVarRW(bar, "Color2", TW_TYPE_COLOR4F, &g_Colors[2], " Alpha HLS Group='Vertex 2' Label=Color ");
    TwAddVarRW(bar, "Pos2", pointType, &g_Positions[2], " Group='Vertex 2' Label='Position' ");


    // Show and update the window
    ShowWindow(wnd, cmdShow);
    UpdateWindow(wnd);

    // Main message loop.
    // Passive loop: Content is repaint only when needed.
    MSG msg = {0};
    while( GetMessage(&msg, NULL, 0, 0) > 0 )
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    TwTerminate();
    Cleanup();

    return (int)msg.wParam;
}
Example #16
0
int main(int argc, char** argv)
{
	{
	::SetPriorityClass(::GetCurrentProcess(),REALTIME_PRIORITY_CLASS);
	/*btDbvt::benchmark();
	exit(0);*/
	}
	// Initialize AntTweakBar
	// (note that AntTweakBar could also be intialize after GLUT, no matter)
	if(!TwInit(TW_OPENGL, NULL))
	{
		// A fatal error occured	
		fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError());
	}

	// Initialize Glut
	glutInit(&argc, argv);
	glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
	int mainHandle = glutCreateWindow("CD Test Framework");

/*	HWND hWnd;
	hWnd = FindWindow("GLUT", "CD Test Framework");
	RECT Rect;
	GetWindowRect(hWnd, &Rect);
*/
	glutCreateMenu(NULL);
	glutSetWindow(mainHandle);
	glutDisplayFunc(RenderCallback);
	glutReshapeFunc(ReshapeCallback);
	glutIdleFunc(IdleCallback);
	glutKeyboardFunc(KeyboardCallback);
	glutSpecialFunc(ArrowKeyCallback);
	glutMouseFunc(MouseCallback);
	glutMotionFunc(MotionCallback);
	atexit(Terminate);	// Called after glutMainLoop ends

	glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
	TwGLUTModifiersFunc(glutGetModifiers);

	// Setup default render states
	glClearColor(0.3f, 0.4f, 0.5f, 1.0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_CULL_FACE);
	glDepthFunc(GL_LEQUAL);

	// Setup lighting
	glEnable(GL_LIGHTING);
	float AmbientColor[] = { 0.0f, 0.1f, 0.2f, 0.0f };		glLightfv(GL_LIGHT0, GL_AMBIENT, AmbientColor);
	float DiffuseColor[] = { 1.0f, 1.0f, 1.0f, 0.0f };		glLightfv(GL_LIGHT0, GL_DIFFUSE, DiffuseColor);
	float SpecularColor[] = { 0.0f, 0.0f, 0.0f, 0.0f };		glLightfv(GL_LIGHT0, GL_SPECULAR, SpecularColor);
	float Position[] = { -10.0f, 1000.0f, -4.0f, 1.0f };	glLightfv(GL_LIGHT0, GL_POSITION, Position);
	glEnable(GL_LIGHT0);

	gFnt.init();
	gFnt.setScreenResolution(WINDOW_WIDTH, WINDOW_HEIGHT);
	gFnt.setColor(1.0f, 1.0f, 1.0f, 1.0f);

	CreateTerrain();

	// Create main tweak bar
	{
		gMainBar = TwNewBar("CollisionTests");
		TwEnumVal testEV[MAX_NB_TESTS] = {
//			{TEST_SPHERE_MESH_QUERY, "Sphere-mesh query"},
//			{TEST_OBB_MESH_QUERY, "OBB-mesh query"},
//			{TEST_CAPSULE_MESH_QUERY, "Capsule-mesh query"},
//			{TEST_COMPLETE_BOX_PRUNING, "OPCODE SAP 1024"},
			{TEST_COMPLETE_BOX_PRUNING_8192, "OPCODE BOX PRUNING 8192"},
//			{TEST_BULLET_SAP_1024, "Bullet SAP HASHPAIR 1024"},
//			{TEST_BULLET_SAP_8192, "Bullet SAP HASHPAIR 8192"},
//			{TEST_BULLET_SAP_SORTEDPAIRS_8192, "Bullet SAP SORTEDPAIR 8192"},
//			{TEST_BULLET_MULTISAP_8192, "Bullet MultiSAP 8192"},
//			{TEST_BIPARTITE_BOX_PRUNING, "Bipartite box pruning"},
			{TEST_DBVT_8192, "Bullet DBVT 8192"},
			{TEST_BULLET_CUDA_8192, "Bullet CUDA 8192"},
			{TEST_BULLET_3DGRID_8192, "Bullet 3D Grid 8192"},
			{TEST_OPCODE_ARRAY_SAP, "OPCODE ARRAY SAP"},
		};
		TwType testType = TwDefineEnum("CollisionTest", testEV, MAX_NB_TESTS);
		TwAddVarRW(gMainBar, "CollisionTests", testType, &gSelectedTest, "");		
		TwAddVarRW(gMainBar, "% of updates",TW_TYPE_INT32,&percentUpdate,"min=0 max=100");
		TwAddVarRW(gMainBar, "Draw",TW_TYPE_BOOLCPP,&enableDraw,"");
	}

	// Create tests
	gTest = 0;
//	gCollisionTests[TEST_SPHERE_MESH_QUERY]	= new SphereMeshQuery;
//	gCollisionTests[TEST_OBB_MESH_QUERY]	= new OBBMeshQuery;
//	gCollisionTests[TEST_CAPSULE_MESH_QUERY]	= new CapsuleMeshQuery;
//	gCollisionTests[TEST_COMPLETE_BOX_PRUNING]	= new CompleteBoxPruningTest(NUM_SAP_BOXES);
 //	gCollisionTests[TEST_COMPLETE_BOX_PRUNING_8192]	= new CompleteBoxPruningTest(NUM_SAP_BOXES);
	gCollisionTests[TEST_COMPLETE_BOX_PRUNING_8192]	= new CompleteBoxPruningTest(NUM_SAP_BOXES);
//	gCollisionTests[TEST_BULLET_SAP_1024]	= new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,1);
// 	gCollisionTests[TEST_BULLET_SAP_8192]	= new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,1);
//	gCollisionTests[TEST_BULLET_SAP_SORTEDPAIRS_8192]	= new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,3);
// 	gCollisionTests[TEST_BULLET_MULTISAP_8192]	= new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,6);
//	gCollisionTests[TEST_BIPARTITE_BOX_PRUNING]	= new BipartiteBoxPruningTest;
	gCollisionTests[TEST_DBVT_8192]	= new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,7);
	gCollisionTests[TEST_BULLET_CUDA_8192]	= new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,8);
	gCollisionTests[TEST_BULLET_3DGRID_8192]	= new BulletSAPCompleteBoxPruningTest(NUM_SAP_BOXES,9);
	gCollisionTests[TEST_OPCODE_ARRAY_SAP]	= new OpcodeArraySAPTest(NUM_SAP_BOXES);

	for(int i=0;i<MAX_NB_TESTS;i++)
		gCollisionTests[i]->Init();
	gCollisionTests[gTest]->Select();

	//
	MotionCallback(0,0);

	// Run
	glutMainLoop();

	return 0;
}
Example #17
0
// Main
int main(int argc, char *argv[])
{
	TwBar *bar;	// Pointer to a tweak bar

	// Initialize AntTweakBar
	// (note that AntTweakBar could also be intialize after GLUT, no matter)
	if( !TwInit(TW_OPENGL, NULL) )
	{
		// A fatal error occured	
		fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError());
		return 1;
	}

	// Initialize GLUT
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(640, 480);
	glutCreateWindow("AntTweakBar simple example using GLUT");
	glutCreateMenu(NULL);

	// Set GLUT callbacks
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	atexit(Terminate);	// Called after glutMainLoop ends

	// Set GLUT event callbacks
	// - Directly redirect GLUT mouse button events to AntTweakBar
	glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT);
	// - Directly redirect GLUT mouse motion events to AntTweakBar
	glutMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
	// - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion)
	glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
	// - Directly redirect GLUT key events to AntTweakBar
	glutKeyboardFunc((GLUTkeyboardfun)TwEventKeyboardGLUT);
	// - Directly redirect GLUT special key events to AntTweakBar
	glutSpecialFunc((GLUTspecialfun)TwEventSpecialGLUT);
	// - Send 'glutGetModifers' function pointer to AntTweakBar;
	//   required because the GLUT key event functions do not report key modifiers states.
	TwGLUTModifiersFunc(glutGetModifiers);

	// Create some 3D objects (stored in display lists)
	glNewList(SHAPE_TEAPOT, GL_COMPILE);
	glutSolidTeapot(1.0);
	glEndList();
	glNewList(SHAPE_TORUS, GL_COMPILE);
	glutSolidTorus(0.3, 1.0, 16, 32);
	glEndList();
	glNewList(SHAPE_CONE, GL_COMPILE);
	glutSolidCone(1.0, 1.5, 64, 4);
	glEndList();

	// Create a tweak bar
	bar = TwNewBar("TweakBar");
	// Add 'g_Zoom' to 'bar': it is a modifable (RW) variable of type TW_TYPE_FLOAT. Its key shortcuts are [z] and [Z].
	TwAddVarRW(bar, "Zoom", TW_TYPE_FLOAT, &g_Zoom, " min=0.01 max=2.5 step=0.01 keyIncr=z keyDecr=Z ");
	// Add 'g_LightMultiplier' to 'bar': it is a variable of type TW_TYPE_FLOAT. Its key shortcuts are [+] and [-].
	TwAddVarRW(bar, "Multiplier", TW_TYPE_FLOAT, &g_LightMultiplier, " label='Light booster' min=0.1 max=4 step=0.02 keyIncr='+' keyDecr='-' ");
	// Add 'g_MatAmbient' to 'bar': it is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored). It is inserted into a group named 'Material'.
	TwAddVarRW(bar, "Ambient", TW_TYPE_COLOR3F, &g_MatAmbient, " group='Material' ");
	// Add 'g_MatDiffuse' to 'bar': it is a variable of type TW_TYPE_COLOR3F (3 floats color, alpha is ignored). It is inserted into group 'Material'.
	TwAddVarRW(bar, "Diffuse", TW_TYPE_COLOR3F, &g_MatDiffuse, " group='Material' ");
	// Add the enum variable 'g_CurrentShape' to 'bar'
	// (before adding an enum variable, its enum type must be declared to AntTweakBar as follow)
	{
		// ShapeEV associates Shape enum values with labels that will be displayed instead of enum values
		TwEnumVal shapeEV[NUM_SHAPES] = { {SHAPE_TEAPOT, "Teapot"}, {SHAPE_TORUS, "Torus"}, {SHAPE_CONE, "Cone"} };
		// Create a type for the enum shapeEV
		TwType shapeType = TwDefineEnum("ShapeType", shapeEV, NUM_SHAPES);
		// add 'g_CurrentShape' to 'bar': it is a variable of type ShapeType. Its key shortcuts are [<] and [>].
		TwAddVarRW(bar, "Shape", shapeType, &g_CurrentShape, " keyIncr='<' keyDecr='>' ");
	}

	// Call the GLUT main loop
	glutMainLoop();

	return 0;
}