Forum

Draw a pentagon using vertex arrays?

Discuss programming topics that involve the OpenGL API.

Moderator: InsideQC Admins

Draw a pentagon using vertex arrays?

Postby Baker » Fri Mar 02, 2012 3:23 am

The rectangle way goes like this:

Code: Select all
   const int VertCount = 4; // Rectangle
   
   const GLfloat Vertex2f [] =
   {
      drawRect.x1, y1,
      drawRect.x2, y1,
      drawRect.x2, y2,
      drawRect.x1, y2,
   };
   
   const GLfloat TexCoord2f[] =
   {
      drawRect.left,  drawRect.top,      // Top
      drawRect.right, drawRect.top,      // Right
      drawRect.right, drawRect.bottom,   // Bottom
      drawRect.left,  drawRect.bottom,   // Left
   };

   glEnable              (GL_TEXTURE_2D);
   glBindTexture         (GL_TEXTURE_2D, TexSlot);
   
   // size (Specifies  the  number  of  coordinates per array element), type (GL_FLOAT, etc), stride, pointer
   glTexCoordPointer      (2, GL_FLOAT, 0, TexCoord2f);
   glEnableClientState      (GL_TEXTURE_COORD_ARRAY);   
   
   glVertexPointer         (2, GL_FLOAT, 0, Vertex2f);
   glEnableClientState      (GL_VERTEX_ARRAY);
   
   glDrawArrays         (GL_TRIANGLE_FAN, 0, VertCount);   // First, count
   
   glDisableClientState   (GL_VERTEX_ARRAY);
   glEnableClientState      (GL_TEXTURE_COORD_ARRAY);


But I'm not seeing this work for, say, a pentagon or octagon. For a rectangle, conveniently a set of 4 verts you can take the first 3 and draw a triangle and then the last 3 and draw a triangle. On paper, I'm not seeing this work for a pentagon.

Thoughts?

And if not, I'm sure I'll eventually self-solve and post answer.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3639
Joined: Tue Mar 14, 2006 5:15 am

Re: Draw a pentagon using vertex arrays?

Postby Baker » Fri Mar 02, 2012 3:38 am

Image

Nevermind. ^^ Triangle fan.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3639
Joined: Tue Mar 14, 2006 5:15 am

Re: Draw a pentagon using vertex arrays?

Postby frag.machine » Sat Mar 03, 2012 3:36 am

Baker wrote:Image

Nevermind. ^^ Triangle fan.


Shouldn't be a triangle strip ?
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2031
Joined: Sat Nov 25, 2006 1:49 pm

Re: Draw a pentagon using vertex arrays?

Postby mh » Sat Mar 03, 2012 1:52 pm

Fan or strip can do it. GL_TRIANGLES with indexes is better though.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2283
Joined: Sat Jan 12, 2008 1:38 am

Re: Draw a pentagon using vertex arrays?

Postby Baker » Sat Mar 03, 2012 7:20 pm

frag.machine wrote:Shouldn't be a triangle strip ?


A triangle fan let's me essentially use an existing array of vertices to draw a convex polygon. Vert 1, 2, 3, 4 5 = done

A trianglestrip was what I was thinking I was using, and was thinking in those terms.

mh wrote:Fan or strip can do it. GL_TRIANGLES with indexes is better though.


I'm doing some elementary things with simple shapes. Just want to give it literally 5 verts for a 2D polygon for a pentagram or 8 for an octagon. My little geometry thread at QuakeOne has taken me to somewhere interesting and I'm working on 2D representation of these ideas.

[And geometry applies to image manipulation and on-screen controls and the user interface ... ]
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3639
Joined: Tue Mar 14, 2006 5:15 am


Return to OpenGL Programming

Who is online

Users browsing this forum: No registered users and 1 guest