SFML community forums

Help => Graphics => Topic started by: mathme on July 04, 2013, 12:28:10 am

Title: VertexArray of points
Post by: mathme on July 04, 2013, 12:28:10 am
I am making a vertexArray of points to draw my map. Each point is a pixel on the screen.

    drawArray.setPrimitiveType(sf::Points);
    drawArray.resize((ScreenHeight * ScreenWidth));
    int size = 0;
    for(int x = 0; x < ScreenWidth; x++)
    {
        for(int y = 0; y < ScreenlHeight; y++)
        {
            if(MapVector[x][y].isPixel)
            {
                sf::Vector2f pixelPos(x,y);
                drawArray[size].color = sf::Color::Magenta;
                drawArray[size].position = pixelPos;
                size++;
            }
        }
    }
 


Then at the end of populating this vertexArray called "drawArray" I draw it to the screen just using window.draw(drawArray)

Any ideas on why this just gives me a black screen?
Title: Re: VertexArray of points
Post by: The Hatchet on July 04, 2013, 12:42:18 am
Are you calling window.display(); after all your window.draw(xxx); code?
Title: Re: VertexArray of points
Post by: mathme on July 04, 2013, 12:44:13 am
Yes I call clear(), then draw(), then display().
Title: Re: VertexArray of points
Post by: G. on July 04, 2013, 12:45:38 am
Your code isn't complete (and minimal), we could only guess what the problem is.

What are the value of PixelHeight PixelWidth ScreenWidth and ScreenlHeight? Why do you use 2 different variables for the same thing?
Is isPixel always true?
Title: Re: VertexArray of points
Post by: mathme on July 04, 2013, 12:50:28 am
Ah sorry about that, pixelHeight is the same thing I just changed it to screenHeight for better readability in this post. I've added a cout statement there and the values for x,y, and size all make sense and from what I can see the array is being populated fine.

This code is encapsulated in a class function that I call from main.

I can't think of reason it just gives me a black screen since this code works fine on its own
Title: Re: VertexArray of points
Post by: The Hatchet on July 04, 2013, 12:58:07 am
I can't think of reason it just gives me a black screen since this code works fine on its own

If this chunk of code alone in a main() works fine then clearly something you don't include in this code is the problem and you've already found your answer.  Look at what you take out between this in a class and this sitting inside the main().
Title: Re: VertexArray of points
Post by: G. on July 04, 2013, 01:06:03 am
Post a complete and minimal code (https://github.com/SFML/SFML/wiki/FAQ#wiki-tr-grl-minimal).

In your VertexArray draw call, do you pass a texture? (or a RenderState with a texture) If yes, don't.