PDA

View Full Version : OpenGL drawElement by changing index



zezeon
06-02-2017, 08:56 AM
https://s5.postimg.org/jfdy4qbmr/image.png (https://postimg.org/image/jfdy4qbmr/)

https://s5.postimg.org/57o9g2yxv/image.png (https://postimg.org/image/57o9g2yxv/)


picture share (https://postimage.io/)
upper image is what I want, lower image is what I get.

I made 1 million cubes and stacked it. I sent all the vertexes to GPU. I removed some of the cubes and drew those with texture like upper image. But when I do not remove the cube and just change the index array and redraw it, the cubes that were formerly hidden appear as black.

I think I am omitting some procedure. Any help would be appreciated.

Let's simplify the question.. When I draw 100000 full index then I get right image. But if I limit the index size to 50000 like below without changing anything else, when the real index size is 100000, then I get black areas with no texture color.

glDrawElements(GL_QUADS, 50000, GL_UNSIGNED_INT, (void*)(offset+sizeof(unsigned)));

source : https://github.com/ParkSeungwon/NewbieGL/tree/cubemap/
src/test.cpp is the main() file.

Dark Photon
06-02-2017, 06:39 PM
Let's simplify the question.. When I draw 100000 full index then I get right image. But if I limit the index size to 50000 like below without changing anything else, when the real index size is 100000, then I get black areas with no texture color.

Sounds like the vertices for the cut-out geometry are in the back-half of the that 100,000 index index list. The cut-out are is black like the background, suggesting nothing is drawn there.

To verify that nothing is drawn there, clear the screen to red. Then with backface culling enabled, draw with 50,000 indices. If the cut-out's still red, nothing was drawn there.

zezeon
06-03-2017, 02:31 AM
Sounds like the vertices for the cut-out geometry are in the back-half of the that 100,000 index index list. The cut-out are is black like the background, suggesting nothing is drawn there.

To verify that nothing is drawn there, clear the screen to red. Then with backface culling enabled, draw with 50,000 indices. If the cut-out's still red, nothing was drawn there.

Thanks. I tried as you instructed. The background went red, but the missing cube places are still black.
Do I need to redo texture mapping ?
I don't know what's going on... Please help.

Dark Photon
06-03-2017, 07:25 AM
You might flip to rendering wireframe, change your shaders to render white, and disable backface culling. Just to try and see what you've got.

zezeon
06-03-2017, 08:35 AM
You might flip to rendering wireframe, change your shaders to render white, and disable backface culling. Just to try and see what you've got.

Thanks I found out what went wrong..
My normal calculation was wrong.
If there are 8 cubes around one vertex then the normal would be 0. the outer cubes is exceptional because they only have 2 or 3 cubes.