Jump to content

  • Log In with Google      Sign In   
  • Create Account

quad rendering to ortho view set to my window leaves lines between quads


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 bradbobak   Members   -  Reputation: 1097

Like
0Likes
Like

Posted 18 September 2013 - 02:29 AM

 Hi, when I render quads to my ortho view (set up as (0, window_x_size), (0, window_y_size), (-1, 1)) opengl leaves a blank line between neighbouring quads.

 

heres my ortho matrix setup:

matrix4x4 &matrix4x4::make_ortho(float left_, float right_,
 float top_, float bottom_, float near_, float far_)
{
  zero();
 
  mat[0] = 2.0f / (right_ - left_);
  mat[5] = 2.0f / (top_ - bottom_);
  mat[10] = -2.0f / (far_ - near_);
  mat[12] = -((right_ + left_) / (right_ - left_));
  mat[13] = -((top_ + bottom_) / (top_ - bottom_));
  mat[14] = -((far_ + near_) / (far_ - near_));
  mat[15] = 1.0f;
 
  return *this;
}
I call the above with make_ortho(0, 600, 0, 400, -1, 1) where the window size is 600 x 400.
 
This is the contents of my vertex array right before I enable the vertex attrib array and glVertexAttribPointer it.
 
(2 quads, one under the other)
 

verts : (0, 300, 0)
verts : (19, 300, 0)
verts : (19, 319, 0)
verts : (0, 319, 0)
verts : (0, 320, 0)
verts : (19, 320, 0)
verts : (19, 339, 0)
verts : (0, 339, 0)

 
Unfortunately, this is leaving a blank line between the top quad and the bottom one and I can't see why.
 
My vertex shader: (trans is set to my ortho matrix)

#version 330
 
uniform mat4 trans;
 
in vec3 pos;
in vec3 color;
 
out vec3 frag_color;
 
void main()
{
  gl_Position = trans * vec4(pos, 1.0);
 
  frag_color = color;
}
 

 
Fragment shader:

#version 330
 
in vec3 frag_color;
 
out vec4 out_color;
 
void main()
{
  out_color = vec4(frag_color, 1.0); 
}
 

 
 Everything works fine (quad placement is correct, color is correct), except there is a blank (black) horizontal line between the 2 quads.
 
 Any help would be appreciated.
 
 


Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 8192

Like
2Likes
Like

Posted 18 September 2013 - 03:06 AM

You draw two 19x19 pixel-sized quads spaces 20 pixels apart, so yes there's going to be a single pixel spacing between them. I assume you want the quads to be 20x20 so they line up perfectly, so you need to make the quads extend from 300 to 320 and from 320 to 340, respectively, in the Y-direction. And, of course, extend from 0 to 20 in the X-direction.



#3 bradbobak   Members   -  Reputation: 1097

Like
0Likes
Like

Posted 18 September 2013 - 02:30 PM

I thought the quads were 20 pixels, 0..19 is 20 units no?



#4 mark ds   Members   -  Reputation: 1239

Like
2Likes
Like

Posted 18 September 2013 - 02:54 PM

OpenGL coordinates are for the bottom-left of the pixel. So drawing a line from 0,0 to 1,1 fills exactly one pixel (in screen coordinates).

 

Put another way, image a piece of graph paper, with 0,0 at the bottom-left. If you draw a line to 1,1 you will get a diagonal line in the first grid square - it will not extend into the square at 1,1 as below.

 

|_|_|_

|_|_|_

|/|_|_

 

The diagonal represents a line from 0,0 to 1,1 - filling exactly 1 pixel at coordinate 0,0


Edited by mark ds, 18 September 2013 - 02:56 PM.


#5 bradbobak   Members   -  Reputation: 1097

Like
0Likes
Like

Posted 18 September 2013 - 02:58 PM

 I see. Thank you.



#6 Brother Bob   Moderators   -  Reputation: 8192

Like
1Likes
Like

Posted 18 September 2013 - 02:59 PM

You have your projection set up to map one unit to one pixel. Your quad is 19-0=19 units, and thus 19 pixels. You can look at it from another point also, first quad extends from 300 to 319, but the second quad starts at 320 and ends at 399. But what about the one unit gap from 319 to 320? That gap is 320-319=1 unit, and thus the gap is one pixel.

 

What you are probably misunderstanding here is that your coordinates are pixel coordinates; they are not. Pixels are discrete rectangles with a defined size, but the coordinate system is continuous. That is, there are no fractional pixels, but there are fractional coordinates that is located within the small boundary rectangle defined by a pixel. The quad you specify determines the boundary of the shape that is subsequently rasterized such that all pixels inside the boundary is drawn.

 

Let's make the numbers a bit more reasonable for an example and make a small picture. Here's a 5x4 pixel grid, with coordinates ranging from 0 to 5 along the X-axis, and from 0 to 5 along the Y-axis. Now draw a rectangle from (1,1) to (4,3) and observe which pixels are drawn. Also observe that the pixel centers are not located at integer coordinates; pixel boundaries are located at integer coordinates. The X's indicate which pixels are drawn.

4 +---+---+---+---+---+
  |   |   |   |   |   |
3 +---+---+---+---+---+
  |   | X | X | X |   |
2 +---+---+---+---+---+
  |   | X | X | X |   |
1 +---+---+---+---+---+
  |   |   |   |   |   |
0 +---+---+---+---+---+
  0   1   2   3   4   5



#7 Brother Bob   Moderators   -  Reputation: 8192

Like
0Likes
Like

Posted 18 September 2013 - 03:01 PM

And with regards to mark ds' reply, he's talking about lines which (as well as points) have different rasterization rules than filled primitives. His example does not apply in this particular case and is not the reason for the gap or missing pixels. His information is not wrong though, just that lines does not apply in this case.



#8 mark ds   Members   -  Reputation: 1239

Like
0Likes
Like

Posted 18 September 2013 - 03:05 PM

And with regards to mark ds' reply, he's talking about lines which (as well as points) have different rasterization rules than filled primitives. His example does not apply in this particular case and is not the reason for the gap or missing pixels. His information is not wrong though, just that lines does not apply in this case.

 

I should have been clearer - I wasn't referring to OpenGL lines, just the concept that only one grid square (pixel) was actually touched when going from 0,0 to 1,1






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS