Jump to content
  • Advertisement
Sign in to follow this  
Jacob Jingle

OpenGL OpenGL - Newb draw line 2D confusion

This topic is 2400 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm sure this has to do with fact I'm new to OpenGL:
When I draw a line(X=0, Y=0 -> X=0, Y=100) along side of window the line isn't visible. |
A line set to (X=0, Y=0 -> X=100, Y=0) and drawn along top of window is visible. -
If I change below code to glm::translate(glm::mat4(1.0f), glm::vec3(1.0f, 0.0f, 0.0f)); and move my draw area to left
The first line is visible and along side of window
The second line is visible along top of window but has a gap between it and left side of window. | -

Why can't I see the vert line in first instance but I get a gap in horz line in second instance?

Generic shaders and MVP is below
int vPort[4];
glGetIntegerv(GL_VIEWPORT, vPort); // gets x, y, width, height of window
glm::mat4 Projection = glm::ortho<float>(vPort[1], vPort[2], vPort[3], vPort[0], -1.0f, 1.0f);
glm::mat4 View = glm::lookAt(glm::vec3(0,0,1), glm::vec3(0,0,0), glm::vec3(0,1,0));
glm::mat4 Model = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 0.0f));
m_MVP = Projection * View * Model;
glProgramUniformMatrix4fv(m_programIDs[program::VERT], m_MVPMatrixID, 1, GL_FALSE, glm::value_ptr(m_MVP));

//vert
#version 420 core

#define POSITION 0
#define COLOR 1

layout(location = POSITION) in ivec2 in_Position;
layout(location = COLOR) in vec4 in_Color;

uniform mat4 MVP;

out Data
{
vec4 color;
} vdata;

void main(void)
{
gl_Position = MVP * vec4(in_Position, 0.0, 1.0);
vdata.color = in_Color;
}

//frag
#version 420 core

#define POSITION 0
#define COLOR 1

layout(location = 0) out vec4 out_Color;

in Data
{
vec4 color;
} vdata;

void main(void)
{
out_Color = vdata.color;
}

Share this post


Link to post
Share on other sites
Advertisement
When specifying coordinates in pixels, it is necessary to offset them by a small amount, typically 0.50 or 0.375 due to the way that the geometry is scan converted. The OpenGL Red Book recommended adding "glTranslate2f(0.375f,0.375f);" to the modelview matrix.

Try:

[source lang="c++"]
[color=#000000]glm[color=#666600]::[color=#000000]mat4 [color=#660066]Model[color=#000000] [color=#666600]=[color=#000000] glm[color=#666600]::[color=#000000]translate[color=#666600]([color=#000000]glm[color=#666600]::[color=#000000]mat4[color=#666600]([color=#006666]1.0f[color=#666600]),[color=#000000] glm[color=#666600]::[color=#000000]vec3[color=#666600]([color=#006666]0.375f[color=#666600],[color=#000000] [color=#006666]0.375f[color=#666600],[color=#000000] [color=#006666]0.0f[color=#666600]));

[color=#666600][/source]

Share this post


Link to post
Share on other sites

When specifying coordinates in pixels, it is necessary to offset them by a small amount, typically 0.50 or 0.375 due to the way that the geometry is scan converted. The OpenGL Red Book recommended adding "glTranslate2f(0.375f,0.375f);" to the modelview matrix.

Try:

[source lang="c++"]
[color=#000000]glm[color=#666600]::[color=#000000]mat4 [color=#660066]Model[color=#000000] [color=#666600]=[color=#000000] glm[color=#666600]::[color=#000000]translate[color=#666600]([color=#000000]glm[color=#666600]::[color=#000000]mat4[color=#666600]([color=#006666]1.0f[color=#666600]),[color=#000000] glm[color=#666600]::[color=#000000]vec3[color=#666600]([color=#006666]0.375f[color=#666600],[color=#000000] [color=#006666]0.375f[color=#666600],[color=#000000] [color=#006666]0.0f[color=#666600]));

[color=#666600][/source]

Yeah, that works and I see half of my vertical line along left side of window. But doing this cost me a line I have along right side of window - I don't even get half of it showing. (I'm doing an outline around the window client area)

Geesh, this problem is going to give me a few fudge numbers to get things to work the way I want. sad.png

Oh well, thanks for help.

Share this post


Link to post
Share on other sites

Yeah, that works and I see half of my vertical line along left side of window. But doing this cost me a line I have along right side of window - I don't even get half of it showing. (I'm doing an outline around the window client area)


huh.png Well, I am at a loss. The last time I used pixel coordinates, I was making a tile engine and didn't notice this. I haven't tried it with lines.

Share this post


Link to post
Share on other sites

huh.png Well, I am at a loss. The last time I used pixel coordinates, I was making a tile engine and didn't notice this. I haven't tried it with lines.

Funny thing, when I do colored tiles(GL_POINTS + geomatry shader) they line up perfectly. It's just silly.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!