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

Author Topic: sf::Shape Texture Coordinates  (Read 1827 times)

0 Members and 1 Guest are viewing this topic.

foobarbaz

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
sf::Shape Texture Coordinates
« on: April 12, 2013, 03:06:51 am »
Hi, I'm writing a game that procedurally generates 2D planets. Right now, the entire planet is rendered onto a massive texture, which is fine when there is only one planet. I know, though, that I will be having problems when I have 100 planets. To get around this, instead of generating the planet's texture, I want to store polygons to render in OpenGL, but to do this, I need to be able to set texture coordinates from a source texture. I saw that texturing an sf::Shape is possible in the documentation, but couldn't find a way to set texture coordinates. Is there a way? Or am I going to have to dive into the OpenGL documentation and render my planets without SFML's help?

Thanks for your time!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: sf::Shape Texture Coordinates
« Reply #1 on: April 12, 2013, 03:13:28 am »
The easier way than going via sf::Shape is probably to use sf::VertexArray or std::vector<sf::Vertex> directly. You can set either a color or set the texture coordinates (or both).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

foobarbaz

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: sf::Shape Texture Coordinates
« Reply #2 on: April 12, 2013, 03:59:09 am »
Wow, that looks like a great solution, thanks! And thanks for the fast reply :D

foobarbaz

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: sf::Shape Texture Coordinates
« Reply #3 on: April 14, 2013, 04:26:49 am »
Hey, I finally got around to implementing rendering using a VertexArray, but I'm having trouble visualizing how to calculate texture coordinates based off of the vertex pixel coordinates. The planet is composed of a couple hundred vertices and I would like to have it textured as if I had a tiled texture that the vertices "cut" from like a cookie cutter. I don't know if that makes sense?

The vertex array is rendered as a triangle fan.

EDIT:

For anyone who cares, the texture coordinates are actually going to be exactly the same as the pixel coordinates, no computation required! :D
« Last Edit: April 17, 2013, 02:51:27 am by DrSuperSocks »

 

anything