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 vs glDrawArrays

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



Joined: 05 May 2005
Posts: 66

PostPosted: Sun Aug 21, 2005 5:59 am    Post subject: glDrawElements vs glDrawArrays Reply with quote

OK,

I am using this sample of code to render a box:

Code:


struct MyVertex
{
   float u, v;
   float x,y,z;
};

struct MyVertex __attribute__((aligned(16))) verti[12*3] =
{
   {0, 0, -1,-1, 1}, // 0
   {1, 0, -1, 1, 1}, // 4
   {1, 1,  1, 1, 1}, // 5

   {0, 0, -1,-1, 1}, // 0
   {1, 1,  1, 1, 1}, // 5
   {0, 1,  1,-1, 1}, // 1

   {0, 0, -1,-1,-1}, // 3
   {1, 0,  1,-1,-1}, // 2
   {1, 1,  1, 1,-1}, // 6

   {0, 0, -1,-1,-1}, // 3
   {1, 1,  1, 1,-1}, // 6
   {0, 1, -1, 1,-1}, // 7

   {0, 0,  1,-1,-1}, // 0
   {1, 0,  1,-1, 1}, // 3
   {1, 1,  1, 1, 1}, // 7

   {0, 0,  1,-1,-1}, // 0
   {1, 1,  1, 1, 1}, // 7
   {0, 1,  1, 1,-1}, // 4

   {0, 0, -1,-1,-1}, // 0
   {1, 0, -1, 1,-1}, // 3
   {1, 1, -1, 1, 1}, // 7

   {0, 0, -1,-1,-1}, // 0
   {1, 1, -1, 1, 1}, // 7
   {0, 1, -1,-1, 1}, // 4

   {0, 0, -1, 1,-1}, // 0
   {1, 0,  1, 1,-1}, // 1
   {1, 1,  1, 1, 1}, // 2

   {0, 0, -1, 1,-1}, // 0
   {1, 1,  1, 1, 1}, // 2
   {0, 1, -1, 1, 1}, // 3

   {0, 0, -1,-1,-1}, // 4
   {1, 0, -1,-1, 1}, // 7
   {1, 1,  1,-1, 1}, // 6

   {0, 0, -1,-1,-1}, // 4
   {1, 1,  1,-1, 1}, // 6
   {0, 1,  1,-1,-1}, // 5
};

...

//That sets it up, this renders it:
glInterleavedArrays(GL_T2F_V3F, 0,  verti);
glDrawArrays(GL_TRIANGLES, 0, 12*3);


OK, fine, I see a box, whoohoo. Now I want to use indicies so I am testing glDrawElements, same data, now rendering using:

Code:


//Setup simple index buffer
USHORT buff[12*3];
   buff[0] = 0;
   buff[1] = 1;
   buff[2] = 2;
   buff[3] = 3;
   buff[4] = 4;
   buff[5] = 5;
   buff[6] = 6;
   buff[7] = 7;
   buff[8] = 8;
   buff[9] = 9;
   buff[10] =10;
   buff[11] =11;
   buff[12] =12;
   buff[13] =13;
   buff[14] =14;
   buff[15] =15;
   buff[16] =16;
   buff[17] =17;
   buff[18] =18;
   buff[19] =19;
   buff[20] =20;
   buff[21] =21;
   buff[22] =22;
   buff[23] =23;
   buff[24] =24;
   buff[25] =25;
   buff[26] =26;
   buff[27] =27;
   buff[28] =28;
   buff[29] =29;
   buff[30] =30;
   buff[31] =31;
   buff[32] =32;
   buff[33] =33;
   buff[34] =34;
   buff[35] =35;


   glInterleavedArrays(GL_T2F_V3F, 0,  verti);
   glDrawElements(GL_TRIANGLES, 12*3, GL_UNSIGNED_SHORT, &buff[0]);



I see nothing. I have tried GL_UNSIGNED_BYTE as well and INT, but nothing different, am I missing something obvesious here?

NOTE:
I also know that I should be using 8 verts and 36 indicies but this is just a test to get drawelemets to work cause on my other models it doesn't seem to be rendering or incorrectly rendering.

Thanks a lot
Jeff King.
Back to top
View user's profile Send private message
ReKleSS



Joined: 18 Jun 2005
Posts: 73
Location: Melbourne, Australia

PostPosted: Sun Aug 21, 2005 8:32 am    Post subject: Reply with quote

Erm... well... your list is defined as USHORT. Doesn't it follow that you should be using GL_UNSIGNED_SHORT?

edit: ...crap, I should have looked more closely at the code instead of just the text... my mistake.

Also, have you checked to see if glGetError() can tell you anything?

-ReK


Last edited by ReKleSS on Sun Aug 21, 2005 10:48 am; edited 2 times in total
Back to top
View user's profile Send private message
webjeff



Joined: 05 May 2005
Posts: 66

PostPosted: Sun Aug 21, 2005 9:56 am    Post subject: Reply with quote

well yes, but I didn't see anything so I figured it might interpret as something else, who knows what could be wrong.

JK
Back to top
View user's profile Send private message
rinco



Joined: 21 Jan 2005
Posts: 255
Location: Canberra, Australia

PostPosted: Sun Aug 21, 2005 10:16 am    Post subject: Reply with quote

perhaps you see black triangles on a black background?
Back to top
View user's profile Send private message
ector



Joined: 12 May 2005
Posts: 195

PostPosted: Sun Aug 21, 2005 4:06 pm    Post subject: Reply with quote

Perhaps you forgot to flush the cache after writing the index array to memory, before drawing it?
_________________
http://www.dtek.chalmers.se/~tronic/PSPTexTool.zip Free texture converter for PSP with source. More to come.
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