# Rendering 3D Box

**URL:** <https://forums.imgtec.com/t/rendering-3d-box/1814>\
**Category:** PowerVR Insider\
**Tags:** pvrshaman\
**Created:** [June 21, 2013, 8:18am UTC](https://forums.imgtec.com/t/rendering-3d-box/1814 "2013-06-21T08:18:13Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 21, 2013, 8:18am UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/1 "2013-06-21T08:18:13Z")

</div>

Hi,  
  
  
  
I have successfully rendered a triangle on the PandaBoard. But when I try rendering a 3D box (Indexed buffer object comes into picture), I can compile it but during running , a window shows but the box is not rendered. It suddenly turns black and prints the following line on the terminal continuously :  
  
  
  
PVR:(Error): Index offset 608592 is larger than index buffer size 192 [1340, /drawvarray.c]  
  
  
  
Can anyone tell me where did I go wrong ?

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 21, 2013, 10:03am UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/2 "2013-06-21T10:03:13Z")

</div>

Hello  
  
  
  
how did you do your box ?  
  
was it base on a list of triangle indexed or not ?  
  
example :

````auto
GLushort indices[] =<br />
{<br />
4, 5, 6, 4, 6, 7,<br />
1, 0, 3, 1, 3, 2,<br />
0, 4, 7, 0, 7, 3,<br />
5, 1, 2, 5, 2, 6,<br />
0, 4, 5, 0, 5, 1,<br />
3, 7, 6, 3, 6, 2<br />
};<br />
<br />
glGenBuffers(1, &m_BoxIBO);<br />
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_BoxIBO);<br />
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);<br />
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
```<br />
<br />
david<br />
````

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 21, 2013, 10:10am UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/3 "2013-06-21T10:10:22Z")

</div>

The great great PVRShaman can help for fast testing , it allow as well to create Open Built in Object menu and add a custom effect and a simple shader , it work very well and it s fast.

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 21, 2013, 10:18am UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/4 "2013-06-21T10:18:57Z")

</div>

I did exactly the same. The list of triangles was indexed and consisted of 36 indices. The only difference is that I used GLuint indices[]. Please also tell the parameters of glDrawElements(). Mine is :  
  
  
  
glDrawElements(GL\_TRIANGLES, numfaces \* 3, GL\_UNSIGNED\_INT, indices);

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 21, 2013, 10:31am UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/5 "2013-06-21T10:31:45Z")

</div>

```auto
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_BoxIBO);<br />
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, NULL);

```

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 21, 2013, 10:33am UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/6 "2013-06-21T10:33:50Z")

</div>

Why should the last parameter be NULL ?

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 21, 2013, 10:41am UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/7 "2013-06-21T10:41:44Z")

</div>

Well, making the last parameter NULL removed the error but the box doesn’t get rendered. There is only the background.

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 21, 2013, 10:43am UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/8 "2013-06-21T10:43:49Z")

</div>

it s an indexed triangle list !!!

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 21, 2013, 10:47am UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/9 "2013-06-21T10:47:39Z")

</div>

elsewhere i will use glDrawArrays  
  
the SDK have a lot of good material on all the spec , i like to look at it , there is so much to learn !!!

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 21, 2013, 10:47am UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/10 "2013-06-21T10:47:45Z")

</div>

void glDrawElements( GLenum mode,  
  
GLsizei count,  
  
GLenum type,  
  
const GLvoid \* indices);  
  
  
  
indices - Specifies a pointer to the location where the indices are stored.  
  
  
  
Why should we pass NULL to the pointer to the location i.e. indices.

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 21, 2013, 11:14am UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/11 "2013-06-21T11:14:21Z")

</div>

It s not mandatory , it depend of your choice of data structure index /not index list , strip not strip etcetc  
  
as we are in an index list you can select from witch indices you want to start

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 21, 2013, 11:18am UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/12 "2013-06-21T11:18:51Z")

</div>

How do we define an indexed list data structure. I just parsed the coordIndex node of the VRML file i.e. :  
  
  
  
coordIndex  
  
[  
  
0, 1, 2, -1,  
  
2, 3, 0, -1,  
  
3, 2, 4, -1,  
  
4, 5, 3, -1,  
  
5, 4, 7, -1,  
  
7, 6, 5, -1,  
  
6, 7, 1, -1,  
  
1, 0, 6, -1,  
  
6, 0, 3, -1,  
  
3, 5, 6, -1,  
  
1, 7, 2, -1,  
  
7, 4, 2, -1,  
  
]  
  
  
  
removed the -1s and copied the array into a GLuint indices[36].  
  
  
  
Any idea why the box is invisible on changing the parameter to NULL ?

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 21, 2013, 11:27am UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/13 "2013-06-21T11:27:38Z")

</div>

i didnt check your values i assume there are right 🙂 i am too lazy today…  
  
`GLushort coordIndex[] =
{
0, 1, 2, 2, 3, 0,
3, 2, 4, 4, 5, 3,
5, 4, 7, 7, 6, 5,
6, 7, 1, 1, 0, 6,
6, 0, 3, 3, 5, 6,
1, 7, 2, 7, 4, 2
};

glGenBuffers(1, &BoxIBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BoxIBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(coordIndex), coordIndex, GL_STATIC_DRAW);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

Rendering is : 
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BoxIBO);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, NULL);`  
  
  
  
regards  
  
david guimard

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 21, 2013, 12:08pm UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/14 "2013-06-21T12:08:20Z")

</div>

Hey, got the box rendered. 🙂  
  
I don’t know for some reason sizeof(indices) was returning 4, so I tried with (numfaces\*(3\*sizeof(GL\_UNSIGNED\_SHORT)) and parameter as NULL and it worked !  
  
  
  
Thanks for your replies.

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 21, 2013, 12:10pm UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/15 "2013-06-21T12:10:20Z")

</div>

GOOD STUFF what s your next move then ?

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 21, 2013, 12:18pm UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/16 "2013-06-21T12:18:43Z")

</div>

Now I’ll proceed to provide navigation features in the scene.

---

<div class="post-metadata">

**Author:** ![dgu](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dgu](https://forums.imgtec.com/u/dgu)\
**Post date:** [June 21, 2013, 12:21pm UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/17 "2013-06-21T12:21:52Z")

</div>

ok good luck

---

<div class="post-metadata">

**Author:** ![hellboy](https://avatars.discourse-cdn.com/v4/letter/h/48db29/32.png) [@hellboy](https://forums.imgtec.com/u/hellboy)\
**Post date:** [June 24, 2013, 9:11am UTC](https://forums.imgtec.com/t/rendering-3d-box/1814/18 "2013-06-24T09:11:00Z")

</div>

Hey, I think I got it wrong. When I rotated the camera to look the box from a different angle, I saw that it’s actually rendered two dimensionally. Do you know what the problem may be ?
