本文整理汇总了C++中sf::Window类的典型用法代码示例。如果您正苦于以下问题:C++ Window类的具体用法?C++ Window怎么用?C++ Window使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Window类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: checkCollision
//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: mainEventHandler
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;
}
}
}
示例3: saveImage
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++;
}
}
示例4: initOpenGL
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());
}
示例5: windowEvents
void
windowEvents ( sf::Window& window)
{
sf::Event e;
while ( window.pollEvent ( e ) ) {
if ( e.type == sf::Event::Closed ) {
window.close();
}
}
}
示例6: setMatrices
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);
}
示例7: SFMLApplication
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);
}
示例8: handleEvents
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); }
}
}
示例9: renderFrame
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);
}
}
示例10: inputFn
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;
}
}
}
示例11: setMatrices
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;
}
示例12: main
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;
}
示例13: init
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());
}
示例14: start
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();
}
}
示例15: main
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();
}
}