user3316633
user3316633

Reputation: 137

OpenGL draw rectangle composed of lines with vertex array

So I have a vertex array batcher, and I want to use it to render rectangles that are lines instead of filled in. Currently I am using glPolyGonMode(), but since my "shapes" are all uploaded to the graphics card as triangles, I get a line running down the middle of my rectangle, like this:enter image description here

Obviously this is happening because there are two triangles to a rectangle. But I want to render only the rectangle without the middle line. How could I accomplish this?

Upvotes: 0

Views: 3466

Answers (1)

zdd
zdd

Reputation: 8717

You can't do this with triangle list, triangle is the essential primitive to build up 3D models. you need two triangles to build up the rectangle.

If you don't want the middle line

  1. Use GL_QUADS, this is the easist way to your request, but be aware that GL_QUADS was deprecate from core OpenGL 3.1
  2. Use LINE_LOOP instead of triangles to build up your rectangle

Draw with GL_QUADS:

glBegin(GL_QUADS) ;
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(0.0, 0.5, 0.0);
    glVertex3f(0.5, 0.5, 0.0);
    glVertex3f(0.5, 0.0, 0.0);
glEnd() ;

Draw with LINE_LOOP:

glBegin(GL_LINE_LOOP) ;
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(0.0, 0.5, 0.0);
    glVertex3f(0.5, 0.5, 0.0);
    glVertex3f(0.5, 0.0, 0.0);
glEnd() ;

Upvotes: 2

Related Questions