OpenGL not rendering half the points [closed]
I'm trying to build a simple y=x curve with -0.5< x <0.5 and z = 0. But for some reason, half of the x points are not rendered. I'm using point primitive to be simple, and not using any index buffer.
I checked that x values are generated correctly and are in the range, but still the positive half (0< x <0.5) is not displayed.
The code is here:
https://github.com/abhimittal664/opengl
I'm not entirely sure, but can it be due to MVP matrices? I tried experimenting with them but no use.
On an additional note, is there some way to debug problems in shader file? I am using visual studio 2017 on intel integrated graphics machine. Looks like visual studio graphics debugger is for directx only. Currently i'm just trying to debug by outputting points with different color to get visual hints.
Thanks
Edit 1:
The y = x function is in the vertex shader. The vertex buffer only has x values, with y,z = 0.
c++ opengl rendering glm-math
closed as off-topic by genpfault, Nicol Bolas, lagom, V-rund Puro-hit, Foo Nov 12 at 7:15
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – genpfault, Nicol Bolas, lagom, V-rund Puro-hit, Foo
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I'm trying to build a simple y=x curve with -0.5< x <0.5 and z = 0. But for some reason, half of the x points are not rendered. I'm using point primitive to be simple, and not using any index buffer.
I checked that x values are generated correctly and are in the range, but still the positive half (0< x <0.5) is not displayed.
The code is here:
https://github.com/abhimittal664/opengl
I'm not entirely sure, but can it be due to MVP matrices? I tried experimenting with them but no use.
On an additional note, is there some way to debug problems in shader file? I am using visual studio 2017 on intel integrated graphics machine. Looks like visual studio graphics debugger is for directx only. Currently i'm just trying to debug by outputting points with different color to get visual hints.
Thanks
Edit 1:
The y = x function is in the vertex shader. The vertex buffer only has x values, with y,z = 0.
c++ opengl rendering glm-math
closed as off-topic by genpfault, Nicol Bolas, lagom, V-rund Puro-hit, Foo Nov 12 at 7:15
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – genpfault, Nicol Bolas, lagom, V-rund Puro-hit, Foo
If this question can be reworded to fit the rules in the help center, please edit the question.
y=x function is in vertex shader file. This only generates x values
– Plutonium smuggler
Nov 11 at 22:15
Ah, I see. It looks like the colors are red if x > 0 and black if x < 0. If your background is black, that could explain it.
– user1118321
Nov 11 at 22:26
i put the background as white. Added the color line for debugging, but if you run the code, x > 0 is not displayed, which is the problem ie blacks are visible but not red points
– Plutonium smuggler
Nov 11 at 22:28
add a comment |
I'm trying to build a simple y=x curve with -0.5< x <0.5 and z = 0. But for some reason, half of the x points are not rendered. I'm using point primitive to be simple, and not using any index buffer.
I checked that x values are generated correctly and are in the range, but still the positive half (0< x <0.5) is not displayed.
The code is here:
https://github.com/abhimittal664/opengl
I'm not entirely sure, but can it be due to MVP matrices? I tried experimenting with them but no use.
On an additional note, is there some way to debug problems in shader file? I am using visual studio 2017 on intel integrated graphics machine. Looks like visual studio graphics debugger is for directx only. Currently i'm just trying to debug by outputting points with different color to get visual hints.
Thanks
Edit 1:
The y = x function is in the vertex shader. The vertex buffer only has x values, with y,z = 0.
c++ opengl rendering glm-math
I'm trying to build a simple y=x curve with -0.5< x <0.5 and z = 0. But for some reason, half of the x points are not rendered. I'm using point primitive to be simple, and not using any index buffer.
I checked that x values are generated correctly and are in the range, but still the positive half (0< x <0.5) is not displayed.
The code is here:
https://github.com/abhimittal664/opengl
I'm not entirely sure, but can it be due to MVP matrices? I tried experimenting with them but no use.
On an additional note, is there some way to debug problems in shader file? I am using visual studio 2017 on intel integrated graphics machine. Looks like visual studio graphics debugger is for directx only. Currently i'm just trying to debug by outputting points with different color to get visual hints.
Thanks
Edit 1:
The y = x function is in the vertex shader. The vertex buffer only has x values, with y,z = 0.
c++ opengl rendering glm-math
c++ opengl rendering glm-math
edited Nov 12 at 2:59
genpfault
41.6k95197
41.6k95197
asked Nov 11 at 22:03
Plutonium smuggler
1942515
1942515
closed as off-topic by genpfault, Nicol Bolas, lagom, V-rund Puro-hit, Foo Nov 12 at 7:15
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – genpfault, Nicol Bolas, lagom, V-rund Puro-hit, Foo
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by genpfault, Nicol Bolas, lagom, V-rund Puro-hit, Foo Nov 12 at 7:15
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – genpfault, Nicol Bolas, lagom, V-rund Puro-hit, Foo
If this question can be reworded to fit the rules in the help center, please edit the question.
y=x function is in vertex shader file. This only generates x values
– Plutonium smuggler
Nov 11 at 22:15
Ah, I see. It looks like the colors are red if x > 0 and black if x < 0. If your background is black, that could explain it.
– user1118321
Nov 11 at 22:26
i put the background as white. Added the color line for debugging, but if you run the code, x > 0 is not displayed, which is the problem ie blacks are visible but not red points
– Plutonium smuggler
Nov 11 at 22:28
add a comment |
y=x function is in vertex shader file. This only generates x values
– Plutonium smuggler
Nov 11 at 22:15
Ah, I see. It looks like the colors are red if x > 0 and black if x < 0. If your background is black, that could explain it.
– user1118321
Nov 11 at 22:26
i put the background as white. Added the color line for debugging, but if you run the code, x > 0 is not displayed, which is the problem ie blacks are visible but not red points
– Plutonium smuggler
Nov 11 at 22:28
y=x function is in vertex shader file. This only generates x values
– Plutonium smuggler
Nov 11 at 22:15
y=x function is in vertex shader file. This only generates x values
– Plutonium smuggler
Nov 11 at 22:15
Ah, I see. It looks like the colors are red if x > 0 and black if x < 0. If your background is black, that could explain it.
– user1118321
Nov 11 at 22:26
Ah, I see. It looks like the colors are red if x > 0 and black if x < 0. If your background is black, that could explain it.
– user1118321
Nov 11 at 22:26
i put the background as white. Added the color line for debugging, but if you run the code, x > 0 is not displayed, which is the problem ie blacks are visible but not red points
– Plutonium smuggler
Nov 11 at 22:28
i put the background as white. Added the color line for debugging, but if you run the code, x > 0 is not displayed, which is the problem ie blacks are visible but not red points
– Plutonium smuggler
Nov 11 at 22:28
add a comment |
1 Answer
1
active
oldest
votes
Extracted from the link to your code:
//Vertex buffer definition
struct vertex {
glm::vec3 position;
glm::vec3 color;
};
and
void populate_vertex_buffer(vertex* vertices, int n_vertices) {
...
for (int x = 0; x < n_vertices; x++) {
count = -0.5f + (1.f / n_vertices)*(float)x;
vertices[x].position = glm::vec3((-0.5f + (1.f / n_vertices)*(float)x), 0, 0);
vertices[x].color = glm::vec3(0.0, 0.0, 0.0);
...
So data in the buffer is XYZRGBXYZRGBXYZRGB...... with Y,Z,R,G,B all = 0)
You tell the driver how to read this buffer:
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
...
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)offsetof(vertex, color));
Pay attention to the second glVertexAttribPointer
. It tells that the second attribute (vc
in your VS) starts at position offsetof(vertex, color)
and then each color is contiguous to previous (the fifth param = 0). That is good for a buffer data like XYZXYZXYZ......RGBRGBRGBRGB...
I think the read instructions would be
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), NULL);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), 3*sizeof(float);
where the 6
comes from six values XYZRGB between two same attributes.
Thanks. That did it. I did not know this, so definitely new info
– Plutonium smuggler
Nov 12 at 4:10
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Extracted from the link to your code:
//Vertex buffer definition
struct vertex {
glm::vec3 position;
glm::vec3 color;
};
and
void populate_vertex_buffer(vertex* vertices, int n_vertices) {
...
for (int x = 0; x < n_vertices; x++) {
count = -0.5f + (1.f / n_vertices)*(float)x;
vertices[x].position = glm::vec3((-0.5f + (1.f / n_vertices)*(float)x), 0, 0);
vertices[x].color = glm::vec3(0.0, 0.0, 0.0);
...
So data in the buffer is XYZRGBXYZRGBXYZRGB...... with Y,Z,R,G,B all = 0)
You tell the driver how to read this buffer:
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
...
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)offsetof(vertex, color));
Pay attention to the second glVertexAttribPointer
. It tells that the second attribute (vc
in your VS) starts at position offsetof(vertex, color)
and then each color is contiguous to previous (the fifth param = 0). That is good for a buffer data like XYZXYZXYZ......RGBRGBRGBRGB...
I think the read instructions would be
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), NULL);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), 3*sizeof(float);
where the 6
comes from six values XYZRGB between two same attributes.
Thanks. That did it. I did not know this, so definitely new info
– Plutonium smuggler
Nov 12 at 4:10
add a comment |
Extracted from the link to your code:
//Vertex buffer definition
struct vertex {
glm::vec3 position;
glm::vec3 color;
};
and
void populate_vertex_buffer(vertex* vertices, int n_vertices) {
...
for (int x = 0; x < n_vertices; x++) {
count = -0.5f + (1.f / n_vertices)*(float)x;
vertices[x].position = glm::vec3((-0.5f + (1.f / n_vertices)*(float)x), 0, 0);
vertices[x].color = glm::vec3(0.0, 0.0, 0.0);
...
So data in the buffer is XYZRGBXYZRGBXYZRGB...... with Y,Z,R,G,B all = 0)
You tell the driver how to read this buffer:
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
...
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)offsetof(vertex, color));
Pay attention to the second glVertexAttribPointer
. It tells that the second attribute (vc
in your VS) starts at position offsetof(vertex, color)
and then each color is contiguous to previous (the fifth param = 0). That is good for a buffer data like XYZXYZXYZ......RGBRGBRGBRGB...
I think the read instructions would be
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), NULL);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), 3*sizeof(float);
where the 6
comes from six values XYZRGB between two same attributes.
Thanks. That did it. I did not know this, so definitely new info
– Plutonium smuggler
Nov 12 at 4:10
add a comment |
Extracted from the link to your code:
//Vertex buffer definition
struct vertex {
glm::vec3 position;
glm::vec3 color;
};
and
void populate_vertex_buffer(vertex* vertices, int n_vertices) {
...
for (int x = 0; x < n_vertices; x++) {
count = -0.5f + (1.f / n_vertices)*(float)x;
vertices[x].position = glm::vec3((-0.5f + (1.f / n_vertices)*(float)x), 0, 0);
vertices[x].color = glm::vec3(0.0, 0.0, 0.0);
...
So data in the buffer is XYZRGBXYZRGBXYZRGB...... with Y,Z,R,G,B all = 0)
You tell the driver how to read this buffer:
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
...
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)offsetof(vertex, color));
Pay attention to the second glVertexAttribPointer
. It tells that the second attribute (vc
in your VS) starts at position offsetof(vertex, color)
and then each color is contiguous to previous (the fifth param = 0). That is good for a buffer data like XYZXYZXYZ......RGBRGBRGBRGB...
I think the read instructions would be
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), NULL);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), 3*sizeof(float);
where the 6
comes from six values XYZRGB between two same attributes.
Extracted from the link to your code:
//Vertex buffer definition
struct vertex {
glm::vec3 position;
glm::vec3 color;
};
and
void populate_vertex_buffer(vertex* vertices, int n_vertices) {
...
for (int x = 0; x < n_vertices; x++) {
count = -0.5f + (1.f / n_vertices)*(float)x;
vertices[x].position = glm::vec3((-0.5f + (1.f / n_vertices)*(float)x), 0, 0);
vertices[x].color = glm::vec3(0.0, 0.0, 0.0);
...
So data in the buffer is XYZRGBXYZRGBXYZRGB...... with Y,Z,R,G,B all = 0)
You tell the driver how to read this buffer:
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
...
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)offsetof(vertex, color));
Pay attention to the second glVertexAttribPointer
. It tells that the second attribute (vc
in your VS) starts at position offsetof(vertex, color)
and then each color is contiguous to previous (the fifth param = 0). That is good for a buffer data like XYZXYZXYZ......RGBRGBRGBRGB...
I think the read instructions would be
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), NULL);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*sizeof(float), 3*sizeof(float);
where the 6
comes from six values XYZRGB between two same attributes.
answered Nov 12 at 1:11
Ripi2
4,2631825
4,2631825
Thanks. That did it. I did not know this, so definitely new info
– Plutonium smuggler
Nov 12 at 4:10
add a comment |
Thanks. That did it. I did not know this, so definitely new info
– Plutonium smuggler
Nov 12 at 4:10
Thanks. That did it. I did not know this, so definitely new info
– Plutonium smuggler
Nov 12 at 4:10
Thanks. That did it. I did not know this, so definitely new info
– Plutonium smuggler
Nov 12 at 4:10
add a comment |
y=x function is in vertex shader file. This only generates x values
– Plutonium smuggler
Nov 11 at 22:15
Ah, I see. It looks like the colors are red if x > 0 and black if x < 0. If your background is black, that could explain it.
– user1118321
Nov 11 at 22:26
i put the background as white. Added the color line for debugging, but if you run the code, x > 0 is not displayed, which is the problem ie blacks are visible but not red points
– Plutonium smuggler
Nov 11 at 22:28