예제 #1
0
void Camera::initialize(
   const Point3& scene_centre, float scene_radius,
   int window_width_in_pixels, int window_height_in_pixels,
   int viewport_x1, int viewport_y1, int viewport_x2, int viewport_y2
) {
   _initialGround = Vector3( 0, 1, 0 );
   ASSERT_IS_NORMALIZED( _initialGround );

   setSceneCentre( scene_centre );
   setSceneRadius( scene_radius );
   _minimum_feature_size = _nearPlaneFactor * _scene_radius;
   _near_plane = _minimum_feature_size;

   _window_width_in_pixels = window_width_in_pixels;
   _window_height_in_pixels = window_height_in_pixels;
   _viewport_x1 = viewport_x1;
   _viewport_y1 = viewport_y1;
   _viewport_x2 = viewport_x2;
   _viewport_y2 = viewport_y2;

   reset();
   resizeViewport(
      window_width_in_pixels, window_height_in_pixels,
      viewport_x1, viewport_y1, viewport_x2, viewport_y2
   );
}
예제 #2
0
void Game::run()
{
    Log::write(Log::LOG_INFO, "== Starting Game ==");

    // Initialize tools
    ImageManager *im = new ImageManager(); // deleted in the Locator destructor
    Locator::provideImageManager(im);

    Log::write(Log::LOG_INFO, "ImageManager loaded");

    sf::err().rdbuf(std::cout.rdbuf());

    Context &context = getContext();
    sf::RenderWindow &app = context.getApp();

    sf::ContextSettings settings;
    settings.antialiasingLevel = 8;
    Log::write(Log::LOG_INFO, "Antialiasing Level set to 8");

    sf::VideoMode videoMode;
    sf::Uint32 style = sf::Style::Default;

    if(style == sf::Style::Fullscreen)
        videoMode = sf::VideoMode::getDesktopMode();
    else
        videoMode = sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT);

    app.create(videoMode, "CaSFML-Defender", style, settings); // for debug / screenshots / screencasts
    app.setPosition(sf::Vector2i(0, 0)); // for screenshots / screencasts
    app.setView(sf::View(sf::FloatRect(0, 0, VIEW_WIDTH, VIEW_HEIGHT)));
    Log::write(Log::LOG_INFO, std::string("Window " + toString(WINDOW_WIDTH) + ";" + toString(WINDOW_HEIGHT)));
    Log::write(Log::LOG_INFO, std::string("View " + toString(VIEW_WIDTH) + ";" + toString(VIEW_HEIGHT)));

    resizeViewport(videoMode.width, videoMode.height, app);

    std::srand(time(NULL));

    app.setVerticalSyncEnabled(true);

    // Initialize screens
    Log::write(Log::LOG_INFO, "Initializing screens");
    _stateMachine.add("splashscreen", new SplashScreen(_stateMachine));
    _stateMachine.add("menu", new Menu(_stateMachine));
    //_stateMachine.add("playingscreen", new PlayingScreen(_stateMachine));
    _stateMachine.add("gameover", new GameOver(_stateMachine));

    _stateMachine.change("splashscreen");

    _timeSinceLastUpdate = sf::Time::Zero;
    while(!_isExiting)
    {
        gameLoop();
    }

    app.close();
}
예제 #3
0
파일: camera.cpp 프로젝트: 0rps/3dmanager
Camera::Camera(const QSize& sizeViewport) :
    m_cameraFov(45.0f),
    m_nearClip(0.001f),
    m_farClip(1e16f),
    m_viewPortSize(sizeViewport),
    m_scale(1.0),
    m_roll(0.0),
    m_right( QVector3D(1, 0, 0) ),
    m_up( QVector3D(0, 0, 1) ),
    m_isFreeMode(false),
    m_sceneRadius(1.0)
{
    resizeViewport( sizeViewport.width(), sizeViewport.height() );
}
예제 #4
0
void Camera::pushViewportAndTransform(
   int window_width_in_pixels, int window_height_in_pixels,
   int viewport_x1, int viewport_y1,
   int viewport_x2, int viewport_y2,
   int originalViewport[4]
) {
   glGetIntegerv( GL_VIEWPORT, originalViewport );
   resizeViewport(
      window_width_in_pixels, window_height_in_pixels,
      viewport_x1, viewport_y1,
      viewport_x2, viewport_y2
   );
   glMatrixMode( GL_PROJECTION );
   glPushMatrix();
   transform();
}
예제 #5
0
void Game::gameLoop()
{
    sf::RenderWindow& app = getContext().getApp();

    sf::Time elapsedTime = _clock.restart();
    _timeSinceLastUpdate += elapsedTime;
    while(_timeSinceLastUpdate > Game::TimePerFrame)
    {
        _timeSinceLastUpdate -= Game::TimePerFrame;

        while(app.pollEvent(_currentEvent))
        {
            switch(_currentEvent.type)
            {
                case sf::Event::Closed:
                    _isExiting = true;
                    break;
                case sf::Event::KeyPressed:
                    if(_currentEvent.key.code == sf::Keyboard::F3)
                        getContext().setDebug(!getContext().getDebug());
                    break;
                case sf::Event::Resized:
                    Log::write(Log::LOG_INFO, "Resized, new size : " + toString(_currentEvent.size.width) + ";"
                                                                     + toString(_currentEvent.size.height));

                    resizeViewport(_currentEvent.size.width, _currentEvent.size.height, app);
                    break;
            }

        }

        // Update every frame
        _stateMachine.update(Game::TimePerFrame);
    }

    if(getContext().getDebug())
        updateStats(elapsedTime);

    app.clear();

    _stateMachine.draw(app);
    if(getContext().getDebug())
        app.draw(_statisticsText);

    app.display();
}
예제 #6
0
void PlanetWidget::resizeGL (int, int) {
	resizeViewport();
	paintGL();
}
예제 #7
0
	H3DView(int winWidth, int winHeight) :
			BulletEngineTest(),
			//model(0),
			cam(0),
			frameNum(0),
			text(NULL), textLen(32),
			_rx(15), _ry(-50),
			//_rx(0), _ry(0),
			_prev_x(0), _prev_y(0),
			_mouseEnteredThisFrame(false)
	{
		assert(view == NULL);
		view = this;

		text = new char[textLen];
		memset(text, 0, textLen);

		LOG("Initializing Horde3D...");
		h3dInit();

		h3dSetOption(H3DOptions::MaxAnisotropy, 8);
		h3dSetOption(H3DOptions::SampleCount, 16);

		//h3dSetOption(H3DOptions::WireframeMode, 1);
		//h3dSetOption(H3DOptions::DebugViewMode, 1);
		h3dSetOption(H3DOptions::GatherTimeStats, 1);

		LOG("Declaring resources...");

		pipeRes = h3dAddResource(H3DResTypes::Pipeline, "pipelines/forward.pipeline.xml", 0);

		H3DRes skyBoxRes = h3dAddResource(H3DResTypes::SceneGraph, "models/skybox/skybox.scene.xml", 0);

		//modelRes = h3dAddResource(H3DResTypes::SceneGraph, "models/AssJacket/AssJacket.scene.xml", 0);
		//modelRes = h3dAddResource(H3DResTypes::SceneGraph, "models/ares/ares.scene.xml", 0);
		modelRes = h3dAddResource(H3DResTypes::SceneGraph, "models/man/man.scene.xml", 0);

		fontMatRes = h3dAddResource(H3DResTypes::Material, "overlays/font.material.xml", 0);
		panelMatRes = h3dAddResource(H3DResTypes::Material, "overlays/panel.material.xml", 0);

		LOG("Loading resources from disk...");
		h3dutLoadResourcesFromDisk("/home/whitelynx/devel/other/Horde3D/build-make/Binaries/Content"
				"|/home/whitelynx/devel/skewedaspect/precursors-client/resources/content");

		LOG("Building scene...");
		/*
		// Add model to scene
		model = h3dAddNodes(H3DRootNode, modelRes);
		h3dSetNodeTransform(model,
				0, 0, -500,  // Translation
				0, 0, 0,     // Rotation
				1, 1, 1      // Scale
				);
		*/

		// Add light source
		H3DNode light = h3dAddLightNode(H3DRootNode, "Light1", 0, "LIGHTING", "SHADOWMAP");
		// Set light position and radius
		h3dSetNodeTransform(light,
				0, 20, 0,
				0, 0, 0,
				10, 10, 10
				);
		h3dSetNodeParamF(light, H3DLight::RadiusF, 0, 50.0f);

		LOG("Setting up camera...");
		cam = h3dAddCameraNode(H3DRootNode, "Camera", pipeRes);

		resizeViewport(winWidth, winHeight);

#if 1
		H3DNode sky = h3dAddNodes(H3DRootNode, skyBoxRes);
		h3dSetNodeTransform(sky,
				0, 0, 0,      // Translation
				0, 0, 0,      // Rotation
				210, 50, 210  // Scale
				);
		h3dSetNodeFlags(sky, H3DNodeFlags::NoCastShadow, true);
#endif

		LOG("Setting BulletEngine callbacks...");
		setMakeModelCallback(&makeModelCB);
		setUpdateModelCallback(&updateModelCB);

		LOG("Initializing physics...");
		initPhysics();

		LOG("Ready.");
	} // end H3DView
예제 #8
0
//extern void drawModelSetMax(void);
int glInit(void){
	cvar_register(&cvar_gl_MSAA_Samples);
	cvar_pset(&cvar_gl_MSAA_Samples, "0");
//	console_printf("cvar id is %i\n", cvar_gl_MSAA_Samples.myid);
//	console_printf("cvar name is %s\n", cvar_gl_MSAA_Samples.name);
//	console_printf("cvar value is %s\n", cvar_gl_MSAA_Samples.valuestring);
	glewExperimental = TRUE;
	GLenum glewError = glewInit();
	CHECKGLERROR
	if(glewError != GLEW_OK){
		console_printf("ERROR with the glew: %s\n", glewGetErrorString(glewError));
		return FALSE;
	}
	shader_init();
	CHECKGLERROR
	if(!shader_ok){
		//todo call some sort of shutdown of everything
		 return FALSE;
	}
	texture_init();
	CHECKGLERROR
	if(!texture_ok){
		//todo call some sort of shutdown of everything
		 return FALSE;
	}
	framebuffer_init();
	CHECKGLERROR
	if(!framebuffer_ok){
		//todo call some sort of shutdown of everything
		 return FALSE;
	}
	vbo_init();
	CHECKGLERROR
	if(!vbo_ok){
		return FALSE;
		//todo call some sort of shutdown of everything
	}
	ubo_init();
	CHECKGLERROR
	if(!ubo_ok){
		return FALSE;
		//todo call some sort of shutdown of everything
	}
	anim_init();
	CHECKGLERROR
	if(!anim_ok){
		//todo call some sort of shutdown of everything
		return FALSE;
	}
	model_init();
	CHECKGLERROR
	if(!model_ok){
		//todo call some sort of shutdown of everything
		 return FALSE;
	}
/*
	initParticleSystem(128);
	if(!particlesOK){
		//todo call some sort of shutdown of everything
		 return FALSE;
	}
*/
	light_init();
	CHECKGLERROR
	if(!light_ok){
		//todo call some sort of shutdown of everything
		return FALSE;
	}
	lighttile_init();
	CHECKGLERROR
	if(!lighttile_ok){
		//todo call some sort of shutdown of everything
		return FALSE;
	}
	viewport_init();
	CHECKGLERROR
	if(!viewport_ok){
		//todo call some sort of shutdown of everything
		return FALSE;
	}
	text_init();
	CHECKGLERROR
	if(!text_ok){
		//todo call some sort of shutdown of everything
		return FALSE;
	}
	rendermodel_init();
	CHECKGLERROR
	//todo errorcheck
	drawbb_init();
	CHECKGLERROR
	//todo errorcheck

	states_enableForce(GL_MULTISAMPLE);
	glClearDepth(1.0);
	glClearColor(0.0, 0.0, 0.0, 0.0);
	CHECKGLERROR
//	states_disableForce(GL_FOG);
	states_enableForce(GL_DEPTH_TEST);
	CHECKGLERROR
//	glDepthFunc(GL_LESS);
	states_depthFunc(GL_LESS);
	states_enableForce(GL_CULL_FACE);
	states_cullFace(GL_BACK);
//	states_depthMask(GL_TRUE);

	int maxSamples = 0, maxIntSamples = 0, maxColorTextureSamples = 0, maxDepthTextureSamples = 0;
	glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
	glGetIntegerv(GL_MAX_INTEGER_SAMPLES, &maxIntSamples);
	glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &maxColorTextureSamples);
	glGetIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES, &maxDepthTextureSamples);
	maxMSAASamples = maxSamples;
	if(maxIntSamples < maxMSAASamples) maxMSAASamples = maxIntSamples;
	if(maxColorTextureSamples < maxMSAASamples) maxMSAASamples = maxColorTextureSamples;
	if(maxDepthTextureSamples < maxMSAASamples) maxMSAASamples = maxDepthTextureSamples;
	console_printf("Max multisample samples: %i\n", maxMSAASamples);


	cam = createAndAddViewportRPOINT("cam", 1);
	camid = cam->myid;
	cam->outfbid = findFramebufferByNameRINT("screen");

	unsigned char dflags[] = {3, 7, 3};
//	unsigned char drb = FRAMEBUFFERRBFLAGSDEPTH| 2;
	unsigned char drb = FRAMEBUFFERRBFLAGSDEPTH;
	unsigned char dcount = 3;
	cam->dfbid = createAndAddFramebufferRINT("screend", dcount, drb, dflags);
	resizeViewport(cam, 800, 600);
	screenWidth = 800;
	screenHeight = 600;

	glGenBuffers(1, &instancevbo);
	glGenBuffers(1, &instancevbo2);

	//temporary
	CHECKGLERROR
	vbo_t * tvbo = createAndAddVBORPOINT("text", 2);
	textvbo = tvbo->myid;
	textshaderid = shader_createAndAddRINT("text");
	fsblendshaderid = shader_createAndAddRINT("fsblend");
	depthonlyid = shader_createAndAddRINT("depthmodel");
	forwardmodelid = shader_createAndAddRINT("forwardmodel");
	fsquadmodel = model_findByNameRINT("fsquad");

	readyRenderQueueBuffers();



	return TRUE; // so far so good
}