本文整理汇总了C++中sf::RenderTexture::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ RenderTexture::clear方法的具体用法?C++ RenderTexture::clear怎么用?C++ RenderTexture::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::RenderTexture
的用法示例。
在下文中一共展示了RenderTexture::clear方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: draw
void draw(sf::RenderTarget &tg)
{
if (first)
{
rt.clear();
rt.draw(sprite);
rt.draw(logo);
if (logo.getPosition().y == 0.0)rt.draw(press);
if (check && timer.getElapsedTime().asSeconds() < 1)
{
if ((int)(rand() % 10) == 3) rt.clear(sf::Color::White);
}
}
else
{
rt.clear(sf::Color::White);
rt.draw(system);
rt.draw(back2);
rt.draw(pointer);
}
rt.display();
sm.draw(rt, tg);
if (first) tg.draw(v);
};
示例2: run
void run()
{
while (m_window.isOpen())
{
sf::Event event;
while (m_window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
m_window.close();
}
// Update the position of the 'flashlight' to the current mouse position
m_pos = static_cast<sf::Vector2f>(sf::Mouse::getPosition(m_window));
m_flashlight.setPosition(m_pos);
// Stance-out the 'flashlight' circle
m_layer.clear();
m_layer.draw(m_flashlight, sf::BlendMultiply);
m_layer.display();
m_window.clear(sf::Color::Blue);
// Draw the layer sprite on top of the 'scene'
m_window.draw(m_rect);
m_window.draw(m_sprite);
m_window.display();
}
}
示例3: render
bool AppState::render(sf::RenderTexture& texture, int frame)
{
texture.clear();
if (m_preDesktopRenderFunctor) m_preDesktopRenderFunctor(texture, frame);
the_desktop.render(texture, frame);
if (m_postDesktopRenderFunctor) m_postDesktopRenderFunctor(texture, frame);
texture.display();
return true;
}
示例4: generateSpot
void generateSpot()
{
m_flashlightTexture.clear();
// Draw 6 circles with increasing transparency
for (unsigned int i = 0; i < 6; ++i)
{
sf::CircleShape temp(30.f - (i*2.f));
temp.setOrigin(sf::Vector2f(30.f - (i*2.f), 30.f - (i*2.f)));
temp.setFillColor(sf::Color(255, 255, 255, 101 - (i * 20)));
temp.setPosition(sf::Vector2f(30.f, 30.f));
m_flashlightTexture.draw(temp, sf::BlendNone);
}
//m_flashlightTexture.display();
}
示例5: vertices
void draw (sf::RenderTarget & target, sf::RenderStates states = sf::RenderStates::Default) const
{
lightBuffer.clear();
texture.display();
states.texture = &texture.getTexture();
for (const auto & light : lights)
{
light.draw(lightBuffer, getView(), states);
}
sf::Vector2f dimensions = sf::Vector2f(texture.getSize());
sf::VertexArray vertices(sf::Quads, 4);
vertices[0] = sf::Vertex(sf::Vector2f(0.f, 0.f), sf::Color(255, 255, 255, minAlpha), sf::Vector2f(0.f, 0.f));
vertices[1] = sf::Vertex(sf::Vector2f(dimensions.x, 0.f), sf::Color(255, 255, 255, minAlpha), sf::Vector2f(dimensions.x, 0.f));
vertices[2] = sf::Vertex(dimensions, sf::Color(255, 255, 255, minAlpha), dimensions);
vertices[3] = sf::Vertex(sf::Vector2f(0.f, dimensions.y), sf::Color(255, 255, 255, minAlpha), sf::Vector2f(0.f, dimensions.y));
lightBuffer.draw(vertices, states);
lightBuffer.display();
target.draw(sf::Sprite(lightBuffer.getTexture()));
}
示例6:
void clear (const sf::Color & color = sf::Color::Black)
{
texture.clear(color);
}
示例7: onRender
void onRender(sf::RenderWindow &window, double time, double deltaTime)
{
double thermalViewYawRange = thermalViewPitchRange/windowHeight*windowWidth;
double vxmin = 0.0;//viewYaw-thermalViewYawRange/2.0;
double vxmax = 360.0;//viewYaw+thermalViewYawRange/2.0;
double vymin = 0;//viewPitch-thermalViewPitchRange/2.0;
double vymax = thermalObservedPitchRange;//viewPitch+thermalViewPitchRange/2.0;
double cursorTemp = 0.0;
double cursorOverlap = 0.0;
window.clear(sf::Color::Black);
sf::RectangleShape pixel;
//pixel.setSize(sf::Vector2f(thermalViewPixelSize, thermalViewPixelSize));
if(sf::Keyboard::isKeyPressed(sf::Keyboard::P)) {
viewImage.clear();
for(int px = 0; px < windowWidth; px += thermalViewPixelSize) {
for(int py = 0; py < windowHeight; py += thermalViewPixelSize) {
updatedPixels.push_back(sf::Vector2<int>(px, py));
}
}
} else if(sf::Keyboard::isKeyPressed(sf::Keyboard::C)) {
/*std::vector<RectTree<SensorReading>::RectResult> resList;
readingsTree.retrieveAllRects(resList);
readingsTree.removeResults(resList);*/
viewImage.clear();
readingsTree.reset(0.0, 0.0, 360.0, thermalObservedPitchRange, 4);
}
//std::deque< sf::Vector2<int> >::iterator iter = updatedPixels.begin();
auto iter = updatedPixels.begin();
for(; iter != updatedPixels.end(); iter++) {
int px = iter->x, py = iter->y;
double vx = vxmin+(vxmax-vxmin)*((double)px/(double)windowWidth );
double vy = vymin+(vymax-vymin)*((double)py/(double)windowHeight);
double vw = thermalPixelSizeYaw;
double vh = thermalPixelSizePitch;
std::vector<RectTree<SensorReading>::RectResult> resList;
readingsTree.findRectsAtPoint(vx, vy, resList);
std::vector<RectTree<SensorReading>::RectResult> delList;
pixel.setPosition(sf::Vector2f(px, py));
pixel.setSize(sf::Vector2f(
thermalViewPixelSize,
thermalViewPixelSize //(double)thermalViewPixelSize/(double)windowWidth*(double)windowHeight
));
double temp = 0.0; int count = 0; double sum = 0;
RectTree<SensorReading>::RectResult *oldestRes = NULL; double oldestTime = 0.0;
std::vector<RectTree<SensorReading>::RectResult>::iterator iter = resList.begin();
for(; iter != resList.end(); iter++) {
RectTree<SensorReading>::RectResult &res = *iter;
double age = time-res.rect->value.time;
/*if(res.rect->value.time < oldestTime || oldestRes == NULL) {
oldestTime = res.rect->value.time;
oldestRes = &res;
}*/
double ageScalar = 1.0/(1.0+age);
temp += res.rect->value.temp*ageScalar;
sum += ageScalar;
count++;
}
if(count > 40) {
delList.insert(delList.end(), resList.begin(), resList.begin()+10);
}
temp /= sum;
if(count > 0) {
pixel.setFillColor(getThermalPixelColor(temp));
} else {
pixel.setFillColor(sf::Color::Black);
}
viewImage.draw(pixel);
if(
cursorX > px && cursorX < px+thermalViewPixelSize
&& cursorY > py && cursorY < py+thermalViewPixelSize
) {
cursorTemp = temp;
}
readingsTree.removeResults(delList);
}
int updatedPixelCount = updatedPixels.size();
updatedPixels.clear();
viewImage.display();
sf::Sprite sprite(viewImage.getTexture());
window.draw(sprite);
if(0) {
std::vector<RectTree<SensorReading>::RectResult> resList;
readingsTree.retrieveAllRects(resList);
std::vector<RectTree<SensorReading>::RectResult>::iterator iter = resList.begin();
for(; iter != resList.end(); iter++) {
//.........这里部分代码省略.........
示例8: main
//.........这里部分代码省略.........
if(!anyEvent){
leftPress = false;
rightPress = false;
upPress = false;
downPress = false;
}
anyEvent = false;
//for(int x = 0; x < 64; ++x){
// for(int y = 0; y < 64; ++y){
sf::Time t = clock.getElapsedTime();
if(t.asMilliseconds() > speed){
updatePos(*head);
updateDir(*head);
soundCount++;
if(soundCount > 5){
sound.play();
soundCount = 0;
}
clock.restart();
if(!gameOver)
gameOver = !checkBounds(*head);
checkIntersect(*head);//gen blacklist
if(addCount > 0){
--addCount;
Node* end = getEnd(*head);
switch(end->dir){
case UP:
end->next = new Node(end->x, end->y - 1, end->dir);//backwards
break;
case DOWN:
end->next = new Node(end->x, end->y + 1, end->dir);//backwards
break;
case LEFT:
end->next = new Node(end->x + 1, end->y, end->dir);//backwards
break;
case RIGHT:
end->next = new Node(end->x - 1, end->y, end->dir);//backwards
break;}
end->next->next = nullptr;
}
if(newFood){
addCount = 4;
if(speed >100){
speed *= .95;
//sound.setPitch(sound.getPitch()*1.1);
}
foodX = rand() % SIZE;
foodY = rand() % SIZE;
while(blacklist[foodX][foodY] == true){
foodX = rand() % SIZE;
foodY = rand() % SIZE;
}
newFood = false;
}
}
if(gameOver){
window.draw(sprite);
window.display();
gameOver = false;
sf::Time t = sf::seconds(.5);
for(int i = 0; i < 6; ++i)
sf::sleep(t);
delete head->next;
head->x = SIZE/2;
head->y = SIZE/2;
head->next = new Node(SIZE/2,SIZE/2-1,UP);
head->next->next = new Node(SIZE/2,SIZE/2 - 2,UP);
head->next->next->next = new Node(SIZE/2,SIZE/2-3,UP);
head->next->next->next->next = new Node(SIZE/2,SIZE/2-4,UP);
head->next->next->next->next->next = nullptr;
float speed = 150;
foodX = SIZE*.75;
foodY = SIZE*.75;
newFood = false;
}
if(!gameOver){
displaySnake(*head);
sf::RectangleShape draw1 = sf::RectangleShape(sf::Vector2f(640/SIZE,640/SIZE));
draw1.setPosition(sf::Vector2f(foodX * (640/SIZE), foodY * (640/SIZE)));
draw1.setFillColor(sf::Color::White);
renderTexture.draw(draw1);
}
sf::Texture texture = renderTexture.getTexture();
// draw it to the window
sf::Sprite sprite(texture);
window.draw(sprite);
window.display();
renderTexture.clear();
for(int x = 0; x < SIZE; x++){
for( int y = 0; y < SIZE; y++){
blacklist[x][y] = false;
}
}
}
}