static cl::Context PlatformContext(cl_device_type device_type, char* platform_vendor_name, bool enable_gl_interop = false) { cl_uint numPlatforms; cl_platform_id platform = NULL; clGetPlatformIDs(0, NULL, &numPlatforms); if (numPlatforms > 0) { cl_platform_id* platforms = new cl_platform_id[numPlatforms]; clGetPlatformIDs(numPlatforms, platforms, NULL); for (unsigned i = 0; i < numPlatforms; ++i) { char pbuf[100]; clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, sizeof(pbuf), pbuf, NULL); platform = platforms[i]; std::cout << "platform: " << pbuf << std::endl; if (!strcmp(pbuf, platform_vendor_name)) { break; } } delete[] platforms; } if (enable_gl_interop) { // Define OS-specific context properties and create the OpenCL context #if defined (__APPLE__) CGLContextObj kCGLContext = CGLGetCurrentContext(); CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext); cl_context_properties cps[] = { CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)kCGLShareGroup, 0 }; #else #if defined(linux) cl_context_properties cps[] = { CL_GL_CONTEXT_KHR, cl_context_properties(glXGetCurrentContext()), CL_GLX_DISPLAY_KHR, cl_context_properties(glXGetCurrentDisplay()), CL_CONTEXT_PLATFORM, cl_context_properties(platform), 0 }; #else // Win32 cl_context_properties cps[] = { CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(), CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(), CL_CONTEXT_PLATFORM, (cl_context_properties)platform, 0 }; #endif #endif cl::Platform _platform(platform); cl::vector<cl::Device> *_devices = new cl::vector<cl::Device>(); _platform.getDevices(CL_DEVICE_TYPE_GPU, _devices); if(_devices->size() > 1) _devices->pop_back(); if (platform == NULL) return cl::Context(device_type, NULL); else return cl::Context(*_devices,cps); return (NULL == platform) ? cl::Context(device_type, NULL) : cl::Context(*_devices, cps); }else //no opengl interoperability { cl_context_properties cps[] = { CL_CONTEXT_PLATFORM, cl_context_properties(platform), 0 }; return (NULL == platform) ? cl::Context(device_type, NULL) : cl::Context(device_type, cps); } }
int main() { std::map<std::string, std::string> _texts = std::map<std::string, std::string>(); std::vector<GameObject*> _gameObjects = std::vector<GameObject*>(); sf::RenderWindow window(sf::VideoMode(800, 600), "Collision test"); /* sf::Texture _bkg; _bkg.loadFromFile("gorge.jpg"); _bkg.setRepeated(true); sf::Sprite _background(_bkg, sf::IntRect(0, 0, 2000, 1000)); */ if(load("Brown_Rocks.png", sf::Vector2u(32, 32), nullptr, 800, 600)) std::cout << "YEAH\n"; sf::Texture _bkg; _bkg.loadFromFile("Brown_Rocks.png"); _bkg.setRepeated(true); sf::Sprite _background(_bkg, sf::IntRect(0, 0, 2000, 1000)); std::cout << sf::Texture::getMaximumSize() << "\n"; sf::Texture _cliffsTexture; _cliffsTexture.loadFromFile("Cliffs.png"); _cliffsTexture.setRepeated(true); sf::Sprite _cliffsBottom(_cliffsTexture); sf::Sprite _cliffsTop(_cliffsTexture, sf::IntRect(0, 400, 800, -800)); _cliffsTop.setPosition(-300, 0); std::cout << _cliffsTexture.getSize().x << "," << _cliffsTexture.getSize().y; sf::Texture _platformTexture; _platformTexture.loadFromFile("Rocks_Platform1.png"); _platformTexture.setRepeated(true); sf::Sprite _platform(_platformTexture, sf::IntRect(0, 0, 2000, 32)); _platform.setPosition(0, window.getSize().y - 32); sf::Sprite _platformBottom(_platformTexture, sf::IntRect(0, 32, 2000, -32)); _platformBottom.setPosition(0, 0); sf::Texture texture; texture.loadFromFile("plane.png"); //texture.loadFromFile("player.png"); GameObject _player(texture); _player.setPosition(window.getSize().x / 2.f - 300, window.getSize().y / 2.f - 75); _gameObjects.push_back(&_player); sf::Texture etexture; etexture.loadFromFile("plane.png"); //sf::IntRect textRect(64, 0, -64, 32); //GameObject _enemy(etexture, textRect); GameObject _enemy(etexture); _enemy.setPosition(window.getSize().x / 2.f + 75, window.getSize().y / 2.f - 16); _gameObjects.push_back(&_enemy); sf::RectangleShape _bounding1(sf::Vector2f(_player.getBoundingBox().width - 1, _player.getBoundingBox().height - 1)); _bounding1.setPosition(_player.getPosition()); _bounding1.setFillColor(sf::Color::Transparent); _bounding1.setOutlineColor(sf::Color::Red); _bounding1.setOutlineThickness(1); sf::RectangleShape _bounding2(sf::Vector2f(_enemy.getBoundingBox().width - 1, _enemy.getBoundingBox().height - 1)); _bounding2.setPosition(_enemy.getPosition()); _bounding2.setFillColor(sf::Color::Transparent); _bounding2.setOutlineColor(sf::Color::Red); _bounding2.setOutlineThickness(1); sf::Font font; font.loadFromFile("VeraMono.ttf"); sf::Text _text("Debug", font, 12); _text.setPosition(0, 0); sf::Clock clock; sf::Time timeSinceLastUpdate = sf::Time::Zero; // Start the game loop while (window.isOpen()) { sf::Time elapsedTime = clock.restart(); timeSinceLastUpdate += elapsedTime; while (timeSinceLastUpdate > TimePerFrame) { timeSinceLastUpdate -= TimePerFrame; // Process events sf::Event event; while (window.pollEvent(event)) { // Close window : exit if (event.type == sf::Event::Closed) window.close(); if(event.type == sf::Event::KeyPressed) { short id = 1; for( auto& i : _gameObjects ) { i->update(event, id); id++; } } } if(checkCollisions(_gameObjects, _texts)) _texts["Collision"] = "Detected"; else _texts["Collision"] = "NOT Detected"; std::map<std::string, std::string>::iterator i = _texts.begin(); std::stringstream ss; for( ; i != _texts.end(); ++i ) { ss << i->first << ": " << i->second << std::endl << std::endl; } _text.setString(ss.str()); } _bounding1.setPosition(_player.getPosition()); _bounding2.setPosition(_enemy.getPosition()); _statisticsUpdateTime += elapsedTime; _statisticsNumFrames += 1; if (_statisticsUpdateTime >= sf::seconds(1.0f)) { std::stringstream fps, timeupdate; fps << _statisticsNumFrames; timeupdate << _statisticsUpdateTime.asMicroseconds() / _statisticsNumFrames; _statisticsUpdateTime -= sf::seconds(1.0f); _statisticsNumFrames = 0; _texts["FPS"] = fps.str() + "\n" + "Time / Update = " + timeupdate.str() + "us"; } window.clear(); window.draw(_background); // window.draw(m_vertices, &m_tileset); window.draw(_cliffsBottom); window.draw(_cliffsTop); window.draw(_platform); window.draw(_platformBottom); for( auto& i : _gameObjects ) { window.draw(*i); } window.draw(_text); window.draw(_bounding1); window.draw(_bounding2); window.display(); } }