basic opengl black screen when adding IBO
When i only have a VBO and a VAO all works fine but when adding an IBO i'm getting a black screen. Here is the code:
initialisation:
GLuint vbo = 0;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);
GLuint ibo;
glGenBuffers(1, &ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
GLuint vao = 0;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float), NULL);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBindVertexArray(0);
inside loop:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(shader_programme);
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, 14, GL_UNSIGNED_INT, NULL);
glBindVertexArray(0);
vertices and indicies:
float points =
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
-1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
-1.0, 1.0, -1.0,
1.0, 1.0, -1.0,
;
float indices =
0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1
;
c opengl glfw opengl-4
add a comment |
When i only have a VBO and a VAO all works fine but when adding an IBO i'm getting a black screen. Here is the code:
initialisation:
GLuint vbo = 0;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);
GLuint ibo;
glGenBuffers(1, &ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
GLuint vao = 0;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float), NULL);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBindVertexArray(0);
inside loop:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(shader_programme);
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, 14, GL_UNSIGNED_INT, NULL);
glBindVertexArray(0);
vertices and indicies:
float points =
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
-1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
-1.0, 1.0, -1.0,
1.0, 1.0, -1.0,
;
float indices =
0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1
;
c opengl glfw opengl-4
add a comment |
When i only have a VBO and a VAO all works fine but when adding an IBO i'm getting a black screen. Here is the code:
initialisation:
GLuint vbo = 0;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);
GLuint ibo;
glGenBuffers(1, &ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
GLuint vao = 0;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float), NULL);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBindVertexArray(0);
inside loop:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(shader_programme);
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, 14, GL_UNSIGNED_INT, NULL);
glBindVertexArray(0);
vertices and indicies:
float points =
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
-1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
-1.0, 1.0, -1.0,
1.0, 1.0, -1.0,
;
float indices =
0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1
;
c opengl glfw opengl-4
When i only have a VBO and a VAO all works fine but when adding an IBO i'm getting a black screen. Here is the code:
initialisation:
GLuint vbo = 0;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);
GLuint ibo;
glGenBuffers(1, &ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
GLuint vao = 0;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float), NULL);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBindVertexArray(0);
inside loop:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(shader_programme);
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, 14, GL_UNSIGNED_INT, NULL);
glBindVertexArray(0);
vertices and indicies:
float points =
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
-1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
-1.0, 1.0, -1.0,
1.0, 1.0, -1.0,
;
float indices =
0, 1, 2, 3, 7, 1, 5, 4, 7, 6, 2, 4, 0, 1
;
c opengl glfw opengl-4
c opengl glfw opengl-4
asked Nov 15 '18 at 16:20
Shirakawa42Shirakawa42
206
206
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The 5th parameter of glVertexAttribPointer is the byte offset between consecutive generic vertex attributes. If it is 0 then the vertex attributes are understood to be tightly packed.
Your vertices consists of three components of type float, so the stride is 3*sizeof(float):
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), NULL);
Since the vertices are tightly packed, you can also pass 0 to the paramter:
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
The type of the indices is GL_UNSIGNED_INT. The type of the index array has to be an integral data type which corresponds to GL_UNSIGNED_INT. In your case it has to be unsigned int.
unsigned int indices = .... ;
Further, the primitive type GL_TRIANGLES consists of a list of indices where each 3 form a triangle. Indices 0, 1, 2 for ma triangle, indices 4, 5, 6 form the next triangle and so on. So the number of indices has to be dividable by 3.
If you want to draw a cube, then the list of indices may look like this:
unsigned int indices =
0,1,2, 0,2,3,
1,5,6, 1,6,2,
5,4,7, 5,7,6,
4,0,3, 4,3,7,
3,2,6, 3,6,7,
1,0,4, 1,4,5
;
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, NULL);
thx for your answer but after doing that i'm also getting a black screen :/
– Shirakawa42
Nov 15 '18 at 17:04
i tryed with 3*sizeof(float) and 0 but black screen :/ here is my github if you want to see all the code github.com/Shirakawa42/scop
– Shirakawa42
Nov 15 '18 at 17:59
@Shirakawa42unsigned intinstead offloat(for theindices)
– Rabbid76
Nov 15 '18 at 18:19
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323735%2fbasic-opengl-black-screen-when-adding-ibo%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The 5th parameter of glVertexAttribPointer is the byte offset between consecutive generic vertex attributes. If it is 0 then the vertex attributes are understood to be tightly packed.
Your vertices consists of three components of type float, so the stride is 3*sizeof(float):
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), NULL);
Since the vertices are tightly packed, you can also pass 0 to the paramter:
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
The type of the indices is GL_UNSIGNED_INT. The type of the index array has to be an integral data type which corresponds to GL_UNSIGNED_INT. In your case it has to be unsigned int.
unsigned int indices = .... ;
Further, the primitive type GL_TRIANGLES consists of a list of indices where each 3 form a triangle. Indices 0, 1, 2 for ma triangle, indices 4, 5, 6 form the next triangle and so on. So the number of indices has to be dividable by 3.
If you want to draw a cube, then the list of indices may look like this:
unsigned int indices =
0,1,2, 0,2,3,
1,5,6, 1,6,2,
5,4,7, 5,7,6,
4,0,3, 4,3,7,
3,2,6, 3,6,7,
1,0,4, 1,4,5
;
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, NULL);
thx for your answer but after doing that i'm also getting a black screen :/
– Shirakawa42
Nov 15 '18 at 17:04
i tryed with 3*sizeof(float) and 0 but black screen :/ here is my github if you want to see all the code github.com/Shirakawa42/scop
– Shirakawa42
Nov 15 '18 at 17:59
@Shirakawa42unsigned intinstead offloat(for theindices)
– Rabbid76
Nov 15 '18 at 18:19
add a comment |
The 5th parameter of glVertexAttribPointer is the byte offset between consecutive generic vertex attributes. If it is 0 then the vertex attributes are understood to be tightly packed.
Your vertices consists of three components of type float, so the stride is 3*sizeof(float):
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), NULL);
Since the vertices are tightly packed, you can also pass 0 to the paramter:
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
The type of the indices is GL_UNSIGNED_INT. The type of the index array has to be an integral data type which corresponds to GL_UNSIGNED_INT. In your case it has to be unsigned int.
unsigned int indices = .... ;
Further, the primitive type GL_TRIANGLES consists of a list of indices where each 3 form a triangle. Indices 0, 1, 2 for ma triangle, indices 4, 5, 6 form the next triangle and so on. So the number of indices has to be dividable by 3.
If you want to draw a cube, then the list of indices may look like this:
unsigned int indices =
0,1,2, 0,2,3,
1,5,6, 1,6,2,
5,4,7, 5,7,6,
4,0,3, 4,3,7,
3,2,6, 3,6,7,
1,0,4, 1,4,5
;
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, NULL);
thx for your answer but after doing that i'm also getting a black screen :/
– Shirakawa42
Nov 15 '18 at 17:04
i tryed with 3*sizeof(float) and 0 but black screen :/ here is my github if you want to see all the code github.com/Shirakawa42/scop
– Shirakawa42
Nov 15 '18 at 17:59
@Shirakawa42unsigned intinstead offloat(for theindices)
– Rabbid76
Nov 15 '18 at 18:19
add a comment |
The 5th parameter of glVertexAttribPointer is the byte offset between consecutive generic vertex attributes. If it is 0 then the vertex attributes are understood to be tightly packed.
Your vertices consists of three components of type float, so the stride is 3*sizeof(float):
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), NULL);
Since the vertices are tightly packed, you can also pass 0 to the paramter:
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
The type of the indices is GL_UNSIGNED_INT. The type of the index array has to be an integral data type which corresponds to GL_UNSIGNED_INT. In your case it has to be unsigned int.
unsigned int indices = .... ;
Further, the primitive type GL_TRIANGLES consists of a list of indices where each 3 form a triangle. Indices 0, 1, 2 for ma triangle, indices 4, 5, 6 form the next triangle and so on. So the number of indices has to be dividable by 3.
If you want to draw a cube, then the list of indices may look like this:
unsigned int indices =
0,1,2, 0,2,3,
1,5,6, 1,6,2,
5,4,7, 5,7,6,
4,0,3, 4,3,7,
3,2,6, 3,6,7,
1,0,4, 1,4,5
;
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, NULL);
The 5th parameter of glVertexAttribPointer is the byte offset between consecutive generic vertex attributes. If it is 0 then the vertex attributes are understood to be tightly packed.
Your vertices consists of three components of type float, so the stride is 3*sizeof(float):
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), NULL);
Since the vertices are tightly packed, you can also pass 0 to the paramter:
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
The type of the indices is GL_UNSIGNED_INT. The type of the index array has to be an integral data type which corresponds to GL_UNSIGNED_INT. In your case it has to be unsigned int.
unsigned int indices = .... ;
Further, the primitive type GL_TRIANGLES consists of a list of indices where each 3 form a triangle. Indices 0, 1, 2 for ma triangle, indices 4, 5, 6 form the next triangle and so on. So the number of indices has to be dividable by 3.
If you want to draw a cube, then the list of indices may look like this:
unsigned int indices =
0,1,2, 0,2,3,
1,5,6, 1,6,2,
5,4,7, 5,7,6,
4,0,3, 4,3,7,
3,2,6, 3,6,7,
1,0,4, 1,4,5
;
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, NULL);
edited Nov 15 '18 at 18:19
answered Nov 15 '18 at 16:38
Rabbid76Rabbid76
41.5k123353
41.5k123353
thx for your answer but after doing that i'm also getting a black screen :/
– Shirakawa42
Nov 15 '18 at 17:04
i tryed with 3*sizeof(float) and 0 but black screen :/ here is my github if you want to see all the code github.com/Shirakawa42/scop
– Shirakawa42
Nov 15 '18 at 17:59
@Shirakawa42unsigned intinstead offloat(for theindices)
– Rabbid76
Nov 15 '18 at 18:19
add a comment |
thx for your answer but after doing that i'm also getting a black screen :/
– Shirakawa42
Nov 15 '18 at 17:04
i tryed with 3*sizeof(float) and 0 but black screen :/ here is my github if you want to see all the code github.com/Shirakawa42/scop
– Shirakawa42
Nov 15 '18 at 17:59
@Shirakawa42unsigned intinstead offloat(for theindices)
– Rabbid76
Nov 15 '18 at 18:19
thx for your answer but after doing that i'm also getting a black screen :/
– Shirakawa42
Nov 15 '18 at 17:04
thx for your answer but after doing that i'm also getting a black screen :/
– Shirakawa42
Nov 15 '18 at 17:04
i tryed with 3*sizeof(float) and 0 but black screen :/ here is my github if you want to see all the code github.com/Shirakawa42/scop
– Shirakawa42
Nov 15 '18 at 17:59
i tryed with 3*sizeof(float) and 0 but black screen :/ here is my github if you want to see all the code github.com/Shirakawa42/scop
– Shirakawa42
Nov 15 '18 at 17:59
@Shirakawa42
unsigned int instead of float (for the indices)– Rabbid76
Nov 15 '18 at 18:19
@Shirakawa42
unsigned int instead of float (for the indices)– Rabbid76
Nov 15 '18 at 18:19
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323735%2fbasic-opengl-black-screen-when-adding-ibo%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown