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

Author Topic: VertexArray of points  (Read 3095 times)

0 Members and 1 Guest are viewing this topic.

mathme

  • Newbie
  • *
  • Posts: 8
    • View Profile
VertexArray of points
« 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?
« Last Edit: July 04, 2013, 12:50:56 am by mathme »

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: VertexArray of points
« Reply #1 on: July 04, 2013, 12:42:18 am »
Are you calling window.display(); after all your window.draw(xxx); code?

mathme

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: VertexArray of points
« Reply #2 on: July 04, 2013, 12:44:13 am »
Yes I call clear(), then draw(), then display().

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: VertexArray of points
« Reply #3 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?

mathme

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: VertexArray of points
« Reply #4 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

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: VertexArray of points
« Reply #5 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().

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: VertexArray of points
« Reply #6 on: July 04, 2013, 01:06:03 am »
Post a complete and minimal code.

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

 

anything