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

Author Topic: Vertex arrays and diagonal lines  (Read 1518 times)

0 Members and 1 Guest are viewing this topic.

Greysuit

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Vertex arrays and diagonal lines
« on: July 27, 2013, 08:05:20 am »
I wrote some code to make hexagons using sf::Triangles, but the texture is not displaying on the entity as I would expect. Along the top-left vectors, things are mostly fine, but along the others, especially the bottom-right, some peripheral pixels are cut off. An enlarged screenshot and the texture are attached. Below is the printout of the vertex coordinates. The data was the same for .position and .texCoords. According to the data and my texture, I can't find any reason why the image is not displaying properly.

I also have another question, which is related. If, using vertices, I define two lines that are mirror images of each other, such as the diagonal sides of a hexagon, will the set of pixels that make up both lines also be mirror images? Or, what if they are the same line (at different locations) but the order of the vertices is different, so that, in a sense, one line is drawn from left to right and the other from right to left. I know that the paint program I used to make my texture produced a different configuration for each line (using the line tool). If they're not the same, how do I approach that? For example, how would I make two diagonal lines flush with one another?

27              32
54              48
27              64

27              32
27              64
0               48

27              32
0               48
0               16

27              32
0               16
27              3.55271e-15

27              32
27              3.55271e-15
54              16

27              32
54              16
54              48

Ancurio

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: Vertex arrays and diagonal lines
« Reply #1 on: July 27, 2013, 07:42:01 pm »
So what you want is this jagged red outline around your hexagon? Why don't you just add a transparent background to your tileset and draw the quad enclosing the hexagon instead?

Greysuit

  • Newbie
  • *
  • Posts: 9
    • View Profile
    • Email
Re: Vertex arrays and diagonal lines
« Reply #2 on: July 27, 2013, 08:52:43 pm »
Hey, thanks. That seems like it should be a good solution, and not the type I was thinking of. Still, it seems there's something fundamental that I'm missing about how the graphics work, and I don't really want to move on without learning what that might be. In the end, I may use your solution either way, but I have to know what's going on with these hexagons.

Ancurio

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: Vertex arrays and diagonal lines
« Reply #3 on: July 29, 2013, 12:18:01 pm »
You have to understand how OpenGL samples from textures. When you specify the tex coords (16, 16), this is pointing to the top-left corner of the texel. Ideally, you'd want it to sample from the center of the texel however, for which you need to specify (16.5, 16.5). This might be the reason why the drawn image you're seeing looks a bit "shifted" to the top left. You could try and add "0.5" to all your tex coordinates.

 

anything