예제 #1
0
//Checks for a collision between the character and the passed window:
Collision Character::checkCollision(sf::Window& window) const
{	
	//Gets the sides of the character:
	float topA, bottomA, leftA, rightA;
	topA = _sprite.getGlobalBounds().top;
	bottomA = _sprite.getGlobalBounds().height + topA;
	leftA = _sprite.getGlobalBounds().left;
	rightA = _sprite.getGlobalBounds().width + leftA;

	//Top:
	if(topA < 0)
		return COLLISION_TOP;

	//Bottom:
	if(bottomA > window.getSize().y)
		return COLLISION_BOTTOM;

	//Left:
	if(leftA < 0) 
		return COLLISION_LEFT;

	//Right:
	if(rightA > window.getSize().x)
		return COLLISION_RIGHT;

	//Otherwise there is no collision:
	return COLLISION_NONE;
}
예제 #2
0
void setMatrices(const aiScene * scene) {
    // Set up the projection and model-view matrices
    GLfloat aspectRatio = (GLfloat)window.GetWidth()/window.GetHeight();
    GLfloat nearClip = 0.1f;
    GLfloat farClip = 500.0f;
    GLfloat fieldOfView = 45.0f; // Degrees
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(fieldOfView, aspectRatio, nearClip, farClip);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(current_location.x, current_location.y, current_location.z, 
              current_location.x + current_forward.x,
              current_location.y + current_forward.y,
              current_location.z + current_forward.z, 0.0f, 1.0f, 0.0f);
    
    setupLights();
        
    // Pass in our view matrix for cubemapping purposes 
    // note: this may not be the best place to actually pass it to the shader...
    int shaderNum = 1;
    GLfloat* vMatrix = new GLfloat[16];
    glGetFloatv(GL_MODELVIEW_MATRIX, vMatrix);
    
//    // Ugly, ugly, UGLY!
//    aiMatrix4x4 invertMe = aiMatrix4x4(vMatrix[0], vMatrix[1], vMatrix[2], vMatrix[3], vMatrix[4], vMatrix[5], vMatrix[6], vMatrix[7], vMatrix[8], vMatrix[9], vMatrix[10], vMatrix[11], vMatrix[12], vMatrix[13], vMatrix[14], vMatrix[15]);
//    aiMatrix4x4 inverted = invertMe.Inverse();
//    GLfloat* vInvMatrix = new GLfloat{ inverted.a1, inverted.a2, inverted.a3, inverted.a4, inverted.b1, inverted.b2, inverted.b3, inverted.b4, inverted.c1, inverted.c2, inverted.c3, inverted.c4};
    
    GLint vM = glGetUniformLocation(shaders[shaderNum]->programID(), "viewMatrix");
    glUniformMatrix4fv(vM,1,true,vMatrix);
    
    applyMatrixTransform(scene->mRootNode);
}
 SFMLApplication(): contextSettings(32), 
         window(sf::VideoMode(800, 600), "Skeletal Animation Library", sf::Style::Default, contextSettings),
         astroBoyMovingGlasses(astroBoy.model), astroBoyHeadBanging(astroBoy.model) {
     //Output bone hierarchy of astroBoy model:
     printBoneHierarchy(astroBoy.model);
     
     window.setFramerateLimit(144);
     window.setVerticalSyncEnabled(true);
     
     //Various settings
     glClearColor(0.5, 0.5, 0.5, 0.0f);
     glEnable(GL_DEPTH_TEST);
     glDepthFunc(GL_LESS);
     glEnable(GL_TEXTURE_2D);
     
     //Lighting
     GLfloat light_color[] = {0.9, 0.9, 0.9, 1.f};
     glMaterialfv(GL_FRONT, GL_DIFFUSE, light_color);
     glEnable(GL_LIGHTING);
     glEnable(GL_LIGHT0);
     
     //Setup projection matrix
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     //45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
     gluPerspective(45.0, 4.0 / 3.0, 0.1, 100.0);
     
     glMatrixMode(GL_MODELVIEW);
 }
예제 #4
0
	void handleEvents()
	{
		const sf::Input& Input = App->GetInput();
		bool shiftDown = Input.IsKeyDown(sf::Key::LShift) || Input.IsKeyDown(sf::Key::RShift);
		sf::Event Event;
		while (App->GetEvent(Event))
		{
			if (Event.Type == sf::Event::Closed)
				App->Close();
			if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
				App->Close();
			
			// This is for grading your code. DO NOT REMOVE
			if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::Space) {
				firing = 6;
			} 
			if(Event.Type == sf::Event::KeyReleased && Event.Key.Code == sf::Key::Space) {
				firing = 0;
			}

			if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::F12){
				render = RenderEngine();
				render.init();
			}

			
			if (Event.Type == sf::Event::Resized)
			{ glViewport(0, 0, Event.Size.Width, Event.Size.Height); }
		}
	}
예제 #5
0
void mainEventHandler(sf::Window &window){

        sf::Event event;
        while (window.pollEvent(event))
        {
            switch (event.type){
                case sf::Event::Closed:
                    window.close();
                    break;

                case sf::Event::KeyPressed:
                    keyPressedHandler(event);
                    break;

                case sf::Event::KeyReleased:
                    keyReleasedHandler(event);
                    break;

                case sf::Event::LostFocus:
                    /* pause(); */
                    break;

                case sf::Event::GainedFocus:
                    /* resume(); */
                    break;


                default: break;
            }
        }
        
}
예제 #6
0
void renderFrame() {
    glUseProgram(_mainShader.programID());
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f, _window.GetWidth()/_window.GetHeight(), 0.1f, 500);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    _camera.setViewTransform();
    /*
    glBegin(GL_TRIANGLES);
    glVertex2f(0.0f, 0.0f);
    glVertex2f(1.0f, 0.0f);
    glVertex2f(1.0f, 1.0f);
    glEnd();*/
    for (int i =0; i < _scene._VBOs.size(); i++) {
        Scene::VBO vbo = _scene._VBOs.at(i);
        glBindBuffer(GL_ARRAY_BUFFER, vbo.position);
        glVertexAttribPointer(_mainShader.getAttribLocationOf("positionIn"), 3, GL_FLOAT, GL_FALSE, sizeof(aiVector3D), 0);
        glBindBuffer(GL_ARRAY_BUFFER, vbo.texcoord);
        glVertexAttribPointer(_mainShader.getAttribLocationOf("texcoordIn"), 2, GL_FLOAT, GL_FALSE, sizeof(aiVector3D), 0);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.indices);
        glDrawElements(GL_TRIANGLES, vbo.numIndices, GL_UNSIGNED_INT, 0);
    }
}
예제 #7
0
파일: main.cpp 프로젝트: mwlow/flying
void inputFn()
{
	sf::Event evt;
	while (window.GetEvent(evt)) {
		if (window.GetInput().IsKeyDown(sf::Key::Down)) {
			if (max_tess > 1) max_tess -= 1;
		}
		else if(window.GetInput().IsKeyDown(sf::Key::Up)) {
			if (max_tess < 50) max_tess += 1;
		}
		switch (evt.Type) {
			case sf::Event::Closed:
				window.Close();
				break;
			case sf::Event::KeyPressed:
				fflag = evt.Key.Code;
				break;
			case sf::Event::KeyReleased:
				fflag = 0;
				if (evt.Key.Code == 'r')
					move = !move;
				break;
			case sf::Event::MouseMoved:
				mouse = vec2(evt.MouseMove.X, 
							WIN_H - evt.MouseMove.Y);
				break;
			default:
				break;
		}
	}
}
예제 #8
0
파일: Main.cpp 프로젝트: mrotondo/ccrma
void setMatrices()
{
    // Set up the projection and model-view matrices
    GLfloat aspectRatio = (GLfloat)window.GetWidth()/window.GetHeight();
    GLfloat nearClip = 0.1f;
    GLfloat farClip = 500.0f;
    GLfloat fieldOfView = 45.0f; // Degrees

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(fieldOfView, aspectRatio, nearClip, farClip);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0.0, 0.0, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);

    glPushMatrix(); // set the light in the scene correctly
    transNode(cathedralScene, cathedralScene->mRootNode);
    GLfloat light0_position[] = { 0, 30, 0, 0 };
    glLightfv( GL_LIGHT0, GL_POSITION, light0_position );
    GLfloat light1_position[] = { 0, 11, 0, 0.0 };
    glLightfv( GL_LIGHT1, GL_POSITION, light1_position );
    glPopMatrix();

    glRotatef(rad_to_deg(pitch), 1.0, 0.0, 0.0);
    glRotatef(rad_to_deg(yaw), 0.0, 1.0, 0.0);
    glTranslatef(position.x, position.y, position.z);

    // We store the modelview matrix here, but it's actually the view matrix because we haven't done any model transforms yet
//    static double viewMatrix[16];
    GLfloat *viewMatrix = new GLfloat[16];
    glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix);
    GLint inverseViewMatrixUniform = glGetUniformLocation(envMapShader->programID(), "inverseViewMatrix");
    glUniformMatrix4fv(inverseViewMatrixUniform, 1, true, viewMatrix);
    delete [] viewMatrix;
}
예제 #9
0
void video::saveImage(sf::Window &app, int framerate)
{
  if (!app.isOpen())
    return ;
  sf::Vector2u size = app.getSize();
  if (videoTexture.getSize().y != size.y)
    videoTexture.create(size.x, size.y);

  if (videoTimer.getElapsedTime().asMilliseconds() > 1000/framerate)
    {
      videoTimer.restart();

      std::ostringstream videoFramePath;

      videoFramePath << "/tmp/gl-engine-"
		     << std::setw(5)
		     << std::setfill('0')
		     << currentVideoFrame
		     << ".jpg";
      videoTexture.update(app);
      sf::Image videoImage = videoTexture.copyToImage();
      videoImage.saveToFile(videoFramePath.str());
      currentVideoFrame++;
    }
}
예제 #10
0
파일: Main.cpp 프로젝트: OliviaXu/AMazing
void initOpenGL() {
    // Initialize GLEW on Windows, to make sure that OpenGL 2.0 is loaded
#ifdef FRAMEWORK_USE_GLEW
    GLuint error = glewInit();
    if (GLEW_OK != error) {
        std::cerr << glewGetErrorString(error) << std::endl;
        exit(-1);
    }
    if (!GLEW_VERSION_2_0 || !GL_EXT_framebuffer_object) {
        std::cerr << "This program requires OpenGL 2.0 and FBOs" << std::endl;
        exit(-1);
    }
#endif

    // This initializes OpenGL with some common defaults.  More info here:
    // http://www.sfml-dev.org/tutorials/1.6/window-opengl.php
    glClearDepth(1.0f);
    //glClearColor(0.529f, 0.808f, 0.980f, 1.0f);//sky blue
	//glClearColor(0.529f, 0.808f, 0.980f, 1.0f);//sky blue
	glClearColor(0.15f, 0.15f, 0.15f, 1.0f);//sky blue
    glEnable(GL_DEPTH_TEST);

	GL_CHECK(glEnable(GL_TEXTURE_2D));
    glViewport(0, 0, window.GetWidth(), window.GetHeight());
}
예제 #11
0
파일: Main.cpp 프로젝트: sylvon/AMazing
int main(int argc, char** argv) {
    // Put your game loop here (i.e., render with OpenGL, update animation)
    while (window.IsOpened()) {
        window.Display();
    }

    return 0;
}
예제 #12
0
파일: main.cpp 프로젝트: mwlow/flying
void init(int argc, const char **argv)
{
	assert(glewInit() == GLEW_OK);
	assert(GLEW_VERSION_2_0 || GL_EXT_framebuffer_object);
	glClearDepth(1.0f);
    glClearColor(0.15f, 0.15f, 0.15f, 1.0f);
    glEnable(GL_DEPTH_TEST);
    glViewport(0, 0, window.GetWidth(), window.GetHeight());
}
    void start() {
        std::chrono::time_point<std::chrono::system_clock> startTime=std::chrono::system_clock::now();

        //Event thread (main thread)
        bool running = true;
        while (running) {
            sf::Event event;
            while (window.pollEvent(event)) {
                if (event.type == sf::Event::KeyPressed) {
                    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) {
                        window.close();
                        running=false;
                    }
                }
                else if (event.type == sf::Event::Closed) {
                    window.close();
                    running = false;
                }
            }
            
            std::chrono::duration<double> elapsed_seconds = std::chrono::system_clock::now() - startTime;
            double time=elapsed_seconds.count();
            
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glLoadIdentity();
        
            gluLookAt(0.0, 30.0, -65.0, //Camera position in World Space
                      0.0, 5.0, 0.0,    //Camera looks towards this position
                      0.0, 1.0, 0.0);   //Up
        
            glPushMatrix();
            glRotatef(-time*50.0, 0.0, 1.0, 0.0);
            glTranslatef(20.0, 0.0, 0.0);            
            unanimatedAstroBoy.draw();
            glPopMatrix();
            
            glPushMatrix();
            glRotatef(-time*50.0+90.0, 0.0, 1.0, 0.0);
            glTranslatef(20.0, 0.0, 0.0);            
            astroBoy.drawFrame(time);
            glPopMatrix();
            
            glPushMatrix();
            glRotatef(-time*50.0+180.0, 0.0, 1.0, 0.0);
            glTranslatef(20.0, 0.0, 0.0);            
            astroBoyMovingGlasses.drawFrame(time);
            glPopMatrix();
            
            glRotatef(-time*50.0+270.0, 0.0, 1.0, 0.0);
            glTranslatef(20.0, 0.0, 0.0);            
            astroBoyHeadBanging.drawFrame(time);
            
            //Swap buffer (show result)
            window.display();
        }
    }
예제 #14
0
파일: main.cpp 프로젝트: emint/scratch
int main() {
  Renderable3DS object("models/cat-braizer.3ds");
  object.printInfo();
  while (window.IsOpened()) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    handleInput();
    createView();
    object.render();
    window.Display();
  }
}
예제 #15
0
void
windowEvents ( sf::Window& window)
{
    sf::Event e;

    while ( window.pollEvent ( e ) ) {
        if ( e.type == sf::Event::Closed ) {
            window.close();
        }
    }
}
예제 #16
0
int main(int argc, const char * argv[]) {
    initGL();
    loadShader();
    _scene.initialize("current_mesh_texture.ply");
    InputHandler inputHandler(_window, _window.GetInput(), &_camera);
    while (_window.IsOpened()) {
        inputHandler.handleInput();
        renderFrame();
        _window.Display();
    }
    return 0;
}
예제 #17
0
파일: main.cpp 프로젝트: mwlow/flying
void setPerspective()
{

	mat4 r;
	switch (fflag) {
		case 'a':
		case 'q': dir = rot(-ROT_SPEED * bank * abs(bank) / 50 / 50, dir); 
				  if (bank < MAX_BANK) {
				      r = glm::rotate(mstack.top(), BANK_SPEED, glm::vec3(0.0f, 0.0f, 1.0f));
				      mstack.pop();
				      mstack.push(r);
				      bank += BANK_SPEED ;
				  }
				  break;
		case 'd':
		case 'e': 
				  dir = rot(-ROT_SPEED * bank * abs(bank) / 50 / 50, dir);
				  if (bank > -MAX_BANK) {
					  r = glm::rotate(mstack.top(), -BANK_SPEED, glm::vec3(0.0f, 0.0f, 1.0f));
					  mstack.pop();
					  mstack.push(r);
				      bank -= BANK_SPEED;
			      }
				  break;
		default:
				  if (speed_multiplier > 0.2 && fflag == 's') speed_multiplier -= 0.01;
		          if (speed_multiplier < 4.0 && fflag == 'w') speed_multiplier += 0.01;

				  if (bank < BANK_SPEED && bank > -BANK_SPEED) {
					  r = glm::rotate(mstack.top(), -bank, glm::vec3(0.0f, 0.0f, 1.0f));
					  bank = 0;
				  }
				  else {
					  dir = rot(-ROT_SPEED * bank * abs(bank) / 50 / 50, dir);
					  r = glm::rotate(mstack.top(), -bank * BANK_SPEED / 40, glm::vec3(0.0f, 0.0f, 1.0f));
					  bank += -bank * BANK_SPEED / 40;
				  }
				  mstack.pop();
				  mstack.push(r);
				  break;
	}
	
	if (move)
		eye += vec2(dir.x * PLANE_SPEED, dir.y * PLANE_SPEED);
	


	g_projection = glm::perspective(45.0f, 
						(GLfloat)window.GetWidth()/window.GetHeight(), 0.1f, 175.0f);
	g_modelview = glm::lookAt(vec3(eye.x, 5, eye.y), vec3(eye.x+dir.x, 4.7, eye.y+dir.y), vec3(0, 1, 0));
	
}
예제 #18
0
void pollEvents()
{
	sf::Event windowEvent;
	while (window.pollEvent(windowEvent))
	{
		switch (windowEvent.type)
		{
		case sf::Event::Closed:
			window.close();
			break;
		}
	}
}
예제 #19
0
파일: main.cpp 프로젝트: mwlow/flying
int main(int argc, const char **argv)
{	
	init(argc, argv);
	loadAssets();
	while (window.IsOpened()) {
		clockdiff = clck.GetElapsedTime();
		elapsed += clockdiff;
		clck.Reset();
		inputFn();
		renderFn();
		window.Display();
	}
	return 0;
}
예제 #20
0
파일: Main.cpp 프로젝트: mrotondo/ccrma
int main(int argc, char** argv) {

    initOpenGL();
    loadAssets();

    // Put your game loop here (i.e., render with OpenGL, update animation)
    while (window.IsOpened()) {
        handleInput();
        renderFrame();
        window.Display();
    }

    return 0;
}
예제 #21
0
	void renderLoop(sf::Window & window)
	{
		sf::Clock time;
		WorldState state;
		
		while (state.isRunning())
		{
			this->handleEvents(window, state);
			state.timeStep( time.getElapsedTime().asSeconds() );
			engine.display(state);
			window.display();
		}
		window.close();
	}
예제 #22
0
파일: Main.cpp 프로젝트: mrotondo/ccrma
void initOpenGL() {
    // Initialize GLEW on Windows, to make sure that OpenGL 2.0 is loaded
#ifdef FRAMEWORK_USE_GLEW
    GLint error = glewInit();
    if (GLEW_OK != error) {
        std::cerr << glewGetErrorString(error) << std::endl;
        exit(-1);
    }
    if (!GLEW_VERSION_2_0 || !GL_EXT_framebuffer_object) {
        std::cerr << "This program requires OpenGL 2.0 and FBOs" << std::endl;
        exit(-1);
    }
#endif

    // This initializes OpenGL with some common defaults.  More info here:
    // http://www.sfml-dev.org/tutorials/1.6/window-opengl.php
    glClearDepth(1.0f);
    glClearColor(0.15f, 0.15f, 0.15f, 1.0f);
    glEnable(GL_DEPTH_TEST);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
    glViewport(0, 0, window.GetWidth(), window.GetHeight());

    position = aiVector3D(35.0, -20.0, 0.0);
    yaw = M_PI * 3 / 2.0;
    pitch = -M_PI / 7;

    GLfloat light0_position[] = { 0.0, 30.0, 0.0, 0.0 };
    GLfloat light0_ambient[] = { 245/2550.0, 222/2550.0, 179/2550.0, 1 };
    GLfloat light0_diffuse[] = { 245/255.0, 232/255.0, 199/255.0, 1 };
    GLfloat light0_specular[] = { 0.7, 0.7, 0.7, 1 };
    GLfloat shininess = 90;
    glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
    glLightfv( GL_LIGHT0, GL_AMBIENT, light0_ambient );
    glLightfv( GL_LIGHT0, GL_DIFFUSE, light0_diffuse );
    glLightfv( GL_LIGHT0, GL_SPECULAR, light0_specular );
    glLightfv( GL_LIGHT0, GL_SHININESS, &shininess );
    glEnable(GL_LIGHT0);

    GLfloat light1_position[] = { 0, 11, 0, 0.0 };
    GLfloat light1_diffuse[] = { 145/2550.0, 222/2550.0, 149/2550.0, 1 };
    GLfloat light1_specular[] = { 0.1, 0.1, 0.1, 1 };
    glLightfv( GL_LIGHT1, GL_POSITION, light1_position );
    glLightfv( GL_LIGHT1, GL_DIFFUSE, light1_diffuse );
    glLightfv( GL_LIGHT1, GL_SPECULAR, light1_specular );
    glEnable(GL_LIGHT1);

    depthRenderTarget = new DepthRenderTarget(RENDER_WIDTH * SHADOW_MAP_RATIO, RENDER_HEIGHT * SHADOW_MAP_RATIO);
}
예제 #23
0
파일: main.cpp 프로젝트: emint/scratch
void createView() {
  // Set up the projection and model-view matrices
  GLfloat aspectRatio = (GLfloat) window.GetWidth() / window.GetHeight();
  GLfloat nearClip = 0.1f;
  GLfloat farClip = 500.0f;
  GLfloat fieldOfView = 45.0f; // Degrees

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(fieldOfView, aspectRatio, nearClip, farClip);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  gluLookAt(cameraX, cameraY, cameraZ, 0, 0, 0, 0, 1, 0);

}
예제 #24
0
////////////////////////////////////////////////////////////
/// Initialize OpenGL states into the specified view
///
/// \param Window Target window to initialize
///
////////////////////////////////////////////////////////////
void initialize(sf::Window& window)
{
    // Activate the window
    window.setActive();

    // Setup OpenGL states
    // Set color and depth clear value
    glClearDepth(1.f);
    glClearColor(0.f, 0.5f, 0.5f, 0.f);

    // Enable Z-buffer read and write
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);

    // Setup a perspective projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    static const double pi = 3.141592654;
    GLdouble extent = std::tan(90.0 * pi / 360.0);
    glFrustum(-extent, extent, -extent, extent, 1.0, 500.0);

    // Enable position and texture coordinates vertex components
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
}
void init()
{
	sf::ContextSettings settings;
	settings.depthBits = 24;
	settings.stencilBits = 8;
	settings.antialiasingLevel = 2;

	window.create(sf::VideoMode(800, 600), "Bezier_Spline_Wireframe", sf::Style::Close, settings);

	glewExperimental = true;
	glewInit();

	initShaders();

	// Store the data for the triangles in a buffer that the gpu can use to draw
	glGenVertexArrays(1, &vao0);
	glBindVertexArray(vao0);

	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

	glGenBuffers(1, &ebo0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo0);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);

	// Bind buffer data to shader values
	posAttrib = glGetAttribLocation(shaderProgram, "position");
	glEnableVertexAttribArray(posAttrib);
	glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);

	glGenVertexArrays(1, &vao1);
	glBindVertexArray(vao1);

	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

	glGenBuffers(1, &ebo1);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo1);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(outlineElements), outlineElements, GL_STATIC_DRAW);

	// Bind buffer data to shader values
	posAttrib = glGetAttribLocation(shaderProgram, "position");
	glEnableVertexAttribArray(posAttrib);
	glVertexAttribPointer(posAttrib, 3, GL_FLOAT, GL_FALSE, 0, 0);

	timer.restart();

	time_t timer;
	time(&timer);
	srand((unsigned int)timer);

	generateTeapot();

	InputManager::Init(&window);
	CameraManager::Init(800.0f / 600.0f, 60.0f, 0.1f, 100.0f);

	glEnable(GL_DEPTH_TEST);
}
예제 #26
0
파일: camera.cpp 프로젝트: rokn/GEAR
	void Camera::FreeFlyControl(const sf::Window& window, sf::Time elapsedTime)
	{
		if(sf::Keyboard::isKeyPressed(sf::Keyboard::A))
		{
			Move(GEAR::LEFT, elapsedTime.asSeconds());
		}
		if(sf::Keyboard::isKeyPressed(sf::Keyboard::D))
		{
			Move(GEAR::RIGHT, elapsedTime.asSeconds());
		}
		if(sf::Keyboard::isKeyPressed(sf::Keyboard::S))
		{
			Move(GEAR::BACKWARD, elapsedTime.asSeconds());
		}
		if(sf::Keyboard::isKeyPressed(sf::Keyboard::W))
		{
			Move(GEAR::FORWARD, elapsedTime.asSeconds());
		}
		
		sf::Vector2u screenSize = window.getSize();
		sf::Vector2i windowCenterPos(screenSize.x/2,screenSize.y/2);
		
		sf::Vector2i mouseOffset = sf::Mouse::getPosition(window) - windowCenterPos;
		
		Turn(mouseOffset.x * SENSITIVITY, -mouseOffset.y * SENSITIVITY);
	}
예제 #27
0
	void EventBuffer::pollEvents(sf::Window& window)
	{
		sf::Event event;

		while (window.pollEvent(event))
			pushEvent(event);
	}
예제 #28
0
bool updatePlayer(){
	vec2 pos;
	pos = player.pos;
	sf::Event event;


	while (window.pollEvent(event)){
		while (event.type != sf::Event::KeyPressed){
		    switch (event.key.code){
		    	case sf::Keyboard::W:
	   			pos.y--;
		    	break;
		    	case sf::Keyboard::A:
				pos.x--;
		    	break;
		    	case sf::Keyboard::S:
				pos.y++;
		    	break;
		    	case sf::Keyboard::D:
				pos.x++;
		    	break;
		    	default:
		    	return false;
		    }
		}
	}

	if (arborArray[pos.x][pos.y] == '.'){
		updateWolf();
		player.pos = pos;
		arborArray[player.pos.x][player.pos.y] = '@';	
		return true;
	}
	return false;
}
예제 #29
0
파일: Engine.cpp 프로젝트: sindney/fury3d
	bool Engine::Initialize(sf::Window &window, int numThreads, LogLevel level, const char* logfile,
		bool console, const LogFormatter &formatter, bool append)
	{
		Log<0>::Initialize(std::move(level), std::move(logfile), std::move(console), formatter, std::move(append));

		ThreadUtil::Initialize(std::move(numThreads));
		ThreadUtil::Instance()->SetMainThread();

		FURYD << ThreadUtil::Instance()->GetWorkerCount() << " thread launched!";

		MeshUtil::m_UnitQuad = MeshUtil::CreateQuad("quad_mesh", Vector4(-1.0f, -1.0f, 0.0f), Vector4(1.0f, 1.0f, 0.0f));
		MeshUtil::m_UnitCube = MeshUtil::CreateCube("cube_mesh", Vector4(-1.0f), Vector4(1.0f));
		MeshUtil::m_UnitIcoSphere = MeshUtil::CreateIcoSphere("ico_sphere_mesh", 1.0f, 2);
		MeshUtil::m_UnitSphere = MeshUtil::CreateSphere("sphere_mesh", 1.0f, 20, 20);
		MeshUtil::m_UnitCylinder = MeshUtil::CreateCylinder("cylinder_mesh", 1.0f, 1.0f, 1.0f, 4, 10);
		MeshUtil::m_UnitCone = MeshUtil::CreateCylinder("cone_mesh", 0.0f, 1.0f, 1.0f, 4, 10);

		InputUtil::Initialize(window.getSize().x, window.getSize().y);

#ifdef _FURY_FBXPARSER_IMP_
		FbxParser::Initialize();
#endif

		int flag = gl::LoadGLFunctions();

		RenderUtil::Initialize();

		BufferManager::Initialize();

#ifdef _FURY_GUI_IMP_
		Gui::Initialize(&window);
#endif

		if (flag == 1)
			return true;

		if (flag < 1)
		{
			FURYE << "Failed to load gl functions.";
		}
		else
		{
			FURYE << "Failed to load " << flag - 1 << " gl functions.";
		}

		return false;
	}
예제 #30
0
void Init(sf::Window& window, sf::RenderTarget& target, bool loadDefaultFont)
{
    ImGui::CreateContext();
    ImGuiIO& io = ImGui::GetIO();

    io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos;

    // init keyboard mapping
    io.KeyMap[ImGuiKey_Tab] = sf::Keyboard::Tab;
    io.KeyMap[ImGuiKey_LeftArrow] = sf::Keyboard::Left;
    io.KeyMap[ImGuiKey_RightArrow] = sf::Keyboard::Right;
    io.KeyMap[ImGuiKey_UpArrow] = sf::Keyboard::Up;
    io.KeyMap[ImGuiKey_DownArrow] = sf::Keyboard::Down;
    io.KeyMap[ImGuiKey_PageUp] = sf::Keyboard::PageUp;
    io.KeyMap[ImGuiKey_PageDown] = sf::Keyboard::PageDown;
    io.KeyMap[ImGuiKey_Home] = sf::Keyboard::Home;
    io.KeyMap[ImGuiKey_End] = sf::Keyboard::End;
    io.KeyMap[ImGuiKey_Insert] = sf::Keyboard::Insert;
#ifdef ANDROID
    io.KeyMap[ImGuiKey_Backspace] = sf::Keyboard::Delete;
#else
    io.KeyMap[ImGuiKey_Delete] = sf::Keyboard::Delete;
    io.KeyMap[ImGuiKey_Backspace] = sf::Keyboard::BackSpace;
#endif
    io.KeyMap[ImGuiKey_Space] = sf::Keyboard::Space;
    io.KeyMap[ImGuiKey_Enter] = sf::Keyboard::Return;
    io.KeyMap[ImGuiKey_Escape] = sf::Keyboard::Escape;
    io.KeyMap[ImGuiKey_A] = sf::Keyboard::A;
    io.KeyMap[ImGuiKey_C] = sf::Keyboard::C;
    io.KeyMap[ImGuiKey_V] = sf::Keyboard::V;
    io.KeyMap[ImGuiKey_X] = sf::Keyboard::X;
    io.KeyMap[ImGuiKey_Y] = sf::Keyboard::Y;
    io.KeyMap[ImGuiKey_Z] = sf::Keyboard::Z;

    io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
    s_joystickId = getConnectedJoystickId();

    for (unsigned int i = 0; i < ImGuiNavInput_COUNT; i++) {
        s_joystickMapping[i] = NULL_JOYSTICK_BUTTON;
    }

    initDefaultJoystickMapping();

    // init rendering
    io.DisplaySize = static_cast<sf::Vector2f>(target.getSize());

    if (s_fontTexture) { // delete previously created texture
        delete s_fontTexture;
    }
    s_fontTexture = new sf::Texture;

    if (loadDefaultFont) {
        // this will load default font automatically
        // No need to call AddDefaultFont
        UpdateFontTexture();
    }

    s_windowHasFocus = window.hasFocus();
}