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

Author Topic: RenderTexture, cannot align with vertexArray  (Read 1755 times)

0 Members and 1 Guest are viewing this topic.

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
RenderTexture, cannot align with vertexArray
« on: April 21, 2014, 05:45:01 pm »
Hello.
When i am drawing sf::VertexArray onto a sf::RenderTexture, the sf::VertexArray is in global space and sf::RenderTexture is in local 0, 0 thus i do not know how to align those two so i would draw VertexArray with transform? that would set its world coordinate to 0, 0.

I have a sf::View that i use and it centers on a units X and Y coordinate.
i am using sfml coordinate system having 0, 0 at left down corner and x axis goes right intro + and y axis goes down intro +.

When unit is at x = 1000, y = 1000 and i want to draw something on screen i draw its position 1000, 1000 at it ends up in center of screen.
But now i have unit at x = 1000, y = 1000. The texture is supposed to start from XPos= (Unit.x - Screen_Width / 2), YPos= (Unit.y - Screen_Height / 2) but it starts with 0, thus when i draw vertexArray onto RenderTexture and then use sf::Sprite to set its position to (XPos, YPos), i don't see the VertexArray because it was out of bounds, how do i correct the position of vertexArray instead of repositioning all vertices each draw?
Code: [Select]
//Small preview code
sf::View view;
sf::RenderTexture renTex;
sf::VertexArray verArr;
sf::Vector2f unit;//Represents position
sf::RenderWindow renWin;
int Window_Width = 800;
int Window_Height = 600;
int block_unitSize = 32;
sf::renderState renState;//Used for texture

//Execution
renTex.create(Window_Width, Window_Height);//Create texture 800x600
unit = sf::Vector2f(1000.f, 1000.f);
view.setCenter(unit);
renWin.setView(view);
verArr.setPrimitiveType(sf::Quads);
//Square of a vertexArray with size of 32 at pos X,Y = 1000
verArr.append(sf::Vector2f(1000, 1000));
verArr.append(sf::Vector2f(1000+block_unitSize, 1000));
verArr.append(sf::Vector2f(1000+block_unitSize, 1000+block_unitSize));
verArr.append(sf::Vector2f(1000, 1000+block_unitSize));
//Draw verArr to renWin, the rectangle will be starting from center of screen going right down
renWin.draw(verArr, renState);
renTex.clear(sf::Color::Black);//Clear with black color
renTex.draw(verArr, renState);//The recatngle goes out of screen thus the whole renTex is black
renTex.display();
sf::Sprite spr;
spr.setTexture(renTex.getTexture());
spr.setPosition(view.getCenter().x - Window_Width /2, view.getCenter().y - Window_Height /2);
renWin.draw(spr);
So the question is, how do i get the VertexArray to draw at renTex and renWin the same thing at same position in this case?
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: RenderTexture, cannot align with vertexArray
« Reply #1 on: April 21, 2014, 09:19:05 pm »
sf::RenderTexture.setView(); i missed that even when i looked at documentation.
Problem solved!
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0