Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - shujidev

Pages: [1]
1
Graphics / Re: Trying not to draw all RenderTextures at every frame
« on: June 16, 2020, 11:29:41 pm »
ok thank you very much I think I get it now

2
Graphics / Re: Trying not to draw all RenderTextures at every frame
« on: June 16, 2020, 10:47:01 pm »
I see, what I get is the RenderTexture is not displaying and there is a blinking black and white in the whole screen when I try to add antialiasing to their ContextSettings on creation.

3
Graphics / Is it possible to reduce the size of a VertexBuffer?
« on: June 16, 2020, 05:34:41 am »
I was trying to draw a buffer after removing the last vertex and I couldn't see any changes, only after this I noticed it was possible to modify a part of the vertexbuffer but apparently the buffer is not getting smaller, so is something like a resize possible somehow?

4
Graphics / Re: Trying not to draw all RenderTextures at every frame
« on: June 16, 2020, 12:48:08 am »
Thank you guys for your answers, I was able to recreate the program in c++ with the following code I think the problem arises after adding a ContextSettings to the RenderTextures (is antialiasing not supported on textures?)

//g++ -Wall -o "%e" "%f" -I. -L. -lsfml-graphics-2 -lsfml-window-2 -lsfml-system-2
#include "SFML/Graphics.hpp"
#include <iostream>

void displaytex(sf::RenderTexture *tex){tex->display();}
void clear(sf::RenderTarget *target){target->clear(sf::Color(255,255,255,0));}
void drawsprite(sf::Sprite *sprite, sf::RenderTarget *target, int x, int y){
        if(x!=0 || y!=0) sprite->setPosition(x,y);
        target->draw(*sprite);
}
int main(){
        sf::ContextSettings settings;
        settings.antialiasingLevel = 8;
        sf::CircleShape shape(50.f);
        shape.setFillColor(sf::Color(100, 250, 50, 155));
        shape.setPosition(0,0);
        sf::CircleShape shape2(50.f);
        shape2.setFillColor(sf::Color(250, 100, 50, 155));
        shape2.setPosition(100,0);
       
        sf::RenderWindow window(sf::VideoMode(800, 600), "My window", sf::Style::Default, settings);
        auto mainlayer = new sf::RenderTexture();
        mainlayer->create(800,600, settings);
        auto layer1 = new sf::RenderTexture();
        layer1->create(800,600, settings);
       
        while (window.isOpen()){
                sf::Event event;
                while (window.pollEvent(event)){
                        if (event.type == sf::Event::Closed)
                                window.close();
                        if (event.type==sf::Event::MouseMoved) {
                                std::cout << "mouse moved" << std::endl;
                                clear(mainlayer);
                                clear(layer1);
                                layer1->draw(shape); //drawing lots of things
                                layer1->draw(shape2); //drawing lots of things
                                displaytex(layer1);
                                sf::Sprite *sprite1=new sf::Sprite(layer1->getTexture());
                                drawsprite(sprite1,mainlayer,0,0);
                        }
                }
                window.clear(sf::Color(200,200,200,255));
                mainlayer->display();
                sf::Sprite sprite(mainlayer->getTexture());
                window.draw(sprite);
                window.display();
        }

        return 0;
}

I am still not sure what I am doing wrong, on update I clear, draw and display the textures. What would you change?

5
Hi this is my problem, I had a render texture which I fill with other textures and draw at every frame but it's not too efficient drawing all textures since they are not changing all the time, so I assumed by drawing only at some events into the main texture would be faster, except that nothing but a blinking screen is displaying, any idea what went wrong?
I have something like this:

window = new sf::RenderWindow(sf::VideoMode(1000, 800), "My window");
mainlayer = new sf::RenderTexture();
mainlayer->create(800,600)
while (window->isOpen()){
                sf::Event event;
                while (window->pollEvent(event)){
                        if (event.type==sf::Event::Closed) window->close();
                        if (event.type==sf::Event::MouseMoved) {
                                clear(mainlayer)
                                loop(layers) draw(layers,mainlayer)
                        }
                }
                window->clear(sf::Color(200,200,200,255));
                window->draw(quad);

                //clear(mainlayer)
                //loop(layers) draw(layer,mainlayer) #if I do this here, it's too inefficient

                mainlayer->display();
                sf::Sprite sprite(mainlayer->getTexture());
                window->draw(sprite);
                window->display();
        }
void draw(Layer layer, RenderTexture target){ #draw into the main texture
        clear(layer.renderTexture)
        draw(layer.curves, layer.renderTexture) #draw vertexbuffers into the texture
        drawtexture(layer.renderTexture, target) #draw texture into the main texture
}
 


If I add the drawing part into the draw function everything works fine but when I try to draw somewhere else, its as if the mainlayer was empty when I try to draw it to the renderwindow. Please help! what am I missing?

6
Graphics / Re: position problem when drawing a CircleShape
« on: July 12, 2017, 01:08:53 am »
ok I did so but the problem remained the same, what I tried to do is clear and display the texture once and increment it by drawing circles into it
One thing I noticed is when I tried to draw the circle on (10,10) it was painted under the title bar.

7
Graphics / position problem when drawing a CircleShape on Windows 10
« on: July 12, 2017, 12:03:59 am »
I am not sure but I think it's a problem with windows 10 borderless windows
The problem is when I draw the circle its always drawn with a little offset from where it should be.

top-left corner


bottom-right corner


In the top of the window the shape is drawn above the mouse, in the bottom the shape is drawn under the mouse and so for each side of the window

#include "SFML/Graphics.hpp"
#include <stdio.h>
int main(int argc, char **argv){
        sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Application");
        window.setFramerateLimit(60);

        sf::RenderTexture renderTexture;
        renderTexture.create(800,600);
        renderTexture.setSmooth(true);
        renderTexture.clear(sf::Color(255,255,255,255));
        renderTexture.display();

        int wpoint=10;
        sf::CircleShape point(wpoint,50);
        point.setFillColor(sf::Color(255, 0, 0, 128));

        while(1){
                sf::Event event;
                while (window.pollEvent(event)){
                        if (event.type==sf::Event::MouseMoved && sf::Mouse::isButtonPressed(sf::Mouse::Left)){
                                //printf("%d\n",sf::Mouse::isButtonPressed(sf::Mouse::Left));
                                //point.setPosition(event.mouseMove.x-(wpoint/2),event.mouseMove.y-(wpoint/2));
                                //point.setPosition(event.mouseMove.x,event.mouseMove.y);
                                //auto pos=sf::Mouse::getPosition();
                                auto poswindow=window.getPosition();
                                printf("%d,%d\n",poswindow.x,poswindow.y); //This prints -8,0 when I position the window on the left-top corner (0,0)!!
                                //auto pos=sf::Mouse::getPosition(window);
                                auto pos=window.mapPixelToCoords(sf::Mouse::getPosition(window));
                                point.setPosition(pos.x,pos.y);
                                renderTexture.draw(point, sf::BlendAlpha);
                        }
                        if (event.type==sf::Event::Closed
                         || event.type==sf::Event::KeyPressed && event.key.code==sf::Keyboard::Escape)
                                return 0;
                }

                sf::Sprite canvas(renderTexture.getTexture());
                // draw
                window.clear();
                window.draw(canvas);
                window.display();
        }
        return 0;
}

It doesn't matter, I read somewhere that it's a thing that only happens with some Intel drivers, I just hope that the users don't have it or I will be in troubles. It's weird because I have been working with the Winapi for a long time and the mouse coordinates have always been correct.
If this is something that affects a lot of people one solution might be to add an empty window filling the ClientRect and adding the context to it, am I right?

Pages: [1]