forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

glDrawElements - what i do wrong?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
LarryTM



Joined: 04 Jul 2006
Posts: 30

PostPosted: Fri Jul 28, 2006 2:01 am    Post subject: glDrawElements - what i do wrong? Reply with quote

Im trying to learn how to use glDrawElements, but i have a problem.

Here is my cube object :

Code:

#define NR_Box01 0
objects[NR_Box01].id = ID_TRIMESH;
objects[NR_Box01].vertex_count = 8;
objects[NR_Box01].faces_count = 12;
objects[NR_Box01].vertex_list = &Box01_vertex_list[0];
objects[NR_Box01].faces_list = &Box01_faces_list[0];
objects[NR_Box01].face_normals_list = &Box01_face_normals_list[0];
objects[NR_Box01].tex_coords_list = &Box01_tex_coords_list[0];
objects[NR_Box01].dim_x1 = -5.000000;
objects[NR_Box01].dim_x2 = 5.000000;
objects[NR_Box01].dim_y1 = -5.000000;
objects[NR_Box01].dim_y2 = 5.000000;
objects[NR_Box01].dim_z1 = -4.981750;
objects[NR_Box01].dim_z2 = 5.018250;

static xyz Box01_vertex_list[] =
{
{-5.000000, -5.000000, -4.981750},
{5.000000, -5.000000, -4.981750},
{-5.000000, 5.000000, -4.981750},
{5.000000, 5.000000, -4.981750},
{-5.000000, -5.000000, 5.018250},
{5.000000, -5.000000, 5.018250},
{-5.000000, 5.000000, 5.018250},
{5.000000, 5.000000, 5.018250}
};
static face Box01_faces_list[] =
{
0, 2, 3,
3, 1, 0,
4, 5, 7,
7, 6, 4,
0, 1, 5,
5, 4, 0,
1, 3, 7,
7, 5, 1,
3, 2, 6,
6, 7, 3,
2, 0, 4,
4, 6, 2
};
static xyz Box01_face_normals_list[] =
{
{0.000000, 0.000000, -1.000000},
{0.000000, 0.000000, -1.000000},
{0.000000, 0.000000, 1.000000},
{0.000000, 0.000000, 1.000000},
{0.000000, -1.000000, 0.000000},
{0.000000, -1.000000, 0.000000},
{1.000000, 0.000000, 0.000000},
{1.000000, 0.000000, 0.000000},
{0.000000, 1.000000, 0.000000},
{0.000000, 1.000000, 0.000000},
{-1.000000, 0.000000, 0.000000},
{-1.000000, 0.000000, 0.000000}
};
static coords Box01_tex_coords_list[] =
{
{0.999500, 0.000500, 0.000499},
{0.000499, 0.000500, 0.999500},
{0.000499, 0.000500, 0.000500},
{0.000499, 0.000500, 0.999500},
{0.999500, 0.999501, 0.000499},
{0.000499, 0.999501, 0.999500},
{0.000499, 0.999501, 0.000500},
{0.000499, 0.999501, 0.999500},
{0.999501, 0.000500, 0.000500},
{0.999500, 0.999501, 0.000500},
{0.000499, 0.999500, 0.000500},
{0.000499, 0.999500, 0.000500},
{0.000500, 0.000499, 0.000500},
{0.999501, 0.000500, 0.000500},
{0.000499, 0.000500, 0.999501},
{0.999500, 0.000499, 0.999501},
{0.999501, 0.999500, 0.999501},
{0.999501, 0.999500, 0.999501},
{0.000500, 0.999501, 0.999501},
{0.000499, 0.000500, 0.999501},
{0.000499, 0.000500, 0.000500},
{0.999500, 0.000500, 0.000499},
{0.999500, 0.999501, 0.000499},
{0.999500, 0.999501, 0.000499},
{0.000499, 0.999501, 0.000500},
{0.000499, 0.000500, 0.000500},
{0.000499, 0.000500, 0.999500},
{0.999500, 0.000500, 0.999501},
{0.999500, 0.999501, 0.999501},
{0.999500, 0.999501, 0.999501},
{0.000499, 0.000500, 0.999500},
{0.999500, 0.000500, 0.999501},
{0.999500, 0.999501, 0.999501},
{0.999500, 0.999501, 0.999501},
{0.000499, 0.000500, 0.000500},
{0.999500, 0.999501, 0.000499}
};


and here is my code :

Code:

unsigned int   m_nVBOVertices;   
unsigned int   m_nVBOTexCoords;   
unsigned int index_buf;

Init :

  glGenBuffersARB( 1, &m_nVBOVertices );   
   glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOVertices );      
   glBufferDataARB( GL_ARRAY_BUFFER_ARB, objects[0].vertex_count*3*sizeof(float), objects[0].vertex_list, GL_STATIC_DRAW_ARB );
   
   glGenBuffersARB(1, &index_buf);
   glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, index_buf);
   glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, objects[0].faces_count*sizeof(GLushort), objects[0].faces_list, GL_STATIC_DRAW_ARB);

Draw:

glEnableClientState(GL_VERTEX_ARRAY);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, m_nVBOVertices );
glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );     
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, index_buf);   
               
glDrawElements(GL_TRIANGLES, objects[0].faces_count, GL_UNSIGNED_SHORT, 0);
glDisableClientState( GL_VERTEX_ARRAY );   
       


And I have one triangle on screen. Why? What I do wrong?

/lar
Back to top
View user's profile Send private message Visit poster's website
Kojima



Joined: 26 Jun 2006
Posts: 275

PostPosted: Fri Jul 28, 2006 3:45 am    Post subject: Reply with quote

you're passing the amount of faces to drawelements, but as the name suggests, you actually have to pass how many elements there are.

i.e TriCount * 3
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group